@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.
Files changed (129) hide show
  1. package/.env.example +19 -14
  2. package/CONFIG_ARCHITECTURE.md +2002 -0
  3. package/NOTICE +1 -1
  4. package/README.md +233 -94
  5. package/agents/builtin/build.md +73 -0
  6. package/agents/builtin/general.md +80 -0
  7. package/agents/builtin/plan.md +23 -5
  8. package/agents/builtin/test.md +65 -0
  9. package/agents/builtin/writer.md +67 -0
  10. package/agents/manager.py +261 -195
  11. package/agents/subagent_tool.py +277 -43
  12. package/agents/tui_commands.py +7 -12
  13. package/bin/venastine.mjs +528 -382
  14. package/bin/venastine.py +71 -0
  15. package/cli_commands.py +835 -0
  16. package/config.py +95 -1198
  17. package/config.yaml +1090 -0
  18. package/config_edit.py +1301 -0
  19. package/config_schema.py +966 -0
  20. package/config_update.py +749 -0
  21. package/core/agent_activity.py +158 -20
  22. package/core/ansi.py +452 -0
  23. package/core/approval.py +27 -5
  24. package/core/call_view.py +364 -0
  25. package/core/cancel.py +121 -0
  26. package/core/chatgpt_auth.py +747 -0
  27. package/core/claims_view.py +107 -0
  28. package/core/client.py +1238 -82
  29. package/core/commands.py +454 -0
  30. package/core/compaction.py +830 -66
  31. package/core/config_loader.py +516 -97
  32. package/core/connect.py +686 -0
  33. package/core/events.py +68 -6
  34. package/core/file_mentions.py +280 -0
  35. package/core/interaction.py +87 -4
  36. package/core/line_pattern.py +128 -0
  37. package/core/loop.py +1516 -440
  38. package/core/memory.py +120 -8
  39. package/core/pipeline_models.py +23 -9
  40. package/core/provider_errors.py +234 -0
  41. package/core/reasoning/confidence_scoring.py +70 -54
  42. package/core/reasoning/json_retry.py +19 -1
  43. package/core/reasoning/orchestrator.py +232 -53
  44. package/core/reasoning/output_writer.py +90 -31
  45. package/core/reasoning/payload_validation.py +133 -7
  46. package/core/reasoning/pipeline_storage.py +427 -361
  47. package/core/reasoning/review.py +659 -615
  48. package/core/reasoning/scholar.py +38 -14
  49. package/core/reasoning/source_corpus.py +110 -4
  50. package/core/replay.py +158 -26
  51. package/core/session.py +36 -12
  52. package/core/session_view.py +259 -0
  53. package/core/session_wake.py +259 -0
  54. package/core/shell_sessions.py +1553 -0
  55. package/core/workspace_trust.py +1 -1
  56. package/credentials.py +308 -180
  57. package/database.py +82 -1
  58. package/{PRIVACY.md → docs/PRIVACY.md} +19 -7
  59. package/docs/SECURITY.md +108 -0
  60. package/docs/THIRD_PARTY_NOTICES.md +148 -0
  61. package/env_secrets.py +118 -77
  62. package/json_store.py +236 -16
  63. package/logging_setup.py +121 -11
  64. package/main.py +1671 -199
  65. package/mcp_client/client.py +257 -23
  66. package/mcp_client/config.py +484 -379
  67. package/mcp_client/registration.py +163 -2
  68. package/memories/manager.py +15 -0
  69. package/memories/tui_commands.py +7 -12
  70. package/package.json +234 -4
  71. package/project_init/config_files.py +4 -0
  72. package/project_init/generator.py +201 -37
  73. package/project_init/manifest.py +418 -406
  74. package/project_init/tui_commands.py +7 -4
  75. package/prompts/revalidate.md +1 -1
  76. package/prompts/revise.md +17 -15
  77. package/prompts/system_prompts.py +64 -10
  78. package/providers.json.example +94 -92
  79. package/pyproject.toml +51 -2
  80. package/requirements.txt +252 -29
  81. package/safety/policy_enforcement.py +353 -17
  82. package/security/askpass.py +419 -0
  83. package/security/capability.py +37 -7
  84. package/security/confine.py +484 -0
  85. package/security/hosted.py +182 -0
  86. package/security/permissions.py +54 -7
  87. package/security/posture.py +124 -12
  88. package/security/protected_paths.py +198 -6
  89. package/security/sandbox.py +3262 -139
  90. package/security/secrets.py +855 -0
  91. package/skills/tui_commands.py +3 -4
  92. package/storage.py +368 -35
  93. package/tools/base.py +465 -305
  94. package/tools/builtin/_math_common.py +306 -16
  95. package/tools/builtin/_net_common.py +267 -61
  96. package/tools/builtin/arxiv.py +681 -223
  97. package/tools/builtin/ask_user.py +231 -213
  98. package/tools/builtin/discrete_math.py +35 -4
  99. package/tools/builtin/fetch_url.py +239 -21
  100. package/tools/builtin/file_ops.py +341 -33
  101. package/tools/builtin/geometry.py +184 -148
  102. package/tools/builtin/get_time.py +2 -2
  103. package/tools/builtin/linear_algebra.py +66 -23
  104. package/tools/builtin/load_skill.py +10 -0
  105. package/tools/builtin/logic.py +171 -12
  106. package/tools/builtin/pin.py +46 -12
  107. package/tools/builtin/probability_stats.py +224 -228
  108. package/tools/builtin/project_docs.py +80 -21
  109. package/tools/builtin/remember.py +21 -4
  110. package/tools/builtin/shell.py +586 -67
  111. package/tools/builtin/shell_sessions.py +613 -0
  112. package/tools/builtin/symbolic_math.py +80 -10
  113. package/tools/builtin/todo.py +5 -3
  114. package/tools/builtin/web_search.py +329 -151
  115. package/tools/context.py +23 -0
  116. package/tools/isolation.py +387 -314
  117. package/tools/registry.py +347 -30
  118. package/tui/app.py +4645 -438
  119. package/tui/app.tcss +185 -2
  120. package/tui/commands.py +10 -154
  121. package/tui/diffs.py +286 -265
  122. package/tui/hosted_driver.py +102 -0
  123. package/tui/markdown.py +60 -10
  124. package/tui/meters.py +103 -7
  125. package/tui/screens.py +346 -92
  126. package/tui/themes.py +59 -19
  127. package/tui/widgets.py +1575 -111
  128. package/SECURITY.md +0 -88
  129. package/THIRD_PARTY_NOTICES.md +0 -100
@@ -3,30 +3,71 @@ core/agent_activity.py
3
3
 
4
4
  ROADMAP_v2 §18, batch 59: WHICH agent is running right now, and how deep.
5
5
 
6
- The harness runs exactly one agent at a time -- `core/loop.py` dispatches
7
- tool calls in a plain `for` loop and `spawn_subagent` BLOCKS on the child
8
- run, so there is never a second one alongside. What there can be is a
9
- STACK: a chat turn at depth 0 spawning a subagent at depth 1 spawning
10
- another at depth 2 (config.SUBAGENT_MAX_DEPTH), each frame suspended
11
- inside the one below it. This module is how a shell learns the shape of
12
- that stack while it exists.
6
+ The harness runs a TREE of agents, and until §47 slice 8 it ran a stack.
7
+
8
+ This paragraph used to open "the harness runs exactly one agent at a time",
9
+ and that was measured rather than assumed: `core/loop.py` dispatched tool
10
+ calls in a plain `for` loop and `spawn_subagent` BLOCKED on the child run,
11
+ so there was never a second one alongside. NA9 partitions a response
12
+ instead, so several children of one turn are now PEERS, up to
13
+ config.SUBAGENT_MAX_PARALLEL of them, each still able to nest to
14
+ config.SUBAGENT_MAX_DEPTH. What a shell learns from this module is
15
+ therefore the shape of a tree.
16
+
17
+ Almost nothing here had to change for that, which is the part worth
18
+ knowing: the depth is still ToolContext.subagent_depth, the parent is
19
+ still a ContextVar, and a span still brackets one run. The two things that
20
+ did are outside this file -- the sink that keeps the stack needs a lock
21
+ (NA16), and the panel that draws it needs lineage order rather than
22
+ arrival order (NA17), because a stack can only arrive outermost-first and
23
+ a tree cannot.
13
24
 
14
25
  WHY A CHANNEL AND NOT A LoopEvent, which is the obvious first reach:
15
26
 
16
27
  * A generator cannot yield from inside a nested call. spawn_subagent's
17
- handler runs inside registry.dispatch(), which runs inside _run()'s
18
- `for call in response.tool_calls:` body -- there is no yield point
19
- there, so a child's activity cannot be turned into a parent event
20
- however much one would like it to be.
28
+ handler runs inside registry.dispatch(), which runs inside the loop's
29
+ per-call body -- there is no yield point there, so a child's activity
30
+ cannot be turned into a parent event however much one would like it
31
+ to be.
32
+
33
+ STILL TRUE AFTER §47 SLICE 8, and the distinction is worth stating
34
+ because NA15 adds a queue that looks like a counter-example. That
35
+ conduit carries the PARENT'S own events about its own tool calls, which
36
+ it would have yielded itself had it not handed the work to a thread,
37
+ and it is drained by a frame that is still inside `_run` and can still
38
+ yield. A child's stream reaches nothing: the bullet below is why, and
39
+ D6 is unchanged.
21
40
  * run_agent_conversation drains its OWN _run() through
22
41
  run_to_completion(), so a child's events are consumed internally and
23
42
  never reach the parent's stream. That is not an oversight to route
24
43
  around; §18/D6 returns only the subagent's distilled final text, on
25
44
  the pipeline's "don't share raw history" principle.
26
45
 
27
- So this carries LIFECYCLE ONLY -- a name and a depth, in and out. Never
28
- the child's text, tool calls, or events. A shell that wanted those would
29
- be asking for the thing D6 declines to give it.
46
+ So this carries LIFECYCLE ONLY -- a name, a depth, an identity, and the
47
+ id of the thread the run is writing. Never the child's text, tool calls,
48
+ or events. A shell that wanted those would be asking for the thing D6
49
+ declines to give it.
50
+
51
+ §47 ADDED THE IDENTITY, AND AN IDENTIFIER IS NOT CONTENT. A run already
52
+ writes its whole conversation to its own ConversationThread, and a human
53
+ can already open one by id (`--ref`, `/resume`). What nobody could do was
54
+ find out WHICH thread a row in the sidebar was about. So a span carries
55
+ `id` and `parent_id` now, and `bind()` says which thread it opened.
56
+ Everything a shell then displays it reads back out of the ARCHIVE --
57
+ `core/replay.py`, the same function and the same policy `/resume` uses --
58
+ so nothing here forwards a child's stream to its parent, which is what
59
+ D6 is about. The distinction is the whole design: the channel gained an
60
+ address, not a payload.
61
+
62
+ THE PARENT COMES FROM A ContextVar, NOT FROM A PARAMETER. Five call sites
63
+ open spans and none of them knows what is above it; threading a parent
64
+ through all of them would put the answer in the hands of whoever
65
+ remembers to pass it -- the D24/R13 failure shape. The var is set and
66
+ reset inside the same context manager whose `finally` already makes
67
+ `exit` unforgettable, so the two cannot drift. It is also the shape that
68
+ survives concurrency: a ContextVar is per-thread, so a run submitted to
69
+ an executor takes `contextvars.copy_context()` with it rather than
70
+ reading a variable that would be wrong the moment two children run.
30
71
 
31
72
  It rides the same route response_channel already rides (loop -> dispatch
32
73
  -> handler -> the child's own loop), for the same reason: an out-of-band
@@ -36,12 +77,21 @@ Lives in core/ rather than tui/ because D12 makes the CLI a permanent
36
77
  fallback -- and because nothing here knows what a widget is.
37
78
  """
38
79
 
39
- from contextlib import contextmanager
40
- from dataclasses import dataclass
41
80
  import logging
81
+ from contextlib import contextmanager
82
+ from contextvars import ContextVar
83
+ from dataclasses import dataclass, field
84
+ from typing import Optional
85
+ from uuid import uuid4
42
86
 
43
87
  logger = logging.getLogger(__name__)
44
88
 
89
+ #: The innermost span open on THIS thread, or None. Read by `span()` to
90
+ #: find a new span's parent and by `bind()` to find the run whose thread
91
+ #: has just been created. Module-level and private: nothing outside this
92
+ #: file sets it, so the context manager below is the only writer.
93
+ _CURRENT: ContextVar = ContextVar("venastine_agent_span", default=None)
94
+
45
95
 
46
96
  @dataclass(frozen=True)
47
97
  class AgentSpan:
@@ -51,9 +101,35 @@ class AgentSpan:
51
101
  consumer indenting by it is drawing the same nesting the depth limit
52
102
  is about. Frozen because a span is posted to another thread and read
53
103
  later; a mutable one would be a second writer of the stack.
104
+
105
+ `id` is minted per span rather than derived from anything, because
106
+ the thing it has to distinguish is two runs that agree on every other
107
+ field: a goal turn spawning `explore` twice gives two spans with the
108
+ same name and the same depth, and a sink that could not tell them
109
+ apart had to pop by last match and hope. `parent_id` is the enclosing
110
+ span's, or None at the root.
111
+
112
+ NEITHER IS THE THREAD ID, and the gap between them is deliberate. A
113
+ span opens BEFORE the run it describes creates its thread -- the
114
+ handler brackets the call, the thread is made inside it -- so the
115
+ address arrives later, through `bind()`. A frozen span cannot be
116
+ edited to hold it, which is correct: the binding belongs to the sink,
117
+ which is the thing that has to redraw when it arrives.
54
118
  """
55
119
  name: str
56
120
  depth: int
121
+ # Defaulted so `AgentSpan("explore", 1)` still constructs -- the
122
+ # positional pair is what every existing caller and test writes.
123
+ id: str = field(default_factory=lambda: uuid4().hex)
124
+ parent_id: Optional[str] = None
125
+ # §47. WHICH tool call started this run, when one did. The same
126
+ # kind of fact as the name and the depth -- what the run IS --
127
+ # rather than a second channel: a shell that knows both this and
128
+ # the bound thread can make the CALL LINE in the transcript open
129
+ # the run while it is still going, instead of only once its
130
+ # result comes back. None for the compactor and the reviewer,
131
+ # which no tool call starts.
132
+ call_id: Optional[str] = None
57
133
 
58
134
 
59
135
  class AgentActivity:
@@ -70,8 +146,25 @@ class AgentActivity:
70
146
  def exit(self, span: AgentSpan) -> None:
71
147
  """That run ended -- successfully or not."""
72
148
 
149
+ def bind(self, span_id: str, thread_id) -> None:
150
+ """That run's conversation thread exists, and this is its id.
151
+
152
+ Separate from `enter` because it genuinely happens later: the
153
+ span brackets the call, and the thread is created inside it. A
154
+ sink that wants to make a row openable holds this against the
155
+ span id it was given at `enter`.
156
+
157
+ Called at most once per span, and not at all for a run that
158
+ never gets that far -- a spawn refused before it starts. A run
159
+ whose provider fails at the FIRST CALL is bound all the same:
160
+ `run_agent_conversation` binds as soon as the thread exists, before
161
+ its user message and before any model call, which is what lets a
162
+ failed child still be opened from its spawn line. (This docstring
163
+ said the opposite until batch 91.)
164
+ """
165
+
73
166
  @contextmanager
74
- def span(self, name: str, depth: int):
167
+ def span(self, name: str, depth: int, call_id=None):
75
168
  """Bracket one agent-shaped run.
76
169
 
77
170
  A CONTEXT MANAGER RATHER THAN A PAIR OF CALLS, and that is the
@@ -87,8 +180,20 @@ class AgentActivity:
87
180
  it is merely describing. Logged rather than swallowed silently,
88
181
  so a broken sink is findable -- the same posture
89
182
  tools/registry.dispatch() takes around a tool handler.
183
+
184
+ THE ContextVar IS RESET IN THE SAME `finally` AS `exit`, and that
185
+ pairing is the point rather than a convenience. A token that
186
+ outlived its span would make the NEXT sibling a child of a run
187
+ that has finished -- lineage that is wrong rather than missing,
188
+ which is the harder kind to notice. `reset(token)` rather than
189
+ `set(parent)`, because that is what restores the exact state this
190
+ frame found, including "there was nothing".
90
191
  """
91
- span = AgentSpan(name, depth)
192
+ parent = _CURRENT.get()
193
+ span = AgentSpan(
194
+ name, depth, call_id=call_id,
195
+ parent_id=parent.id if parent is not None else None)
196
+ token = _CURRENT.set(span)
92
197
  try:
93
198
  self.enter(span)
94
199
  except Exception: # noqa: BLE001 -- contained
@@ -96,6 +201,7 @@ class AgentActivity:
96
201
  try:
97
202
  yield span
98
203
  finally:
204
+ _CURRENT.reset(token)
99
205
  try:
100
206
  self.exit(span)
101
207
  except Exception: # noqa: BLE001 -- contained
@@ -106,7 +212,7 @@ NULL = AgentActivity()
106
212
  """The no-op sink. Every non-TUI shell runs on this."""
107
213
 
108
214
 
109
- def span(activity, name: str, depth: int):
215
+ def span(activity, name: str, depth: int, call_id=None):
110
216
  """Bracket a run against an OPTIONAL sink.
111
217
 
112
218
  `activity` is None on every path but the TUI's, and this is what
@@ -115,4 +221,36 @@ def span(activity, name: str, depth: int):
115
221
  `with agent_activity.span(activity, name, depth):` and never have to
116
222
  ask whether anyone is watching.
117
223
  """
118
- return (activity or NULL).span(name, depth)
224
+ return (activity or NULL).span(name, depth, call_id)
225
+
226
+
227
+ def current() -> Optional[AgentSpan]:
228
+ """The innermost span open on this thread, or None.
229
+
230
+ Public because two things outside this module need to know which run
231
+ is speaking without being handed it: `bind()` below, and the approval
232
+ path, which names the asking agent on a modal that would otherwise
233
+ say only which TOOL was asked for.
234
+ """
235
+ return _CURRENT.get()
236
+
237
+
238
+ def bind(activity, thread_id) -> None:
239
+ """Tell the sink which thread the innermost open run is writing.
240
+
241
+ A no-op when nothing is open, which is the ordinary state of a
242
+ top-level `run_agent_conversation` -- the CLI's chat, a test calling
243
+ it directly. That is why the call site needs no branch, matching
244
+ `span()` above.
245
+
246
+ CONTAINED like the sink's other two calls, and for the identical
247
+ reason: this is display machinery. A sink that raises while learning
248
+ an id must not fail the run whose id it was learning.
249
+ """
250
+ span = _CURRENT.get()
251
+ if span is None or thread_id is None:
252
+ return
253
+ try:
254
+ (activity or NULL).bind(span.id, thread_id)
255
+ except Exception: # noqa: BLE001 -- contained
256
+ logger.exception("agent activity sink raised on bind")