@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,190 +1,237 @@
1
- """
2
- security/permissions.py
3
-
4
- POLICY, not mechanism: "may this tool be called at all?" and "does this
5
- call need a human to approve it?". tools/registry.py owns dispatch
6
- mechanics and is the only caller; tool modules never import this.
7
-
8
- ROADMAP_v2 §15 adds the "stricter wins" rule (D14). Every currently
9
- active layer is consulted -- the global config dataclasses, plus an
10
- optional ToolContext contributed by the active agent (§18) and the skills
11
- it has activated (§19):
12
-
13
- * allow/deny is a logical AND -- a tool is available only if global
14
- policy allows it AND every layer that expresses an opinion allows it.
15
- A globally-disabled tool can never be re-enabled by a context; that
16
- check runs first and unconditionally.
17
- * approval is a logical OR -- approval is required if the global
18
- setting says so, OR the context says so, OR (in the registry) the
19
- tool's own dynamic approval_check says so. A context can therefore
20
- tighten a lenient default but can never loosen a strict one.
21
-
22
- ToolContext is imported for typing only. security/ must not gain a
23
- runtime dependency on tools/ -- the real direction is tools -> security,
24
- and inverting it would create a cycle the moment tools/context.py grows
25
- an import of its own.
26
- """
27
-
28
- from typing import TYPE_CHECKING, Iterable, Optional
29
-
30
- import config
31
-
32
- if TYPE_CHECKING: # pragma: no cover - typing only, never imported at runtime
33
- from tools.context import ToolContext
34
-
35
-
36
- def _default_for_unknown_tool(tool_name: str) -> bool:
37
- """Explicit, named default for tools with no declared field, rather
38
- than letting getattr's fallback decide by omission.
39
-
40
- config.ToolPermissions is a static dataclass with one field per known
41
- tool. MCP tools (§17) are named at connection time
42
- (`mcp__<server>__<tool>`) and can never have a pre-declared field, so
43
- a bare `getattr(..., False)` would deny every one of them forever.
44
- They are allowed here because their real control point is the
45
- server-level trust gate in §17. Anything else unknown is denied --
46
- and for statically registered tools, omission is caught outright by
47
- assert_permissions_declared() at import time (D24), so this branch
48
- should be unreachable for them.
49
- """
50
- return tool_name.startswith("mcp__")
51
-
52
-
53
- def _default_for_unknown_approval(tool_name: str) -> bool:
54
- """Approval counterpart to _default_for_unknown_tool.
55
-
56
- MCP tools default to REQUIRING approval (§17 decision D). They are
57
- allowed by default but not trusted by default, and those are different
58
- questions: an MCP server is third-party code that the model can reach
59
- without the user ever naming it. The project tier is trust-gated
60
- (D17), but a user-level mcp.json auto-connects, and config files grow
61
- entries that installers appended.
62
-
63
- Everything else unknown defaults to not requiring approval, matching
64
- the previous getattr fallback.
65
- """
66
- return tool_name.startswith("mcp__")
67
-
68
-
69
- # Base approval defaults for tools that cannot have a declared field --
70
- # populated at connection time from each MCP server's `autoApprove`.
71
- #
72
- # This exists because the per-server opt-out CANNOT be expressed as a
73
- # ToolSpec.approval_check: registry.approval_needed() ORs those in, and OR
74
- # can only ever tighten. Varying the BASE DEFAULT instead keeps D14's
75
- # one-way ratchet exactly intact -- a context override can still force
76
- # approval back on for an auto-approved server, but nothing can wave a
77
- # call past a gate a stricter layer set.
78
- _dynamic_approval_defaults: dict = {}
79
-
80
-
81
- def set_dynamic_approval_default(tool_name: str, required: bool) -> None:
82
- """Declare the base approval default for a dynamically-named tool."""
83
- _dynamic_approval_defaults[tool_name] = bool(required)
84
-
85
-
86
- def clear_dynamic_approval_defaults(*names: str) -> None:
87
- """Drop defaults for tools that no longer exist. Idempotent, because
88
- disconnect handling can run more than once for the same server. With
89
- no arguments, drops all of them.
90
-
91
- Names are EXACT. This took a PREFIX until §14-§18 review finding f8,
92
- which is the same over-match hazard `mcp__<server>__<tool>` has one
93
- layer up and for the same reason -- neither `__` in a server name nor
94
- `__` in a tool name is illegal. Clearing "mcp__fs__read" by prefix
95
- also cleared "mcp__fs__read_file", silently returning a live tool to
96
- the approval-required default (or, for an auto-approved server, to
97
- requiring approval it was configured not to need).
98
- """
99
- if not names:
100
- _dynamic_approval_defaults.clear()
101
- return
102
- for name in names:
103
- _dynamic_approval_defaults.pop(name, None)
104
-
105
-
106
- def is_tool_allowed(
107
- tool_name: str, context: Optional["ToolContext"] = None
108
- ) -> bool:
109
- """Should this tool be callable at all, given current policy?
110
-
111
- Logical AND across layers. The global check is unconditional and
112
- happens first: no agent or skill context can re-enable a tool that
113
- config has disabled.
114
- """
115
- permissions = config.ToolPermissions()
116
- if not getattr(permissions, tool_name, _default_for_unknown_tool(tool_name)):
117
- return False
118
- if context is not None and context.allowed_tools is not None:
119
- return tool_name in context.allowed_tools
120
- return True
121
-
122
-
123
- def requires_approval(
124
- tool_name: str, params: dict, context: Optional["ToolContext"] = None
125
- ) -> bool:
126
- """Does this specific call need a human to approve it before running?
127
-
128
- Logical OR across layers, which is what makes approval_overrides a
129
- one-way ratchet: a context entry can ADD an approval requirement, but
130
- an entry of `False` is indistinguishable from the key being absent
131
- and can never remove one. That asymmetry is D14's intent -- do not
132
- "fix" it into a three-state override, or an agent definition (which
133
- may come from a merely-trusted project directory) could wave a call
134
- past a gate the global config deliberately set.
135
-
136
- Note this function covers the global + context layers only. The
137
- tool's own dynamic approval_check is OR'd in by
138
- ToolRegistry.approval_needed(), which is the single source of truth
139
- both dispatch() and the loop's permission bridge call.
140
- """
141
- approvals = config.ToolApprovals()
142
- if hasattr(approvals, tool_name):
143
- tool_level = getattr(approvals, tool_name)
144
- else:
145
- # No declared field: a dynamically-named tool (§17). Its base
146
- # default is whatever was registered for it, falling back to the
147
- # named default rather than to bare False.
148
- tool_level = _dynamic_approval_defaults.get(
149
- tool_name, _default_for_unknown_approval(tool_name)
150
- )
151
- context_level = (
152
- context.approval_overrides.get(tool_name, False)
153
- if context is not None
154
- else False
155
- )
156
- return tool_level or context_level
157
-
158
-
159
- def assert_permissions_declared(tool_names: Iterable[str]) -> None:
160
- """D24: every statically registered tool must have a field in BOTH
161
- config dataclasses. Raises rather than warning, because the failure
162
- this guards against is invisible at runtime.
163
-
164
- The precedent is `fetch_url`: registered, documented as working, and
165
- denied on every call for its entire life because nobody added the
166
- field. Nothing logged and nothing raised -- the schema was still
167
- advertised to the model, so it kept choosing the tool, and the only
168
- trace was a denial string inside a tool result it then worked around.
169
- Making omission MEANINGFUL for MCP tools (see
170
- _default_for_unknown_tool) is exactly what makes it important that
171
- omission is never accidental for built-in ones.
172
-
173
- Dynamically-named `mcp__*` tools are exempt by design; they can never
174
- have a declared field. Call this after static registration only.
175
- """
176
- permissions = config.ToolPermissions()
177
- approvals = config.ToolApprovals()
178
- missing = [
179
- name
180
- for name in tool_names
181
- if not name.startswith("mcp__")
182
- and not (hasattr(permissions, name) and hasattr(approvals, name))
183
- ]
184
- if missing:
185
- raise RuntimeError(
186
- "Tools are registered with no declared permission/approval "
187
- f"field, so they would be silently denied forever: {sorted(missing)}. "
188
- "Add a bool field for each to BOTH config.ToolPermissions and "
189
- "config.ToolApprovals (ROADMAP_v2 §15, D24)."
190
- )
1
+ """
2
+ security/permissions.py
3
+
4
+ POLICY, not mechanism: "may this tool be called at all?" and "does this
5
+ call need a human to approve it?". tools/registry.py owns dispatch
6
+ mechanics and is the only caller; tool modules never import this.
7
+
8
+ ROADMAP_v2 §15 adds the "stricter wins" rule (D14). Every currently
9
+ active layer is consulted -- the global config dataclasses, plus an
10
+ optional ToolContext contributed by the active agent (§18) and the skills
11
+ it has activated (§19):
12
+
13
+ * allow/deny is a logical AND -- a tool is available only if global
14
+ policy allows it AND every layer that expresses an opinion allows it.
15
+ A globally-disabled tool can never be re-enabled by a context; that
16
+ check runs first and unconditionally.
17
+ * approval is a logical OR -- approval is required if the global
18
+ setting says so, OR the context says so, OR (in the registry) the
19
+ tool's own dynamic approval_check says so. A context can therefore
20
+ tighten a lenient default but can never loosen a strict one.
21
+
22
+ ToolContext is imported for typing only. security/ must not gain a
23
+ runtime dependency on tools/ -- the real direction is tools -> security,
24
+ and inverting it would create a cycle the moment tools/context.py grows
25
+ an import of its own.
26
+ """
27
+
28
+ from collections.abc import Iterable
29
+ from typing import TYPE_CHECKING, Optional
30
+
31
+ import config
32
+ from security import hosted
33
+
34
+ if TYPE_CHECKING: # pragma: no cover - typing only, never imported at runtime
35
+ from tools.context import ToolContext
36
+
37
+
38
+ # The tools whose approval is decided by `shell_approval_mode` and nothing
39
+ # else, so they have a `tool_permissions` field and no `tool_approvals` one.
40
+ # `shell` since §28 (G3): a field there was the ratchet, and every answer it
41
+ # could give is one the mode already names. The two background-session start
42
+ # tools since ROADMAP_v3 §49 (SS16), because they run a command through the
43
+ # same gate -- a second switch over it would be G3's ratchet again.
44
+ #
45
+ # A set named here rather than `name == "shell"` inline, so the exemption
46
+ # has one spelling that tests can hold against the registry: an import-time
47
+ # check in tools/registry.py requires every name here to be registered with
48
+ # shell's own approval check, so the exemption cannot outlive the gate it is
49
+ # an exemption FOR.
50
+ APPROVAL_BY_SHELL_MODE = frozenset({"shell", "shell_background",
51
+ "shell_monitor",
52
+ "shell_interactive"})
53
+
54
+
55
+ def _default_for_unknown_tool(tool_name: str) -> bool:
56
+ """Explicit, named default for tools with no declared field, rather
57
+ than letting getattr's fallback decide by omission.
58
+
59
+ config.ToolPermissions is a static dataclass with one field per known
60
+ tool. MCP tools (§17) are named at connection time
61
+ (`mcp__<server>__<tool>`) and can never have a pre-declared field, so
62
+ a bare `getattr(..., False)` would deny every one of them forever.
63
+ They are allowed here because their real control point is the
64
+ server-level trust gate in §17. Anything else unknown is denied --
65
+ and for statically registered tools, omission is caught outright by
66
+ assert_permissions_declared() at import time (D24), so this branch
67
+ should be unreachable for them.
68
+ """
69
+ return tool_name.startswith("mcp__")
70
+
71
+
72
+ def _default_for_unknown_approval(tool_name: str) -> bool:
73
+ """Approval counterpart to _default_for_unknown_tool.
74
+
75
+ MCP tools default to REQUIRING approval (§17 decision D). They are
76
+ allowed by default but not trusted by default, and those are different
77
+ questions: an MCP server is third-party code that the model can reach
78
+ without the user ever naming it. The project tier is trust-gated
79
+ (D17), but a user-level mcp.json auto-connects, and config files grow
80
+ entries that installers appended.
81
+
82
+ Everything else unknown defaults to not requiring approval, matching
83
+ the previous getattr fallback.
84
+ """
85
+ return tool_name.startswith("mcp__")
86
+
87
+
88
+ # Base approval defaults for tools that cannot have a declared field --
89
+ # populated at connection time from each MCP server's `autoApprove`.
90
+ #
91
+ # This exists because the per-server opt-out CANNOT be expressed as a
92
+ # ToolSpec.approval_check: registry.approval_needed() ORs those in, and OR
93
+ # can only ever tighten. Varying the BASE DEFAULT instead keeps D14's
94
+ # one-way ratchet exactly intact -- a context override can still force
95
+ # approval back on for an auto-approved server, but nothing can wave a
96
+ # call past a gate a stricter layer set.
97
+ _dynamic_approval_defaults: dict = {}
98
+
99
+
100
+ def set_dynamic_approval_default(tool_name: str, required: bool) -> None:
101
+ """Declare the base approval default for a dynamically-named tool."""
102
+ _dynamic_approval_defaults[tool_name] = bool(required)
103
+
104
+
105
+ def clear_dynamic_approval_defaults(*names: str) -> None:
106
+ """Drop defaults for tools that no longer exist. Idempotent, because
107
+ disconnect handling can run more than once for the same server. With
108
+ no arguments, drops all of them.
109
+
110
+ Names are EXACT. This took a PREFIX until §14-§18 review finding f8,
111
+ which is the same over-match hazard `mcp__<server>__<tool>` has one
112
+ layer up and for the same reason -- neither `__` in a server name nor
113
+ `__` in a tool name is illegal. Clearing "mcp__fs__read" by prefix
114
+ also cleared "mcp__fs__read_file", silently returning a live tool to
115
+ the approval-required default (or, for an auto-approved server, to
116
+ requiring approval it was configured not to need).
117
+ """
118
+ if not names:
119
+ _dynamic_approval_defaults.clear()
120
+ return
121
+ for name in names:
122
+ _dynamic_approval_defaults.pop(name, None)
123
+
124
+
125
+ def is_tool_allowed(
126
+ tool_name: str, context: Optional["ToolContext"] = None
127
+ ) -> bool:
128
+ """Should this tool be callable at all, given current policy?
129
+
130
+ Logical AND across layers. The global check is unconditional and
131
+ happens first: no agent or skill context can re-enable a tool that
132
+ config has disabled.
133
+ """
134
+ permissions = config.ToolPermissions()
135
+ if not getattr(permissions, tool_name, _default_for_unknown_tool(tool_name)):
136
+ return False
137
+ # ROADMAP_v3 §79 (HD4). A shared hosted deployment refuses the tools
138
+ # that reach the container itself, whatever config.yaml says: every
139
+ # visitor shares that container and one Unix user. Second to the global
140
+ # check and before any context, for the same reason that check is
141
+ # first -- no agent or skill may re-enable what this layer refuses.
142
+ # HD11 adds the math tools, unless the bridge verified their confinement.
143
+ if tool_name in hosted.refused_tools():
144
+ return False
145
+ if context is not None and context.allowed_tools is not None:
146
+ return tool_name in context.allowed_tools
147
+ return True
148
+
149
+
150
+ def requires_approval(
151
+ tool_name: str, params: dict, context: Optional["ToolContext"] = None
152
+ ) -> bool:
153
+ """Does this specific call need a human to approve it before running?
154
+
155
+ Logical OR across layers, which is what makes approval_overrides a
156
+ one-way ratchet: a context entry can ADD an approval requirement, but
157
+ an entry of `False` is indistinguishable from the key being absent
158
+ and can never remove one. That asymmetry is D14's intent -- do not
159
+ "fix" it into a three-state override, or an agent definition (which
160
+ may come from a merely-trusted project directory) could wave a call
161
+ past a gate the global config deliberately set.
162
+
163
+ Note this function covers the global + context layers only. The
164
+ tool's own dynamic approval_check is OR'd in by
165
+ ToolRegistry.approval_needed(), which is the single source of truth
166
+ both dispatch() and the loop's permission bridge call.
167
+ """
168
+ approvals = config.ToolApprovals()
169
+ if hasattr(approvals, tool_name):
170
+ tool_level = getattr(approvals, tool_name)
171
+ else:
172
+ # No declared field: a dynamically-named tool (§17). Its base
173
+ # default is whatever was registered for it, falling back to the
174
+ # named default rather than to bare False.
175
+ tool_level = _dynamic_approval_defaults.get(
176
+ tool_name, _default_for_unknown_approval(tool_name)
177
+ )
178
+ context_level = (
179
+ context.approval_overrides.get(tool_name, False)
180
+ if context is not None
181
+ else False
182
+ )
183
+ # bool(), because the signature says so and an override is only typed
184
+ # where a definition is PARSED (§67 A28): a ToolContext built in code
185
+ # with {"web_search": "false"} returned the string 'false' (batch 220,
186
+ # #250). Truthiness is unchanged -- that string still TIGHTENS, which is
187
+ # the ratchet above working, not a leak -- only the type is.
188
+ return bool(tool_level or context_level)
189
+
190
+
191
+ def assert_permissions_declared(tool_names: Iterable[str]) -> None:
192
+ """D24: every statically registered tool must have a declared permission
193
+ field, and -- with one deliberate exception -- a declared approval
194
+ field. Raises rather than warning, because the failure
195
+ this guards against is invisible at runtime.
196
+
197
+ The precedent is `fetch_url`: registered, documented as working, and
198
+ denied on every call for its entire life because nobody added the
199
+ field. Nothing logged and nothing raised -- the schema was still
200
+ advertised to the model, so it kept choosing the tool, and the only
201
+ trace was a denial string inside a tool result it then worked around.
202
+ Making omission MEANINGFUL for MCP tools (see
203
+ _default_for_unknown_tool) is exactly what makes it important that
204
+ omission is never accidental for built-in ones.
205
+
206
+ The exception is APPROVAL_BY_SHELL_MODE in approvals: those tools'
207
+ approval is governed solely by `shell_approval_mode`, and a second
208
+ switch there could only force `always` -- exactly what the mode already
209
+ says. A test pins the set as the SOLE exemption, and tools/registry.py
210
+ requires each name in it to carry shell's own approval check, so a
211
+ future omission cannot ride in on it.
212
+
213
+ Dynamically-named `mcp__*` tools are exempt by design; they can never
214
+ have a declared field. Call this after static registration only.
215
+ """
216
+ permissions = config.ToolPermissions()
217
+ approvals = config.ToolApprovals()
218
+ missing = [
219
+ name
220
+ for name in tool_names
221
+ if not name.startswith("mcp__")
222
+ and not (hasattr(permissions, name)
223
+ and (name in APPROVAL_BY_SHELL_MODE
224
+ or hasattr(approvals, name)))
225
+ ]
226
+ if missing:
227
+ raise RuntimeError(
228
+ "Tools are registered with no declared permission/approval "
229
+ f"field, so they would be silently denied forever: {sorted(missing)}. "
230
+ "Add a bool field for each to ToolPermissionsModel and -- "
231
+ f"except {sorted(APPROVAL_BY_SHELL_MODE)}, whose approval lives "
232
+ "solely in shell_approval_mode -- to ToolApprovalsModel in "
233
+ "config_schema.py, and a key for each to tool_permissions "
234
+ "(and, with the same exception, tool_approvals) in config.yaml "
235
+ "(ROADMAP_v2 §15, D24). The field names live in Python so this "
236
+ "check stays a build-time one; the values live in the YAML."
237
+ )