@yahyahammad/venastine 0.2.0 → 0.3.9

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 (152) hide show
  1. package/.env.example +9 -4
  2. package/CONFIG_ARCHITECTURE.md +2030 -0
  3. package/LICENSE +201 -201
  4. package/NOTICE +1 -1
  5. package/README.md +1034 -895
  6. package/agents/builtin/build.md +73 -0
  7. package/agents/builtin/compactor.md +75 -75
  8. package/agents/builtin/explore.md +77 -77
  9. package/agents/builtin/general.md +80 -0
  10. package/agents/builtin/pipeline-reviewer.md +100 -100
  11. package/agents/builtin/plan.md +106 -88
  12. package/agents/builtin/review.md +74 -74
  13. package/agents/builtin/test.md +65 -0
  14. package/agents/builtin/writer.md +67 -0
  15. package/agents/manager.py +68 -2
  16. package/agents/subagent_tool.py +472 -238
  17. package/agents/tui_commands.py +238 -151
  18. package/bin/venastine.mjs +150 -4
  19. package/bin/venastine.py +71 -0
  20. package/cli_commands.py +838 -0
  21. package/config.py +95 -1198
  22. package/config.yaml +1103 -0
  23. package/config_edit.py +1301 -0
  24. package/config_schema.py +971 -0
  25. package/config_update.py +749 -0
  26. package/core/agent_activity.py +256 -118
  27. package/core/ansi.py +452 -0
  28. package/core/approval.py +137 -115
  29. package/core/call_view.py +364 -0
  30. package/core/cancel.py +121 -0
  31. package/core/chatgpt_auth.py +747 -0
  32. package/core/claims_view.py +107 -0
  33. package/core/client.py +2715 -1559
  34. package/core/commands.py +460 -0
  35. package/core/compaction.py +1735 -971
  36. package/core/config_loader.py +1982 -1563
  37. package/core/connect.py +686 -0
  38. package/core/events.py +123 -61
  39. package/core/file_mentions.py +280 -0
  40. package/core/interaction.py +411 -328
  41. package/core/line_pattern.py +128 -0
  42. package/core/loop.py +2566 -1490
  43. package/core/memory.py +482 -370
  44. package/core/pipeline_models.py +190 -176
  45. package/core/provider_errors.py +234 -0
  46. package/core/reasoning/authorization.py +130 -130
  47. package/core/reasoning/base.py +219 -219
  48. package/core/reasoning/confidence_scoring.py +484 -468
  49. package/core/reasoning/events.py +149 -149
  50. package/core/reasoning/json_retry.py +19 -1
  51. package/core/reasoning/orchestrator.py +1561 -1382
  52. package/core/reasoning/output_writer.py +345 -286
  53. package/core/reasoning/payload_validation.py +524 -398
  54. package/core/reasoning/pipeline_storage.py +88 -22
  55. package/core/reasoning/review.py +659 -615
  56. package/core/reasoning/scholar.py +458 -434
  57. package/core/reasoning/source_corpus.py +433 -327
  58. package/core/reasoning/source_scoring.py +855 -855
  59. package/core/replay.py +315 -183
  60. package/core/session.py +36 -12
  61. package/core/session_view.py +259 -0
  62. package/core/session_wake.py +259 -0
  63. package/core/shell_sessions.py +1553 -0
  64. package/core/workspace_trust.py +1 -1
  65. package/credentials.py +148 -20
  66. package/database.py +333 -252
  67. package/{PRIVACY.md → docs/PRIVACY.md} +78 -66
  68. package/docs/SECURITY.md +108 -0
  69. package/docs/THIRD_PARTY_NOTICES.md +148 -0
  70. package/env_secrets.py +50 -9
  71. package/json_store.py +343 -123
  72. package/logging_setup.py +295 -185
  73. package/main.py +3433 -1961
  74. package/mcp_client/client.py +733 -499
  75. package/mcp_client/config.py +126 -21
  76. package/mcp_client/registration.py +343 -182
  77. package/memories/manager.py +147 -132
  78. package/memories/tui_commands.py +319 -244
  79. package/package.json +303 -73
  80. package/project_init/config_files.py +282 -278
  81. package/project_init/generator.py +728 -564
  82. package/project_init/manifest.py +18 -6
  83. package/project_init/tui_commands.py +147 -144
  84. package/prompts/critic_pass.md +24 -24
  85. package/prompts/revalidate.md +25 -25
  86. package/prompts/revise.md +2 -0
  87. package/prompts/source_grounding.md +66 -66
  88. package/prompts/system_prompts.py +316 -262
  89. package/providers.json.example +4 -2
  90. package/pyproject.toml +149 -100
  91. package/requirements.txt +295 -72
  92. package/safety/policy_enforcement.py +1082 -746
  93. package/security/askpass.py +419 -0
  94. package/security/capability.py +207 -177
  95. package/security/confine.py +484 -0
  96. package/security/hosted.py +182 -0
  97. package/security/permissions.py +237 -190
  98. package/security/posture.py +124 -12
  99. package/security/protected_paths.py +501 -309
  100. package/security/sandbox.py +4108 -985
  101. package/security/secrets.py +855 -0
  102. package/skills/builtin/math/formal-specification.md +67 -67
  103. package/skills/builtin/math/numerical-methods.md +66 -66
  104. package/skills/builtin/research/experiment-design.md +62 -62
  105. package/skills/builtin/research/reproducibility.md +55 -55
  106. package/skills/builtin/research/source-evaluation.md +70 -70
  107. package/skills/builtin/research/statistical-inference.md +63 -63
  108. package/skills/builtin/research/technical-writing.md +59 -59
  109. package/skills/builtin/software/code-review.md +61 -61
  110. package/skills/builtin/software/debugging.md +61 -61
  111. package/skills/builtin/software/test-design.md +67 -67
  112. package/skills/tui_commands.py +110 -111
  113. package/storage.py +1338 -1005
  114. package/tools/base.py +161 -1
  115. package/tools/builtin/_math_common.py +667 -377
  116. package/tools/builtin/_net_common.py +225 -19
  117. package/tools/builtin/arxiv.py +497 -39
  118. package/tools/builtin/ask_user.py +231 -213
  119. package/tools/builtin/discrete_math.py +35 -4
  120. package/tools/builtin/fetch_url.py +371 -153
  121. package/tools/builtin/file_ops.py +720 -412
  122. package/tools/builtin/geometry.py +48 -12
  123. package/tools/builtin/get_time.py +2 -2
  124. package/tools/builtin/linear_algebra.py +66 -23
  125. package/tools/builtin/load_skill.py +76 -66
  126. package/tools/builtin/logic.py +171 -12
  127. package/tools/builtin/pin.py +227 -193
  128. package/tools/builtin/probability_stats.py +12 -16
  129. package/tools/builtin/project_docs.py +464 -405
  130. package/tools/builtin/remember.py +175 -158
  131. package/tools/builtin/shell.py +980 -461
  132. package/tools/builtin/shell_sessions.py +613 -0
  133. package/tools/builtin/symbolic_math.py +80 -10
  134. package/tools/builtin/todo.py +149 -147
  135. package/tools/builtin/web_search.py +191 -13
  136. package/tools/context.py +159 -136
  137. package/tools/isolation.py +107 -34
  138. package/tools/registry.py +1242 -925
  139. package/tui/app.py +8318 -4100
  140. package/tui/app.tcss +747 -556
  141. package/tui/commands.py +26 -170
  142. package/tui/diffs.py +34 -13
  143. package/tui/history.py +128 -128
  144. package/tui/hosted_driver.py +102 -0
  145. package/tui/markdown.py +1329 -1279
  146. package/tui/meters.py +364 -268
  147. package/tui/ravens.py +146 -146
  148. package/tui/screens.py +1255 -943
  149. package/tui/themes.py +599 -559
  150. package/tui/widgets.py +3813 -2332
  151. package/SECURITY.md +0 -88
  152. package/THIRD_PARTY_NOTICES.md +0 -100
@@ -1,193 +1,227 @@
1
- """
2
- tools/builtin/pin.py
3
-
4
- ROADMAP_v2 §21: mark recent turns compaction-exempt.
5
-
6
- Thread-scoped and reversible, which is why D26 leaves it ungated while
7
- requiring approval for §21b's `remember`. They differ on the axis that
8
- already separates `read` from `write`: a wrong pin costs some context
9
- budget inside a conversation the user is watching, while a durable memory
10
- outlives the thread and silently shapes conversations that have not
11
- started yet.
12
-
13
- That decision has a consequence worth naming rather than discovering: this
14
- tool works on the CLI and inside a research pass, where an approval-gated
15
- tool is not merely denied but never advertised (§13).
16
-
17
- THE INTERFACE IS ORDINAL, NOT AN ID. §21 keeps MessageLog.id out of the
18
- provider-neutral message shape -- the model never sees one, so it cannot
19
- name one -- and putting it there would mean a persistence concept in the
20
- contract the memory design rests on, with all three provider translation
21
- branches then needing to strip it before the wire. "Pin the last N turns"
22
- needs no id and is how the tool would realistically be used mid-conversation.
23
- """
24
-
25
- import config
26
-
27
- TOOL_SCHEMA = {
28
- "name": "pin",
29
- "description": (
30
- "Protect the most recent turns of this conversation from being "
31
- "summarized away when the context gets long. Use this when "
32
- "something established recently must survive verbatim -- an exact "
33
- "identifier, a constraint the user stated once, a decision the rest "
34
- "of the work depends on. A turn is one user message and everything "
35
- "that answered it. Pinned messages stay in full; everything else "
36
- "may eventually be condensed into a summary. There is a cap on how "
37
- "much may be pinned at once; the error states it if you reach it."
38
- ),
39
- "input_schema": {
40
- "type": "object",
41
- "properties": {
42
- "last_n": {
43
- "type": "integer",
44
- "description": "How many recent turns to pin. Defaults to 1 "
45
- "(the exchange in progress and the one before "
46
- "it are already protected automatically, so "
47
- "reach further back than you think you need).",
48
- "minimum": 1,
49
- },
50
- },
51
- "required": [],
52
- },
53
- }
54
-
55
- UNPIN_TOOL_SCHEMA = {
56
- "name": "unpin",
57
- "description": (
58
- "Release the compaction protection on recent turns (#89). The "
59
- "mirror of pin: use it when something you pinned earlier no longer "
60
- "needs to survive verbatim -- a resolved question, a superseded "
61
- "decision, stale detail. Pinned material is permanent until "
62
- "released, so unpinning is how the conversation stays condensable."
63
- ),
64
- "input_schema": {
65
- "type": "object",
66
- "properties": {
67
- "last_n": {
68
- "type": "integer",
69
- "description": "How many recent turns to release. Defaults "
70
- "to 1.",
71
- "minimum": 1,
72
- },
73
- },
74
- "required": [],
75
- },
76
- }
77
-
78
-
79
- def _validated_turns(params: dict) -> object:
80
- """pin/unpin's shared argument validation: the error, or the int."""
81
- last_n = params.get("last_n", 1)
82
- if isinstance(last_n, bool) or not isinstance(last_n, int):
83
- # isinstance(True, int) is True in Python, and a model emitting
84
- # `last_n: true` would otherwise pin exactly one turn while looking
85
- # like it had been understood.
86
- return "requires 'last_n' to be a whole number of turns."
87
- if last_n < 1:
88
- return "requires 'last_n' to be at least 1."
89
- return last_n
90
-
91
-
92
- def _pinned_share(memory) -> tuple:
93
- """(tokens still protected, cap) for result text -- M14's rule that a
94
- cap is stated in what the model reads, not only in a log."""
95
- from core.compaction import pin_measurements
96
-
97
- m = pin_measurements(memory.thread_id, 1)
98
- return m["pinned_tokens"], m["max_tokens"]
99
-
100
-
101
- def run(params: dict, memory=None) -> dict:
102
- # params.get, not params[]: no provider validates tool inputs against
103
- # the schema, and a bare KeyError escapes the loop's ToolCallDenied
104
- # handler and aborts the whole turn. Same reasoning as load_skill's.
105
- last_n = _validated_turns(params)
106
- if isinstance(last_n, str):
107
- return {"error": f"pin {last_n}"}
108
- if memory is None:
109
- # Reachable only if the tool is dispatched outside a run. Better an
110
- # explained error than a silent no-op reported as success -- the
111
- # model would otherwise believe something is protected when nothing
112
- # is, which is worse than not having the tool. pin.py's reasoning.
113
- return {"error": "pin is only available inside a conversation."}
114
-
115
- # #89's cap, checked BEFORE anything is applied. A pin is a permanent
116
- # floor under the derived view -- pinned rows re-enter it verbatim
117
- # forever (M9), nothing folds them -- so one ungated call used to be
118
- # able to put a thread permanently past the compaction trigger with no
119
- # way back. Over-cap REFUSES rather than trimming (M15's rule in the
120
- # tool direction): silently protecting less than was asked would leave
121
- # the model believing material is safe when it is not. The refusal
122
- # states the cap, the request, and the current share, so the retry is
123
- # informed rather than blind.
124
- from core.compaction import pin_measurements
125
-
126
- m = pin_measurements(memory.thread_id, last_n)
127
- if m["requested_tokens"] > m["max_tokens"]:
128
- already = (f"{m['pinned_tokens']} tokens are already protected "
129
- f"({100 * m['pinned_tokens'] // max(1, m['max_tokens'])}% "
130
- f"of the cap).")
131
- return {
132
- "error": (
133
- f"Pinning the last {last_n} turn(s) would protect about "
134
- f"{m['requested_tokens']} tokens, over the cap of "
135
- f"{m['max_tokens']}. Nothing was changed. {already} "
136
- f"Pin fewer turns, or unpin older material with `unpin`."
137
- ),
138
- }
139
-
140
- changed = memory.pin_last(last_n)
141
- if not changed:
142
- # Distinguish "already pinned" from "nothing to pin". Both return
143
- # zero and they call for different next moves.
144
- return {"result": f"Nothing to pin -- the last {last_n} turn(s) are "
145
- f"already protected, or the conversation has not "
146
- f"got that far yet."}
147
- pinned, cap = _pinned_share(memory)
148
- return {
149
- "result": f"Pinned the last {last_n} turn(s) ({changed} messages). "
150
- f"They will be kept verbatim rather than summarized when "
151
- f"this conversation is compacted. {pinned} tokens "
152
- f"protected of the {cap}-token cap.",
153
- }
154
-
155
-
156
- def unpin_run(params: dict, memory=None) -> dict:
157
- """The mirror of run(): releases the ordinal window instead of
158
- protecting it (#89). D26 called a pin reversible; until batch 16
159
- nothing anywhere reversed one, and `set_pinned(pinned=False)` was
160
- written and unreachable. Long sessions accumulate stale pins -- an
161
- identifier resolved, a decision superseded -- and every one of them is
162
- a row no future compaction can touch, so release has to be as
163
- reachable as protection, for the same ungated reasons."""
164
- if memory is None:
165
- return {"error": "unpin is only available inside a conversation."}
166
- last_n = _validated_turns(params)
167
- if isinstance(last_n, str):
168
- return {"error": f"unpin {last_n}"}
169
-
170
- released = memory.unpin_last(last_n)
171
- if not released:
172
- return {"result": f"Nothing to release -- the last {last_n} "
173
- f"turn(s) were not pinned."}
174
- pinned, cap = _pinned_share(memory)
175
- return {
176
- "result": f"Released the last {last_n} turn(s) ({released} message"
177
- f"{'s' if released != 1 else ''}). {pinned} tokens still "
178
- f"protected of the {cap}-token cap.",
179
- }
180
-
181
-
182
- def available() -> bool:
183
- """ToolSpec.available_check.
184
-
185
- Hidden when compaction cannot happen at all. Pinning is protection
186
- FROM compaction, so with the compactor agent missing there is nothing
187
- to be protected from -- and advertising a tool whose only effect is to
188
- set a flag nothing reads is the fetch_url defect shape (D24): a schema
189
- the model can see, choose, and never get value from.
190
- """
191
- from core import config_loader
192
-
193
- return config.COMPACTOR_AGENT in config_loader.get_agents()
1
+ """
2
+ tools/builtin/pin.py
3
+
4
+ ROADMAP_v2 §21: mark recent turns compaction-exempt.
5
+
6
+ Thread-scoped and reversible, which is why D26 leaves it ungated while
7
+ requiring approval for §21b's `remember`. They differ on the axis that
8
+ already separates `read` from `write`: a wrong pin costs some context
9
+ budget inside a conversation the user is watching, while a durable memory
10
+ outlives the thread and silently shapes conversations that have not
11
+ started yet.
12
+
13
+ That decision has a consequence worth naming rather than discovering: this
14
+ tool works on the CLI and inside a research pass, where an approval-gated
15
+ tool is not merely denied but never advertised (§13).
16
+
17
+ THE INTERFACE IS ORDINAL, NOT AN ID. §21 keeps MessageLog.id out of the
18
+ provider-neutral message shape -- the model never sees one, so it cannot
19
+ name one -- and putting it there would mean a persistence concept in the
20
+ contract the memory design rests on, with all three provider translation
21
+ branches then needing to strip it before the wire. "Pin the last N turns"
22
+ needs no id and is how the tool would realistically be used mid-conversation.
23
+ """
24
+
25
+ import config
26
+
27
+ TOOL_SCHEMA = {
28
+ "name": "pin",
29
+ "description": (
30
+ "Protect the most recent turns of this conversation from being "
31
+ "summarized away when the context gets long. Use this when "
32
+ "something established recently must survive verbatim -- an exact "
33
+ "identifier, a constraint the user stated once, a decision the rest "
34
+ "of the work depends on. A turn is one user message and everything "
35
+ "that answered it. Pinned messages stay in full; everything else "
36
+ "may eventually be condensed into a summary. There is a cap on how "
37
+ "much may be pinned at once; the error states it if you reach it."
38
+ ),
39
+ "input_schema": {
40
+ "type": "object",
41
+ "properties": {
42
+ "last_n": {
43
+ "type": "integer",
44
+ "description": "How many recent turns to pin. Defaults to 1 "
45
+ "(the exchange in progress and the one before "
46
+ "it are already protected automatically, so "
47
+ "reach further back than you think you need).",
48
+ "minimum": 1,
49
+ "default": 1,
50
+ },
51
+ },
52
+ "required": [],
53
+ },
54
+ }
55
+
56
+ UNPIN_TOOL_SCHEMA = {
57
+ "name": "unpin",
58
+ "description": (
59
+ "Release the compaction protection on recent turns (#89). The "
60
+ "mirror of pin: use it when something you pinned earlier no longer "
61
+ "needs to survive verbatim -- a resolved question, a superseded "
62
+ "decision, stale detail. Pinned material is permanent until "
63
+ "released, so unpinning is how the conversation stays condensable."
64
+ ),
65
+ "input_schema": {
66
+ "type": "object",
67
+ "properties": {
68
+ "last_n": {
69
+ "type": "integer",
70
+ "description": "How many recent turns to release. Defaults "
71
+ "to 1.",
72
+ "minimum": 1,
73
+ "default": 1,
74
+ },
75
+ },
76
+ "required": [],
77
+ },
78
+ }
79
+
80
+
81
+ def _validated_turns(params: dict) -> object:
82
+ """pin/unpin's shared argument validation: the error, or the int.
83
+
84
+ An explicit null is ABSENT (batch 190). The ChatGPT plan's model sends
85
+ each optional parameter at its declared default (ROADMAP_v3 §83, the
86
+ owner's live check), so the schema now declares 1; a model that sends
87
+ null instead means the same thing, and refusing it cost a turn. Every
88
+ other non-integer is still refused, never coerced.
89
+ """
90
+ last_n = params.get("last_n")
91
+ if last_n is None:
92
+ last_n = 1
93
+ if isinstance(last_n, bool) or not isinstance(last_n, int):
94
+ # isinstance(True, int) is True in Python, and a model emitting
95
+ # `last_n: true` would otherwise pin exactly one turn while looking
96
+ # like it had been understood.
97
+ return "requires 'last_n' to be a whole number of turns."
98
+ if last_n < 1:
99
+ return "requires 'last_n' to be at least 1."
100
+ return last_n
101
+
102
+
103
+ def _pinned_share(memory, parent_run=None) -> tuple:
104
+ """(tokens still protected, cap) for result text -- M14's rule that a
105
+ cap is stated in what the model reads, not only in a log.
106
+
107
+ `parent_run` is threaded through for the CAP, which is a fraction of
108
+ the trigger THIS model folds at (batch 148): a result sentence
109
+ naming a different number than the refusal would be worse than naming
110
+ none.
111
+ """
112
+ from core.compaction import pin_measurements
113
+
114
+ m = pin_measurements(memory.thread_id, 1, *_pair(parent_run))
115
+ return m["pinned_tokens"], m["max_tokens"]
116
+
117
+
118
+ def _pair(parent_run) -> tuple:
119
+ """(model, provider_name) off the enclosing run, or (None, None).
120
+
121
+ A RunInfo is built once per turn (core/loop.py) so this is available on
122
+ every path a model can call `pin` from -- chat, the CLI and a research
123
+ pass. None is not a failure: pin_measurements then measures the cap
124
+ against the configured trigger, which is what it did everywhere before
125
+ #89's cap started depending on the model.
126
+ """
127
+ if parent_run is None:
128
+ return None, None
129
+ return (getattr(parent_run, "model", None),
130
+ getattr(parent_run, "provider_name", None))
131
+
132
+
133
+ def run(params: dict, memory=None, parent_run=None) -> dict:
134
+ # params.get, not params[]: no provider validates tool inputs against
135
+ # the schema. tools/base.py carries the one copy of why, under
136
+ # "WHAT A CALLABLE REGISTERED BELOW MAY RAISE": a handler's exception IS
137
+ # contained, so what this buys is an error dict the model can READ rather
138
+ # than the generic wrapper dispatch() would return (batch 146).
139
+ last_n = _validated_turns(params)
140
+ if isinstance(last_n, str):
141
+ return {"error": f"pin {last_n}"}
142
+ if memory is None:
143
+ # Reachable only if the tool is dispatched outside a run. Better an
144
+ # explained error than a silent no-op reported as success -- the
145
+ # model would otherwise believe something is protected when nothing
146
+ # is, which is worse than not having the tool. pin.py's reasoning.
147
+ return {"error": "pin is only available inside a conversation."}
148
+
149
+ # #89's cap, checked BEFORE anything is applied. A pin is a permanent
150
+ # floor under the derived view -- pinned rows re-enter it verbatim
151
+ # forever (M9), nothing folds them -- so one ungated call used to be
152
+ # able to put a thread permanently past the compaction trigger with no
153
+ # way back. Over-cap REFUSES rather than trimming (M15's rule in the
154
+ # tool direction): silently protecting less than was asked would leave
155
+ # the model believing material is safe when it is not. The refusal
156
+ # states the cap, the request, and the current share, so the retry is
157
+ # informed rather than blind.
158
+ from core.compaction import pin_measurements
159
+
160
+ m = pin_measurements(memory.thread_id, last_n, *_pair(parent_run))
161
+ if m["requested_tokens"] > m["max_tokens"]:
162
+ already = (f"{m['pinned_tokens']} tokens are already protected "
163
+ f"({100 * m['pinned_tokens'] // max(1, m['max_tokens'])}% "
164
+ f"of the cap).")
165
+ return {
166
+ "error": (
167
+ f"Pinning the last {last_n} turn(s) would protect about "
168
+ f"{m['requested_tokens']} tokens, over the cap of "
169
+ f"{m['max_tokens']}. Nothing was changed. {already} "
170
+ f"Pin fewer turns, or unpin older material with `unpin`."
171
+ ),
172
+ }
173
+
174
+ changed = memory.pin_last(last_n)
175
+ if not changed:
176
+ # Distinguish "already pinned" from "nothing to pin". Both return
177
+ # zero and they call for different next moves.
178
+ return {"result": f"Nothing to pin -- the last {last_n} turn(s) are "
179
+ f"already protected, or the conversation has not "
180
+ f"got that far yet."}
181
+ pinned, cap = _pinned_share(memory, parent_run)
182
+ return {
183
+ "result": f"Pinned the last {last_n} turn(s) ({changed} messages). "
184
+ f"They will be kept verbatim rather than summarized when "
185
+ f"this conversation is compacted. {pinned} tokens "
186
+ f"protected of the {cap}-token cap.",
187
+ }
188
+
189
+
190
+ def unpin_run(params: dict, memory=None, parent_run=None) -> dict:
191
+ """The mirror of run(): releases the ordinal window instead of
192
+ protecting it (#89). D26 called a pin reversible; until batch 16
193
+ nothing anywhere reversed one, and `set_pinned(pinned=False)` was
194
+ written and unreachable. Long sessions accumulate stale pins -- an
195
+ identifier resolved, a decision superseded -- and every one of them is
196
+ a row no future compaction can touch, so release has to be as
197
+ reachable as protection, for the same ungated reasons."""
198
+ if memory is None:
199
+ return {"error": "unpin is only available inside a conversation."}
200
+ last_n = _validated_turns(params)
201
+ if isinstance(last_n, str):
202
+ return {"error": f"unpin {last_n}"}
203
+
204
+ released = memory.unpin_last(last_n)
205
+ if not released:
206
+ return {"result": f"Nothing to release -- the last {last_n} "
207
+ f"turn(s) were not pinned."}
208
+ pinned, cap = _pinned_share(memory, parent_run)
209
+ return {
210
+ "result": f"Released the last {last_n} turn(s) ({released} message"
211
+ f"{'s' if released != 1 else ''}). {pinned} tokens still "
212
+ f"protected of the {cap}-token cap.",
213
+ }
214
+
215
+
216
+ def available() -> bool:
217
+ """ToolSpec.available_check.
218
+
219
+ Hidden when compaction cannot happen at all. Pinning is protection
220
+ FROM compaction, so with the compactor agent missing there is nothing
221
+ to be protected from -- and advertising a tool whose only effect is to
222
+ set a flag nothing reads is the fetch_url defect shape (D24): a schema
223
+ the model can see, choose, and never get value from.
224
+ """
225
+ from core import config_loader
226
+
227
+ return config.COMPACTOR_AGENT in config_loader.get_agents()
@@ -20,6 +20,8 @@ import sympy
20
20
  import sympy.stats as sstats
21
21
  from pydantic import BaseModel, Field
22
22
 
23
+ from tools.builtin._math_common import MathParseError, parse_params
24
+
23
25
  _OPERATIONS = Literal["describe", "distribution_stats", "distribution_pdf", "distribution_cdf"]
24
26
  _DISTRIBUTIONS = Literal["normal", "binomial", "poisson", "uniform", "exponential"]
25
27
 
@@ -59,20 +61,6 @@ TOOL_SCHEMA = {
59
61
  }
60
62
 
61
63
 
62
- def _build_distribution(name: str, dp: dict):
63
- if name == "normal":
64
- return sstats.Normal("X", dp.get("mu", 0), dp.get("sigma", 1))
65
- if name == "binomial":
66
- return sstats.Binomial("X", int(dp["n"]), dp["p"])
67
- if name == "poisson":
68
- return sstats.Poisson("X", dp["lambda"])
69
- if name == "uniform":
70
- return sstats.Uniform("X", dp.get("a", 0), dp.get("b", 1))
71
- if name == "exponential":
72
- return sstats.Exponential("X", dp.get("rate", 1))
73
- raise ValueError(f"Unsupported distribution: {name}")
74
-
75
-
76
64
  def _build_distribution_with_warnings(name: str, dp_orig: Optional[dict]):
77
65
  """Build distribution and collect warnings for defaulted params.
78
66
 
@@ -80,6 +68,11 @@ def _build_distribution_with_warnings(name: str, dp_orig: Optional[dict]):
80
68
  that fell back to a default, per decision 2 (keep forgiving but explain).
81
69
  Binomial/poisson have no defaults — missing required keys become a
82
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.
83
76
  """
84
77
  dp = dp_orig or {}
85
78
  warnings: list[str] = []
@@ -114,7 +107,7 @@ def _maybe_evalf(value, do_eval: bool, precision: int):
114
107
  if hasattr(value, "evalf"):
115
108
  return value.evalf(precision)
116
109
  except Exception:
117
- pass
110
+ pass # no numeric form; the exact value is still a correct answer
118
111
  return value
119
112
 
120
113
 
@@ -154,7 +147,10 @@ def _cdf_at(dist, x):
154
147
 
155
148
 
156
149
  def run(params: dict) -> dict:
157
- parsed = ProbabilityStatsParams(**params)
150
+ try:
151
+ parsed = parse_params(ProbabilityStatsParams, params)
152
+ except MathParseError as e:
153
+ return {"error": str(e)}
158
154
 
159
155
  try:
160
156
  if parsed.operation == "describe":