@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
@@ -11,6 +11,14 @@ the same rule core/config_loader.py and core/workspace_trust.py follow:
11
11
  user ~/.config/venastine/mcp.json -- you authored it
12
12
  project <project>/.venastine/mcp.json -- trust-gated (D17)
13
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
+
14
22
  THE PROJECT PATH IS `.venastine/mcp.json`, NOT `<project>/mcp.json`.
15
23
  §17/D11 put it at the project root to match Claude Code's convention, but
16
24
  workspace_trust hashes only `.venastine/`, and is_trusted() returns True
@@ -33,7 +41,7 @@ import os
33
41
  from dataclasses import dataclass, field
34
42
  from typing import Any, Optional
35
43
 
36
- from json_store import write_json_atomic
44
+ from json_store import read_regular_text, write_json_atomic
37
45
 
38
46
  logger = logging.getLogger(__name__)
39
47
 
@@ -125,7 +133,7 @@ class ServerConfig:
125
133
  rendered = json.dumps(self.raw, indent=2, sort_keys=True,
126
134
  default=str)
127
135
  lines.append(" full entry:")
128
- lines.extend(f" {l}" for l in rendered.splitlines())
136
+ lines.extend(f" {line}" for line in rendered.splitlines())
129
137
  return "\n".join(lines)
130
138
 
131
139
 
@@ -137,22 +145,84 @@ def project_config_path(project_path: str) -> str:
137
145
  return os.path.join(os.path.realpath(project_path), ".venastine", "mcp.json")
138
146
 
139
147
 
140
- def _flag(server: str, key: str, value: Any) -> bool:
141
- """A JSON boolean, or False with a warning.
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.
142
195
 
143
196
  NOT bool(value): bool("false") is True, so `"autoApprove": "false"`
144
197
  -- a plausible hand edit, and a shape other MCP hosts tolerate --
145
198
  would turn the D28 approval gate OFF on a server the user was trying
146
- to keep gated. Failing closed is the only safe direction for both
147
- flags: an unexpectedly-gated server prompts, an unexpectedly-enabled
148
- one runs third-party code unannounced.
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.
149
219
  """
150
220
  if isinstance(value, bool):
151
221
  return value
152
222
  logger.warning(
153
- "mcp.json server %r: %s must be true or false, got %r; using false.",
154
- server, key, value)
155
- return False
223
+ "mcp.json server %r: %s must be true or false, got %r; %s.",
224
+ server, key, value, consequence)
225
+ return None
156
226
 
157
227
 
158
228
  def _parse_entry(name: str, entry: Any, tier: str, path: str) -> ServerConfig:
@@ -171,20 +241,47 @@ def _parse_entry(name: str, entry: Any, tier: str, path: str) -> ServerConfig:
171
241
  logger.debug("mcp.json server %r: ignoring unrecognized keys %s",
172
242
  name, sorted(unknown))
173
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
+
174
255
  cfg = ServerConfig(
175
256
  name=name, tier=tier, path=path, transport="unknown",
176
257
  env=entry.get("env") or {},
177
258
  cwd=entry.get("cwd"),
178
259
  headers=entry.get("headers") or {},
179
- # accept either spelling; ours is camelCase to match the file's
180
- # existing style, but a snake_case one shouldn't silently no-op
181
- auto_approve=_flag(
182
- name, "autoApprove",
183
- entry.get("autoApprove", entry.get("auto_approve", False))),
184
- disabled=_flag(name, "disabled", entry.get("disabled", False)),
260
+ auto_approve=bool(auto_approve),
261
+ disabled=bool(disabled),
185
262
  raw=entry,
186
263
  )
187
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
+
188
285
  declared = str(entry.get("type") or "").lower()
189
286
  if entry.get("command"):
190
287
  raw_args = entry.get("args") or []
@@ -227,9 +324,10 @@ def _read_file(path: str, tier: str) -> dict:
227
324
  try:
228
325
  # utf-8-sig: mcp.json is commonly copied between hosts and hand
229
326
  # edited, so a BOM is realistic and would otherwise be reported as
230
- # invalid JSON at character 0.
231
- with open(path, "r", encoding="utf-8-sig") as f:
232
- data = json.load(f)
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))
233
331
  except (OSError, ValueError) as e:
234
332
  logger.warning("Could not read %s-level mcp.json at %s: %s", tier, path, e)
235
333
  return {}
@@ -322,7 +420,7 @@ def _read_store() -> tuple:
322
420
  if not os.path.exists(path):
323
421
  return {}, False
324
422
  try:
325
- with open(path, "r", encoding="utf-8-sig") as f:
423
+ with open(path, encoding="utf-8-sig") as f:
326
424
  data = json.load(f)
327
425
  except (OSError, ValueError):
328
426
  logger.warning("Could not read %s; re-confirming every user-level "
@@ -375,5 +473,12 @@ def remember_server(cfg: ServerConfig) -> None:
375
473
  # is the sibling that argues hardest for the guarantee. Sharing the
376
474
  # write is what stops a convention four comments long from having a
377
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.
378
483
  write_json_atomic(path, {"version": KNOWN_STORE_VERSION,
379
- "servers": servers})
484
+ "servers": servers}, mode=0o600)