@yahyahammad/venastine 0.1.0

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 (143) hide show
  1. package/.env.example +14 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +14 -0
  4. package/PRIVACY.md +66 -0
  5. package/README.md +878 -0
  6. package/SECURITY.md +88 -0
  7. package/THIRD_PARTY_NOTICES.md +100 -0
  8. package/agents/builtin/compactor.md +75 -0
  9. package/agents/builtin/explore.md +77 -0
  10. package/agents/builtin/grill-me.md +27 -0
  11. package/agents/builtin/initializer.md +94 -0
  12. package/agents/builtin/pipeline-reviewer.md +100 -0
  13. package/agents/builtin/plan.md +88 -0
  14. package/agents/builtin/review.md +74 -0
  15. package/agents/manager.py +195 -0
  16. package/agents/subagent_tool.py +215 -0
  17. package/agents/tui_commands.py +136 -0
  18. package/bin/venastine.mjs +382 -0
  19. package/config.py +1198 -0
  20. package/core/__init__.py +0 -0
  21. package/core/approval.py +115 -0
  22. package/core/client.py +1548 -0
  23. package/core/compaction.py +959 -0
  24. package/core/config_loader.py +1563 -0
  25. package/core/events.py +61 -0
  26. package/core/interaction.py +328 -0
  27. package/core/loop.py +1353 -0
  28. package/core/memory.py +370 -0
  29. package/core/model_windows.py +175 -0
  30. package/core/pipeline_models.py +176 -0
  31. package/core/reasoning/__init__.py +0 -0
  32. package/core/reasoning/authorization.py +130 -0
  33. package/core/reasoning/base.py +219 -0
  34. package/core/reasoning/confidence_scoring.py +468 -0
  35. package/core/reasoning/events.py +149 -0
  36. package/core/reasoning/json_retry.py +219 -0
  37. package/core/reasoning/orchestrator.py +1382 -0
  38. package/core/reasoning/output_writer.py +286 -0
  39. package/core/reasoning/payload_validation.py +398 -0
  40. package/core/reasoning/pipeline_storage.py +361 -0
  41. package/core/reasoning/review.py +615 -0
  42. package/core/reasoning/scholar.py +434 -0
  43. package/core/reasoning/source_corpus.py +327 -0
  44. package/core/reasoning/source_scoring.py +855 -0
  45. package/core/replay.py +167 -0
  46. package/core/session.py +153 -0
  47. package/core/workspace_trust.py +207 -0
  48. package/credentials.py +180 -0
  49. package/database.py +252 -0
  50. package/env_secrets.py +77 -0
  51. package/json_store.py +123 -0
  52. package/logging_setup.py +185 -0
  53. package/main.py +1959 -0
  54. package/mcp_client/__init__.py +15 -0
  55. package/mcp_client/client.py +499 -0
  56. package/mcp_client/config.py +379 -0
  57. package/mcp_client/registration.py +182 -0
  58. package/memories/manager.py +132 -0
  59. package/memories/tui_commands.py +232 -0
  60. package/package.json +73 -0
  61. package/project_init/config_files.py +278 -0
  62. package/project_init/doc_sets.py +330 -0
  63. package/project_init/generator.py +564 -0
  64. package/project_init/manifest.py +406 -0
  65. package/project_init/tui_commands.py +144 -0
  66. package/prompts/__init__.py +0 -0
  67. package/prompts/annotate.md +14 -0
  68. package/prompts/assumption_audit.md +27 -0
  69. package/prompts/claim_extraction.md +34 -0
  70. package/prompts/completeness.md +18 -0
  71. package/prompts/confidence_tiers.md +23 -0
  72. package/prompts/critic_pass.md +24 -0
  73. package/prompts/final_synthesis.md +13 -0
  74. package/prompts/initial_generation.md +14 -0
  75. package/prompts/preliminary_plan.md +23 -0
  76. package/prompts/revalidate.md +25 -0
  77. package/prompts/revise.md +15 -0
  78. package/prompts/source_grounding.md +66 -0
  79. package/prompts/system_prompts.py +262 -0
  80. package/prompts/universal_system_prompt +7 -0
  81. package/prompts/untrusted_content +1 -0
  82. package/providers.json.example +92 -0
  83. package/pyproject.toml +100 -0
  84. package/requirements.txt +72 -0
  85. package/safety/__init__.py +0 -0
  86. package/safety/policy_enforcement.py +682 -0
  87. package/security/__init__.py +0 -0
  88. package/security/capability.py +177 -0
  89. package/security/permissions.py +190 -0
  90. package/security/posture.py +302 -0
  91. package/security/protected_paths.py +309 -0
  92. package/security/sandbox.py +985 -0
  93. package/skills/builtin/crypto/cryptography-verification.md +66 -0
  94. package/skills/builtin/math/formal-specification.md +67 -0
  95. package/skills/builtin/math/numerical-methods.md +66 -0
  96. package/skills/builtin/math/proof-writing.md +61 -0
  97. package/skills/builtin/research/experiment-design.md +62 -0
  98. package/skills/builtin/research/literature-review.md +65 -0
  99. package/skills/builtin/research/reproducibility.md +55 -0
  100. package/skills/builtin/research/source-evaluation.md +70 -0
  101. package/skills/builtin/research/statistical-inference.md +63 -0
  102. package/skills/builtin/research/technical-writing.md +59 -0
  103. package/skills/builtin/security/cybersecurity-research.md +63 -0
  104. package/skills/builtin/software/code-review.md +61 -0
  105. package/skills/builtin/software/debugging.md +61 -0
  106. package/skills/builtin/software/test-design.md +67 -0
  107. package/skills/manager.py +138 -0
  108. package/skills/tui_commands.py +111 -0
  109. package/storage.py +1005 -0
  110. package/tools/base.py +305 -0
  111. package/tools/builtin/__init__.py +0 -0
  112. package/tools/builtin/_math_common.py +377 -0
  113. package/tools/builtin/_net_common.py +61 -0
  114. package/tools/builtin/arxiv.py +223 -0
  115. package/tools/builtin/ask_user.py +213 -0
  116. package/tools/builtin/discrete_math.py +134 -0
  117. package/tools/builtin/fetch_url.py +153 -0
  118. package/tools/builtin/file_ops.py +412 -0
  119. package/tools/builtin/geometry.py +148 -0
  120. package/tools/builtin/get_time.py +20 -0
  121. package/tools/builtin/linear_algebra.py +155 -0
  122. package/tools/builtin/load_skill.py +66 -0
  123. package/tools/builtin/logic.py +96 -0
  124. package/tools/builtin/pin.py +193 -0
  125. package/tools/builtin/probability_stats.py +228 -0
  126. package/tools/builtin/project_docs.py +405 -0
  127. package/tools/builtin/remember.py +158 -0
  128. package/tools/builtin/shell.py +461 -0
  129. package/tools/builtin/symbolic_math.py +119 -0
  130. package/tools/builtin/todo.py +147 -0
  131. package/tools/builtin/web_search.py +151 -0
  132. package/tools/context.py +136 -0
  133. package/tools/isolation.py +314 -0
  134. package/tools/registry.py +897 -0
  135. package/tui/app.py +3423 -0
  136. package/tui/app.tcss +458 -0
  137. package/tui/commands.py +61 -0
  138. package/tui/diffs.py +265 -0
  139. package/tui/preferences.py +182 -0
  140. package/tui/ravens.py +146 -0
  141. package/tui/screens.py +943 -0
  142. package/tui/themes.py +366 -0
  143. package/tui/widgets.py +1239 -0
@@ -0,0 +1,185 @@
1
+ """logging_setup.py
2
+
3
+ Call configure_logging() ONCE, early, from the entry point (main.py once
4
+ ROADMAP.md §1's CLI lands), before any module that might log. Not called
5
+ on import, so tests and library-style usage don't get surprise handlers.
6
+
7
+ Diverges from ROADMAP.md §2's literal "stream=sys.stderr" decision in two
8
+ narrow ways, by explicit product decision:
9
+ 1. Also writes to a rotating file (logs/app.log by default) so tool
10
+ retries survive CLI exit and process close.
11
+ 2. Level is env-overridable via AGENT_LOG_LEVEL instead of a hardcoded
12
+ logging.INFO default. AGENT_LOG_FILE overrides the file path.
13
+
14
+ Idempotent on repeated calls so test runs that invoke configure_logging
15
+ more than once don't stack duplicate handlers and double-emit lines.
16
+ """
17
+
18
+ import logging
19
+ import os
20
+ import sys
21
+ from logging.handlers import RotatingFileHandler
22
+
23
+ # Top-level, not inside format(): this runs on every log record, and
24
+ # safety/policy_enforcement.py is a leaf (stdlib imports only, nothing
25
+ # from this project), so there is no cycle to dodge.
26
+ from safety.policy_enforcement import redact_secrets
27
+
28
+ __all__ = ["configure_logging"]
29
+
30
+ _DEFAULT_FORMAT = "%(asctime)s [%(levelname)s] %(name)s: %(message)s"
31
+ _DEFAULT_DATEFMT = "%Y-%m-%d %H:%M:%S"
32
+
33
+ _DEFAULT_LOG_FILE = "logs/app.log"
34
+ _DEFAULT_LEVEL = "INFO"
35
+
36
+ # Rotation defaults live here, not in config.py: this file owns the
37
+ # logging concern end-to-end (mirrors how ROADMAP.md §2 keeps the whole
38
+ # logging subsystem in one file). Bump via the function signature if
39
+ # needed; there is no project-wide reason to surface them as config yet.
40
+ _DEFAULT_MAX_BYTES = 1_000_000
41
+ _DEFAULT_BACKUP_COUNT = 3
42
+
43
+
44
+ class _RedactingFormatter(logging.Formatter):
45
+ """Secret redaction on the LOG, which was the fourth sink (#132).
46
+
47
+ README enumerates three: "before it reaches the model, the transcript
48
+ or the database". The log is a fourth, and it was never an
49
+ acknowledged exception -- just an unlisted one.
50
+
51
+ `registry.dispatch()` states this exact threat in the comment above
52
+ its redaction call: "an exception message routinely carries the
53
+ request that produced it, and for an HTTP client that means a URL
54
+ with an API key in the query string. Redacting only the success path
55
+ would make a failing tool the way secrets escape." It then calls
56
+ `logger.exception(...)` THIRTEEN LINES EARLIER, so the unredacted
57
+ message and traceback were already on disk by the time
58
+ check_output_policy saw the result. Same string, two sinks, one
59
+ redacted.
60
+
61
+ A FORMATTER, not a logging.Filter, and that is load-bearing.
62
+ `logger.exception` renders the traceback at format time, from
63
+ `record.exc_info` -- and the traceback is precisely what carries the
64
+ upstream URL. A filter rewriting `record.msg` never sees it.
65
+ Formatting the record first and redacting the finished string covers
66
+ the message, the arguments and the traceback in one pass.
67
+
68
+ Fixed here rather than at dispatch's call site because dispatch is
69
+ not the only site: `fetch_url` logs a warning naming the URL it
70
+ failed on, and any future `logger.*` inherits this for free. Fixing
71
+ the one site the issue measured would have left the class open --
72
+ the same producer-vs-consumer argument #47 makes one file over.
73
+ """
74
+
75
+ def format(self, record):
76
+ return redact_secrets(super().format(record))
77
+
78
+
79
+ def _resolve_level(level):
80
+ """Accepts a logging level as int, a name string ("INFO"), a numeric
81
+ string ("20"), or None (in which case AGENT_LOG_LEVEL / the default
82
+ is consulted)."""
83
+ if level is None:
84
+ level = os.environ.get("AGENT_LOG_LEVEL", _DEFAULT_LEVEL)
85
+ if isinstance(level, str):
86
+ # First try a named level ("INFO" -> logging.INFO); fall back to
87
+ # parsing as an int ("20"). Anything else raises ValueError, which
88
+ # is the right failure mode for a misconfigured env var.
89
+ named = getattr(logging, level.upper(), None)
90
+ if isinstance(named, int):
91
+ return named
92
+ return int(level)
93
+ return int(level)
94
+
95
+
96
+ def configure_logging(
97
+ level=None,
98
+ *,
99
+ log_file=None,
100
+ max_bytes=_DEFAULT_MAX_BYTES,
101
+ backup_count=_DEFAULT_BACKUP_COUNT,
102
+ stderr=True,
103
+ ) -> None:
104
+ """Configure the root logger with a stderr handler and a rotating
105
+ file handler.
106
+
107
+ Safe to call more than once: each call clears existing root handlers
108
+ before re-attaching, so repeated invocations (e.g. across tests)
109
+ don't stack duplicates and double-emit lines.
110
+
111
+ Parameters
112
+ ----------
113
+ level:
114
+ Logging level as int, name ("INFO"), numeric string ("20"), or
115
+ None. None falls back to the AGENT_LOG_LEVEL env var, then the
116
+ INFO default.
117
+ log_file:
118
+ Path to the rotating log file. None falls back to the
119
+ AGENT_LOG_FILE env var, then "logs/app.log". Parent directory is
120
+ created if missing.
121
+ max_bytes, backup_count:
122
+ RotatingFileHandler rotation parameters.
123
+ stderr:
124
+ Attach the stderr handler. FALSE FOR THE TUI, and this is not a
125
+ preference. Textual owns the terminal and repaints it; anything
126
+ written to stderr lands on top of the rendered screen, sits over
127
+ the input bar and behind the panels, and disappears at the next
128
+ repaint -- so the message is both corrupting and unreadable. The
129
+ rotating file keeps everything at full detail either way, and
130
+ tui/app.py additionally routes WARNING+ into the transcript so
131
+ nothing that matters is only in a file.
132
+ """
133
+ resolved_level = _resolve_level(level)
134
+ formatter = _RedactingFormatter(_DEFAULT_FORMAT, datefmt=_DEFAULT_DATEFMT)
135
+
136
+ root = logging.getLogger()
137
+ root.setLevel(resolved_level)
138
+
139
+ # Clear any pre-existing handlers so a repeated call does not attach
140
+ # a second stderr and a second file handler on top of the first.
141
+ for handler in list(root.handlers):
142
+ root.removeHandler(handler)
143
+ try:
144
+ handler.close()
145
+ except (OSError, IOError):
146
+ # Closing should not fail loudly, but if a handler is in a
147
+ # weird state we still want to proceed with fresh handlers.
148
+ pass
149
+
150
+ if stderr:
151
+ stderr_handler = logging.StreamHandler(stream=sys.stderr)
152
+ stderr_handler.setFormatter(formatter)
153
+ root.addHandler(stderr_handler)
154
+
155
+ if log_file is None:
156
+ log_file = os.environ.get("AGENT_LOG_FILE", _DEFAULT_LOG_FILE)
157
+ # Normalize relative paths and embedded ../ so makedirs and
158
+ # RotatingFileHandler see a clean absolute path. Not a containment
159
+ # check -- the user can still point AGENT_LOG_FILE anywhere they
160
+ # want; this just prevents accidental path-traversal via relative
161
+ # segments in env-configured paths.
162
+ log_file = os.path.abspath(log_file)
163
+ log_dir = os.path.dirname(log_file)
164
+ try:
165
+ if log_dir and not os.path.isdir(log_dir):
166
+ os.makedirs(log_dir, exist_ok=True)
167
+
168
+ file_handler = RotatingFileHandler(
169
+ log_file,
170
+ maxBytes=max_bytes,
171
+ backupCount=backup_count,
172
+ encoding="utf-8",
173
+ )
174
+ file_handler.setFormatter(formatter)
175
+ root.addHandler(file_handler)
176
+ except OSError as e:
177
+ # Logging to a file is non-essential. If the directory can't be
178
+ # created or the file can't be opened (read-only filesystem,
179
+ # permission denied, disk full), fall back to stderr-only rather
180
+ # than crashing the program at startup.
181
+ print(
182
+ f"Warning: could not create log file at {log_file} ({e}); "
183
+ f"logging to stderr only.",
184
+ file=sys.stderr,
185
+ )