@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
package/mcp_client/config.py
CHANGED
|
@@ -1,379 +1,484 @@
|
|
|
1
|
-
"""
|
|
2
|
-
mcp_client/config.py
|
|
3
|
-
|
|
4
|
-
Discovery and merge of `mcp.json`, plus the "seen this user-level server
|
|
5
|
-
before" store. ROADMAP_v2 §17.
|
|
6
|
-
|
|
7
|
-
Two locations, both resolved at CALL time (not import time) so tests can
|
|
8
|
-
redirect them and a moved config dir is picked up without a restart --
|
|
9
|
-
the same rule core/config_loader.py and core/workspace_trust.py follow:
|
|
10
|
-
|
|
11
|
-
user ~/.config/venastine/mcp.json -- you authored it
|
|
12
|
-
project <project>/.venastine/mcp.json -- trust-gated (D17)
|
|
13
|
-
|
|
14
|
-
THE
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
#
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
a
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if self.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
def
|
|
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
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
#
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
#
|
|
290
|
-
#
|
|
291
|
-
#
|
|
292
|
-
#
|
|
293
|
-
#
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
it
|
|
321
|
-
|
|
322
|
-
if not os.path.exists(path):
|
|
323
|
-
return {}
|
|
324
|
-
try:
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
logger.warning("%s
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
"""
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
1
|
+
"""
|
|
2
|
+
mcp_client/config.py
|
|
3
|
+
|
|
4
|
+
Discovery and merge of `mcp.json`, plus the "seen this user-level server
|
|
5
|
+
before" store. ROADMAP_v2 §17.
|
|
6
|
+
|
|
7
|
+
Two locations, both resolved at CALL time (not import time) so tests can
|
|
8
|
+
redirect them and a moved config dir is picked up without a restart --
|
|
9
|
+
the same rule core/config_loader.py and core/workspace_trust.py follow:
|
|
10
|
+
|
|
11
|
+
user ~/.config/venastine/mcp.json -- you authored it
|
|
12
|
+
project <project>/.venastine/mcp.json -- trust-gated (D17)
|
|
13
|
+
|
|
14
|
+
THE USER ONE IS CREATED EMPTY AT STARTUP IF IT IS ABSENT (batch 121,
|
|
15
|
+
owner request). "You authored it" was doing double duty: it is the
|
|
16
|
+
security argument for why that tier needs no trust prompt, and it was
|
|
17
|
+
also the reason nothing ever created the file -- which left the path
|
|
18
|
+
discoverable only from this docstring. Two plausible homes (the harness
|
|
19
|
+
root, and here) and no way to tell from inside a session means an edit
|
|
20
|
+
goes into a file nothing reads. See ensure_user_config.
|
|
21
|
+
|
|
22
|
+
THE PROJECT PATH IS `.venastine/mcp.json`, NOT `<project>/mcp.json`.
|
|
23
|
+
§17/D11 put it at the project root to match Claude Code's convention, but
|
|
24
|
+
workspace_trust hashes only `.venastine/`, and is_trusted() returns True
|
|
25
|
+
outright when that directory is absent. A root-level mcp.json would
|
|
26
|
+
therefore have been ungated and its edits would never have re-prompted --
|
|
27
|
+
in a file whose whole purpose is naming a local command to execute. Under
|
|
28
|
+
`.venastine/` the existing hash, trust prompt and file listing cover it
|
|
29
|
+
with no change to workspace_trust.py at all.
|
|
30
|
+
|
|
31
|
+
Validation is deliberately by CONNECTION, not by schema (§17 decision G):
|
|
32
|
+
unknown keys are ignored so a config pasted from Claude Desktop or Cursor
|
|
33
|
+
works, and an entry we cannot make sense of becomes that one server's
|
|
34
|
+
named connect failure rather than a startup error for everything else.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
import hashlib
|
|
38
|
+
import json
|
|
39
|
+
import logging
|
|
40
|
+
import os
|
|
41
|
+
from dataclasses import dataclass, field
|
|
42
|
+
from typing import Any, Optional
|
|
43
|
+
|
|
44
|
+
from json_store import read_regular_text, write_json_atomic
|
|
45
|
+
|
|
46
|
+
logger = logging.getLogger(__name__)
|
|
47
|
+
|
|
48
|
+
# Keys this harness actually reads. Anything else is ignored, not an
|
|
49
|
+
# error -- see the module docstring. Kept as data so the DEBUG log can
|
|
50
|
+
# name exactly what it skipped.
|
|
51
|
+
_KNOWN_SERVER_KEYS = frozenset({
|
|
52
|
+
"command", "args", "env", "cwd", # stdio
|
|
53
|
+
"type", "url", "headers", # http
|
|
54
|
+
"autoApprove", "auto_approve", # our extension (§17 D)
|
|
55
|
+
"disabled",
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
# Declared `type` values that mean streamable HTTP. `sse` is NOT one of
|
|
59
|
+
# them (#62): D4 promises SSE, the SDK v2 ships sse_client for it, and
|
|
60
|
+
# aliasing it here is how a server that speaks only SSE got offered a
|
|
61
|
+
# streamable handshake it could not answer.
|
|
62
|
+
_STREAMABLE_TYPES = frozenset({"http", "https", "streamable-http", "streamablehttp"})
|
|
63
|
+
_SSE_TYPES = frozenset({"sse"})
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@dataclass
|
|
67
|
+
class ServerConfig:
|
|
68
|
+
"""One entry from an mcp.json `mcpServers` object."""
|
|
69
|
+
name: str
|
|
70
|
+
tier: str # "user" | "project"
|
|
71
|
+
path: str # the file it came from
|
|
72
|
+
transport: str # "stdio" | "http" | "sse" | "unknown"
|
|
73
|
+
command: Optional[str] = None
|
|
74
|
+
args: list = field(default_factory=list)
|
|
75
|
+
env: dict = field(default_factory=dict)
|
|
76
|
+
cwd: Optional[str] = None
|
|
77
|
+
url: Optional[str] = None
|
|
78
|
+
headers: dict = field(default_factory=dict)
|
|
79
|
+
auto_approve: bool = False
|
|
80
|
+
disabled: bool = False
|
|
81
|
+
raw: dict = field(default_factory=dict)
|
|
82
|
+
error: Optional[str] = None # why transport == "unknown"
|
|
83
|
+
|
|
84
|
+
def describe(self) -> str:
|
|
85
|
+
"""One line naming what this server will actually DO -- shown in
|
|
86
|
+
the trust prompt and the first-run warning, where 'informed' has
|
|
87
|
+
to mean seeing the command, not the server's nickname.
|
|
88
|
+
|
|
89
|
+
#60/F1: the fields that change the security posture ride along.
|
|
90
|
+
`autoApprove` decides whether any later prompt ever exists, so a
|
|
91
|
+
one-`y` acknowledgement that never named it consented blind to
|
|
92
|
+
unprompted execution in every future session including all ten
|
|
93
|
+
headless research passes. Env is disclosed by KEY NAME only --
|
|
94
|
+
printing values would put a credential on the terminal, which is
|
|
95
|
+
a different defect. The digest is computed from the raw entry
|
|
96
|
+
(entry_digest), never from this text, so improving the disclosure
|
|
97
|
+
cannot by itself re-ask an acknowledged server; F3's store bump
|
|
98
|
+
is what forces the one re-consent pass.
|
|
99
|
+
|
|
100
|
+
VENASTINE_MCP_ACK_FULL=1 (F2) appends the entry verbatim, for
|
|
101
|
+
debugging and audits. Read at call time, like every other state
|
|
102
|
+
path in this project: it is operator authority, deliberately not
|
|
103
|
+
a settings.json key, because settings.json's precedence lets a
|
|
104
|
+
project tier style a consent screen this flag renders.
|
|
105
|
+
"""
|
|
106
|
+
if self.transport == "stdio":
|
|
107
|
+
argv = " ".join([self.command or ""] + [str(a) for a in self.args])
|
|
108
|
+
text = f"{self.name} [{self.tier}] runs: {argv.strip()}"
|
|
109
|
+
elif self.transport == "http":
|
|
110
|
+
text = f"{self.name} [{self.tier}] connects to: {self.url}"
|
|
111
|
+
elif self.transport == "sse":
|
|
112
|
+
text = f"{self.name} [{self.tier}] connects via SSE to: {self.url}"
|
|
113
|
+
else:
|
|
114
|
+
return f"{self.name} [{self.tier}] UNUSABLE: {self.error}"
|
|
115
|
+
|
|
116
|
+
notes = []
|
|
117
|
+
if self.auto_approve:
|
|
118
|
+
notes.append("AUTO-APPROVED: its tools will run without asking")
|
|
119
|
+
if self.cwd:
|
|
120
|
+
notes.append(f"working directory: {self.cwd}")
|
|
121
|
+
if self.disabled:
|
|
122
|
+
notes.append("disabled")
|
|
123
|
+
if self.env:
|
|
124
|
+
notes.append("env keys: " + ", ".join(sorted(self.env)))
|
|
125
|
+
if self.headers:
|
|
126
|
+
# Same class of surface as env keys, and MORE live since M19
|
|
127
|
+
# stopped discarding them: Authorization is where an http/sse
|
|
128
|
+
# server's credential actually rides (#60 owner follow-up).
|
|
129
|
+
notes.append("header keys: " + ", ".join(sorted(self.headers)))
|
|
130
|
+
lines = [text] + [f" {n}" for n in notes]
|
|
131
|
+
|
|
132
|
+
if os.environ.get("VENASTINE_MCP_ACK_FULL") == "1":
|
|
133
|
+
rendered = json.dumps(self.raw, indent=2, sort_keys=True,
|
|
134
|
+
default=str)
|
|
135
|
+
lines.append(" full entry:")
|
|
136
|
+
lines.extend(f" {line}" for line in rendered.splitlines())
|
|
137
|
+
return "\n".join(lines)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def user_config_path() -> str:
|
|
141
|
+
return os.path.expanduser("~/.config/venastine/mcp.json")
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def project_config_path(project_path: str) -> str:
|
|
145
|
+
return os.path.join(os.path.realpath(project_path), ".venastine", "mcp.json")
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def ensure_user_config() -> Optional[str]:
|
|
149
|
+
"""Create the user-level mcp.json if absent. Returns the path, or None.
|
|
150
|
+
|
|
151
|
+
Batch 121, owner request: "users don't know whether user-level
|
|
152
|
+
mcp.json is at the harness root or ~/.config/venastine". A file that
|
|
153
|
+
exists answers that; a docstring does not.
|
|
154
|
+
|
|
155
|
+
BEHAVIOUR-NEUTRAL BY CONSTRUCTION. `{"mcpServers": {}}` loads as zero
|
|
156
|
+
servers, and it is the one shape _read_file does not warn about -- an
|
|
157
|
+
empty `{}` trips its "no 'mcpServers' object" branch, so the obvious
|
|
158
|
+
seed would have printed a warning about the harness's own file at
|
|
159
|
+
every launch. The skeleton comes from §24's render_mcp() rather than
|
|
160
|
+
being retyped here, so the two tiers cannot drift.
|
|
161
|
+
|
|
162
|
+
NEVER OVERWRITES, and the check is existence rather than content: a
|
|
163
|
+
file someone emptied by hand is still their file.
|
|
164
|
+
|
|
165
|
+
An OSError is a DEBUG line and None. A read-only config directory is
|
|
166
|
+
a reason not to have the convenience, not a reason not to start --
|
|
167
|
+
every other store in that directory fails the same way, except the
|
|
168
|
+
trust store, which raises because a security decision that silently
|
|
169
|
+
did not persist is worse than a crash. This is not one of those.
|
|
170
|
+
|
|
171
|
+
mode=0o600 like its two siblings there: the entries can carry an
|
|
172
|
+
Authorization header, and on the temp file rather than the
|
|
173
|
+
destination because os.replace carries the source's mode across
|
|
174
|
+
(#19). trailing_newline because a human edits this one -- §24's
|
|
175
|
+
scaffold passes it for exactly that reason.
|
|
176
|
+
"""
|
|
177
|
+
from project_init.config_files import render_mcp
|
|
178
|
+
|
|
179
|
+
path = user_config_path()
|
|
180
|
+
if os.path.exists(path):
|
|
181
|
+
return None
|
|
182
|
+
try:
|
|
183
|
+
write_json_atomic(path, render_mcp(), mode=0o600,
|
|
184
|
+
trailing_newline=True)
|
|
185
|
+
except OSError as e:
|
|
186
|
+
logger.debug("Could not create %s: %s", path, e)
|
|
187
|
+
return None
|
|
188
|
+
logger.info("Created user-level mcp.json at %s", path)
|
|
189
|
+
return path
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def _flag(server: str, key: str, value: Any,
|
|
193
|
+
consequence: str) -> Optional[bool]:
|
|
194
|
+
"""A JSON boolean, or None with a warning naming the consequence.
|
|
195
|
+
|
|
196
|
+
NOT bool(value): bool("false") is True, so `"autoApprove": "false"`
|
|
197
|
+
-- a plausible hand edit, and a shape other MCP hosts tolerate --
|
|
198
|
+
would turn the D28 approval gate OFF on a server the user was trying
|
|
199
|
+
to keep gated.
|
|
200
|
+
|
|
201
|
+
WHAT IT DOES NOT DO ANY MORE IS CHOOSE THE ANSWER (batch 150). It
|
|
202
|
+
used to return False for both keys and say that failing closed was
|
|
203
|
+
"the only safe direction for both flags: an unexpectedly-gated server
|
|
204
|
+
prompts, an unexpectedly-enabled one runs third-party code
|
|
205
|
+
unannounced". That is true of `autoApprove` and backwards for
|
|
206
|
+
`disabled`, where False means NOT disabled -- so the sentence's own
|
|
207
|
+
second clause was the outcome it produced: `"disabled": "true"` ran
|
|
208
|
+
the server, and F1's consent line, which reads self.disabled, showed
|
|
209
|
+
it as live.
|
|
210
|
+
|
|
211
|
+
AND NEITHER CONSTANT IS SAFE FOR `disabled`, which is why this
|
|
212
|
+
function no longer picks one. The two plausible misspellings want
|
|
213
|
+
opposite answers -- `"true"` means stop and `"false"` means run --
|
|
214
|
+
and the only thing that distinguishes them is the value, which this
|
|
215
|
+
function exists to refuse to interpret. So the caller decides, and
|
|
216
|
+
for `disabled` the decision is the one this module already makes for
|
|
217
|
+
an entry it cannot make sense of: that one server's NAMED failure
|
|
218
|
+
(decision G). `tests/test_mcp_config.py` pins both directions.
|
|
219
|
+
"""
|
|
220
|
+
if isinstance(value, bool):
|
|
221
|
+
return value
|
|
222
|
+
logger.warning(
|
|
223
|
+
"mcp.json server %r: %s must be true or false, got %r; %s.",
|
|
224
|
+
server, key, value, consequence)
|
|
225
|
+
return None
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def _parse_entry(name: str, entry: Any, tier: str, path: str) -> ServerConfig:
|
|
229
|
+
"""Turns one raw JSON value into a ServerConfig. Never raises: a bad
|
|
230
|
+
entry is returned with transport == 'unknown' and an error string, so
|
|
231
|
+
one malformed server cannot stop the others from connecting."""
|
|
232
|
+
if not isinstance(entry, dict):
|
|
233
|
+
return ServerConfig(name=name, tier=tier, path=path, transport="unknown",
|
|
234
|
+
error=f"expected an object, got {type(entry).__name__}")
|
|
235
|
+
|
|
236
|
+
unknown = set(entry) - _KNOWN_SERVER_KEYS
|
|
237
|
+
if unknown:
|
|
238
|
+
# DEBUG, not WARNING: configs shared with other MCP clients carry
|
|
239
|
+
# keys we don't implement, and making that noisy on every startup
|
|
240
|
+
# trains people to ignore the log.
|
|
241
|
+
logger.debug("mcp.json server %r: ignoring unrecognized keys %s",
|
|
242
|
+
name, sorted(unknown))
|
|
243
|
+
|
|
244
|
+
# accept either spelling; ours is camelCase to match the file's
|
|
245
|
+
# existing style, but a snake_case one shouldn't silently no-op
|
|
246
|
+
auto_approve = _flag(
|
|
247
|
+
name, "autoApprove",
|
|
248
|
+
entry.get("autoApprove", entry.get("auto_approve", False)),
|
|
249
|
+
"gating its tools, which is this flag's safe answer either way")
|
|
250
|
+
disabled = _flag(
|
|
251
|
+
name, "disabled", entry.get("disabled", False),
|
|
252
|
+
"refusing the entry by name, because neither answer is safe for "
|
|
253
|
+
"this flag")
|
|
254
|
+
|
|
255
|
+
cfg = ServerConfig(
|
|
256
|
+
name=name, tier=tier, path=path, transport="unknown",
|
|
257
|
+
env=entry.get("env") or {},
|
|
258
|
+
cwd=entry.get("cwd"),
|
|
259
|
+
headers=entry.get("headers") or {},
|
|
260
|
+
auto_approve=bool(auto_approve),
|
|
261
|
+
disabled=bool(disabled),
|
|
262
|
+
raw=entry,
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
if disabled is None:
|
|
266
|
+
# A NAMED FAILURE, not a chosen answer (batch 150). `False` ran a
|
|
267
|
+
# server the operator had written a key to stop, and `True` would
|
|
268
|
+
# skip one they had written a key to keep -- which was a defect
|
|
269
|
+
# this file's tests had already been written for once, under the
|
|
270
|
+
# name "the mirror defect". Both directions are pinned now by
|
|
271
|
+
# TestAnUnparseableDisabledIsANamedFailure, whose docstring
|
|
272
|
+
# records why the older test was replaced rather than kept green:
|
|
273
|
+
# it asserted `disabled is False`, which is STILL true here and no
|
|
274
|
+
# longer means the server runs.
|
|
275
|
+
# So the entry becomes unusable the same way a bad `args` does:
|
|
276
|
+
# transport stays 'unknown', describe() prints
|
|
277
|
+
# "UNUSABLE: 'disabled' must be true or false" on the
|
|
278
|
+
# acknowledgement screen, _transport_for raises so the server
|
|
279
|
+
# lands in failures by name, and main.py prints it. Nothing runs
|
|
280
|
+
# and nothing is silent, which is the only pair of properties
|
|
281
|
+
# both spellings can have at once. One edit fixes it.
|
|
282
|
+
cfg.error = "'disabled' must be true or false"
|
|
283
|
+
return cfg
|
|
284
|
+
|
|
285
|
+
declared = str(entry.get("type") or "").lower()
|
|
286
|
+
if entry.get("command"):
|
|
287
|
+
raw_args = entry.get("args") or []
|
|
288
|
+
if not isinstance(raw_args, list):
|
|
289
|
+
# list("--verbose") is ['-', '-', 'v', ...]. A natural hand
|
|
290
|
+
# edit therefore became a per-character argv and failed at
|
|
291
|
+
# connect with an opaque error naming none of the cause,
|
|
292
|
+
# defeating this module's rule that a bad entry becomes that
|
|
293
|
+
# one server's NAMED failure.
|
|
294
|
+
cfg.error = "'args' must be an array of strings"
|
|
295
|
+
return cfg
|
|
296
|
+
cfg.transport = "stdio"
|
|
297
|
+
cfg.command = str(entry["command"])
|
|
298
|
+
cfg.args = list(raw_args)
|
|
299
|
+
# SSE only by EXPLICIT declaration (F5): a bare "url" keeps meaning
|
|
300
|
+
# streamable HTTP, because that is what every config written before
|
|
301
|
+
# this branch existed assumed, and URL sniffing would be magic. The
|
|
302
|
+
# aliases below stay streamable; an unsupported declared type still
|
|
303
|
+
# refuses rather than falling through to HTTP (#61's M7).
|
|
304
|
+
elif entry.get("url") and declared in _SSE_TYPES:
|
|
305
|
+
cfg.transport = "sse"
|
|
306
|
+
cfg.url = str(entry["url"])
|
|
307
|
+
elif entry.get("url") and (not declared or declared in _STREAMABLE_TYPES):
|
|
308
|
+
cfg.transport = "http"
|
|
309
|
+
cfg.url = str(entry["url"])
|
|
310
|
+
elif entry.get("url"):
|
|
311
|
+
cfg.error = f"unsupported transport type {declared!r}"
|
|
312
|
+
else:
|
|
313
|
+
cfg.error = "no 'command' (stdio) and no 'url' (http)"
|
|
314
|
+
return cfg
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def _read_file(path: str, tier: str) -> dict:
|
|
318
|
+
"""Reads one mcp.json. A missing file is empty, not an error. A
|
|
319
|
+
corrupt one is reported and treated as empty -- consistent with G:
|
|
320
|
+
it must not take down a session over a file the user may not have
|
|
321
|
+
written, and the message names the file."""
|
|
322
|
+
if not os.path.exists(path):
|
|
323
|
+
return {}
|
|
324
|
+
try:
|
|
325
|
+
# utf-8-sig: mcp.json is commonly copied between hosts and hand
|
|
326
|
+
# edited, so a BOM is realistic and would otherwise be reported as
|
|
327
|
+
# invalid JSON at character 0. Regular files only (batch 219, #214):
|
|
328
|
+
# the project tier's copy arrives with a clone, and one linked to
|
|
329
|
+
# /dev/zero would be read until memory ran out.
|
|
330
|
+
data = json.loads(read_regular_text(path))
|
|
331
|
+
except (OSError, ValueError) as e:
|
|
332
|
+
logger.warning("Could not read %s-level mcp.json at %s: %s", tier, path, e)
|
|
333
|
+
return {}
|
|
334
|
+
|
|
335
|
+
servers = data.get("mcpServers") if isinstance(data, dict) else None
|
|
336
|
+
if servers is None and isinstance(data, dict):
|
|
337
|
+
# Tolerate a bare {"name": {...}} mapping; some tools write it.
|
|
338
|
+
servers = {k: v for k, v in data.items() if isinstance(v, dict)}
|
|
339
|
+
if not isinstance(servers, dict):
|
|
340
|
+
logger.warning("%s-level mcp.json at %s has no 'mcpServers' object; "
|
|
341
|
+
"ignoring it.", tier, path)
|
|
342
|
+
return {}
|
|
343
|
+
|
|
344
|
+
return {name: _parse_entry(name, entry, tier, path)
|
|
345
|
+
for name, entry in servers.items()}
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
def load_server_configs(project_path: str, trusted: bool) -> dict:
|
|
349
|
+
"""All configured servers, keyed by name.
|
|
350
|
+
|
|
351
|
+
USER BEATS PROJECT on a name collision (§17 decision H), which is the
|
|
352
|
+
OPPOSITE of a plain "more specific wins" rule and deliberately so:
|
|
353
|
+
the user tier is what you authored, the project tier is what arrived
|
|
354
|
+
with a repo you cloned. A shadowed agent changes a prompt; a shadowed
|
|
355
|
+
MCP server changes which local command runs under a name you already
|
|
356
|
+
trust. core/config_loader.py's tier order was changed to match, so
|
|
357
|
+
agents, skills and MCP servers now all resolve the same way.
|
|
358
|
+
|
|
359
|
+
Non-colliding servers from BOTH tiers load -- precedence only ever
|
|
360
|
+
breaks same-name ties.
|
|
361
|
+
|
|
362
|
+
Project entries are omitted entirely when `trusted` is False. Absent,
|
|
363
|
+
not loaded-and-disabled: untrusted content should not be reachable by
|
|
364
|
+
a later bug (§14's rule, applied here).
|
|
365
|
+
"""
|
|
366
|
+
merged: dict = {}
|
|
367
|
+
|
|
368
|
+
for cfg in _read_file(user_config_path(), "user").values():
|
|
369
|
+
merged[cfg.name] = cfg
|
|
370
|
+
|
|
371
|
+
if trusted:
|
|
372
|
+
for cfg in _read_file(project_config_path(project_path), "project").values():
|
|
373
|
+
if cfg.name in merged:
|
|
374
|
+
logger.warning(
|
|
375
|
+
"project-level MCP server %r at %s is shadowed by the "
|
|
376
|
+
"user-level definition at %s, which wins.",
|
|
377
|
+
cfg.name, cfg.path, merged[cfg.name].path,
|
|
378
|
+
)
|
|
379
|
+
continue
|
|
380
|
+
merged[cfg.name] = cfg
|
|
381
|
+
|
|
382
|
+
return merged
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
# --- first-run acknowledgement for user-level servers (§17 decision I) ----
|
|
386
|
+
#
|
|
387
|
+
# Project-level servers are covered by D17's trust prompt. User-level ones
|
|
388
|
+
# have no gate at all, on the assumption you authored them -- which is
|
|
389
|
+
# exactly wrong when an installer or another tool appended to the file.
|
|
390
|
+
# Same content-hash keying as workspace_trust, so an edited command
|
|
391
|
+
# re-asks rather than inheriting an old acknowledgement.
|
|
392
|
+
|
|
393
|
+
def known_servers_path() -> str:
|
|
394
|
+
return os.path.expanduser("~/.config/venastine/known_mcp_servers.json")
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
def entry_digest(cfg: ServerConfig) -> str:
|
|
398
|
+
"""Hash of what the entry will DO. sort_keys so key order in the file
|
|
399
|
+
can't produce a different digest for identical configuration."""
|
|
400
|
+
return hashlib.sha256(
|
|
401
|
+
json.dumps(cfg.raw, sort_keys=True, default=str).encode("utf-8")
|
|
402
|
+
).hexdigest()
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
# v2 (#60/F3): the acknowledgement prompt used to omit autoApprove -- the
|
|
406
|
+
# one field that decides whether any future prompt exists -- so consents
|
|
407
|
+
# recorded under v1 were given blind. The store carries a version; a
|
|
408
|
+
# legacy store's entries are treated as UNKNOWN (one re-ask each, under
|
|
409
|
+
# the improved disclosure) and a blind consent never survives the bump.
|
|
410
|
+
KNOWN_STORE_VERSION = 2
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
def _read_store() -> tuple:
|
|
414
|
+
"""(name -> digest mapping, is_legacy). A missing file is empty and
|
|
415
|
+
current. An unreadable one fails CLOSED as empty-and-current: every
|
|
416
|
+
server then looks new and gets re-confirmed, which is the safe
|
|
417
|
+
direction. A readable store in the OLD flat shape is NOT corrupt --
|
|
418
|
+
it is valid v1, and comes back marked legacy."""
|
|
419
|
+
path = known_servers_path()
|
|
420
|
+
if not os.path.exists(path):
|
|
421
|
+
return {}, False
|
|
422
|
+
try:
|
|
423
|
+
with open(path, encoding="utf-8-sig") as f:
|
|
424
|
+
data = json.load(f)
|
|
425
|
+
except (OSError, ValueError):
|
|
426
|
+
logger.warning("Could not read %s; re-confirming every user-level "
|
|
427
|
+
"MCP server.", path)
|
|
428
|
+
return {}, False
|
|
429
|
+
if not isinstance(data, dict):
|
|
430
|
+
logger.warning("%s is not an object; re-confirming every "
|
|
431
|
+
"user-level MCP server.", path)
|
|
432
|
+
return {}, False
|
|
433
|
+
if data.get("version") == KNOWN_STORE_VERSION \
|
|
434
|
+
and isinstance(data.get("servers"), dict):
|
|
435
|
+
return dict(data["servers"]), False
|
|
436
|
+
return {k: v for k, v in data.items()
|
|
437
|
+
if isinstance(k, str)}, True
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
def is_known(cfg: ServerConfig) -> bool:
|
|
441
|
+
"""Whether this exact server entry has already been acknowledged.
|
|
442
|
+
|
|
443
|
+
Reads the store itself rather than taking one. It used to accept a
|
|
444
|
+
pre-read `store=` for callers batching several checks, and no caller
|
|
445
|
+
ever passed one -- so the branch was dead while the parameter went on
|
|
446
|
+
advertising an optimisation nobody could see was unused.
|
|
447
|
+
"""
|
|
448
|
+
servers, legacy = _read_store()
|
|
449
|
+
# F3: a v1 consent was given under a prompt that never named the
|
|
450
|
+
# field it most needed to name. It does not count.
|
|
451
|
+
if legacy:
|
|
452
|
+
return False
|
|
453
|
+
return servers.get(cfg.name) == entry_digest(cfg)
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
def remember_server(cfg: ServerConfig) -> None:
|
|
457
|
+
path = known_servers_path()
|
|
458
|
+
servers, legacy = _read_store()
|
|
459
|
+
if legacy:
|
|
460
|
+
# Carrying the old digests forward would silently convert blind
|
|
461
|
+
# consents into disclosed ones for servers this session never
|
|
462
|
+
# re-asked. They start over; answering y here records THIS server
|
|
463
|
+
# only, and the others keep asking until they are answered.
|
|
464
|
+
servers = {}
|
|
465
|
+
servers[cfg.name] = entry_digest(cfg)
|
|
466
|
+
# ATOMIC since batch 45, and this was the odd one out. Its three
|
|
467
|
+
# sibling stores each wrote through a temp file and os.replace, and
|
|
468
|
+
# each spent four to eight docstring lines on why -- a
|
|
469
|
+
# truncate-then-write leaves the file empty for the length of the
|
|
470
|
+
# write and permanently damaged if the process dies inside it. This
|
|
471
|
+
# one used a bare open(path, "w") and said nothing, for a file that
|
|
472
|
+
# records CONSENT: the same class of data as the trust store, which
|
|
473
|
+
# is the sibling that argues hardest for the guarantee. Sharing the
|
|
474
|
+
# write is what stops a convention four comments long from having a
|
|
475
|
+
# fourth copy that does not follow it.
|
|
476
|
+
#
|
|
477
|
+
# AND ITS MODE, since batch 170: 0o600, as the trust store has. Without
|
|
478
|
+
# one this took open()'s 0o666 less the umask, so under a umask of 002
|
|
479
|
+
# anyone in the user's group could write a consent here and a server
|
|
480
|
+
# would start without asking. Found by triaging CodeQL's alert on
|
|
481
|
+
# json_store's default mode; the default itself is right for the files
|
|
482
|
+
# the agent writes in a workspace.
|
|
483
|
+
write_json_atomic(path, {"version": KNOWN_STORE_VERSION,
|
|
484
|
+
"servers": servers}, mode=0o600)
|