@yahyahammad/venastine 0.1.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 +249 -93
- 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 +280 -23
- package/agents/tui_commands.py +31 -21
- 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 +256 -0
- 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 +1249 -82
- package/core/commands.py +454 -0
- package/core/compaction.py +1735 -959
- 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 +2566 -1353
- package/core/memory.py +482 -370
- 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 +315 -167
- 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 +1672 -198
- 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 +21 -14
- package/package.json +303 -73
- 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 +149 -100
- package/requirements.txt +252 -29
- package/safety/policy_enforcement.py +1082 -682
- 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 +1338 -1005
- 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 +374 -29
- package/tui/app.py +5281 -397
- package/tui/app.tcss +290 -9
- package/tui/commands.py +26 -61
- package/tui/diffs.py +286 -265
- package/tui/history.py +128 -0
- package/tui/hosted_driver.py +102 -0
- package/tui/markdown.py +1329 -0
- package/tui/meters.py +364 -0
- package/tui/screens.py +346 -92
- package/tui/themes.py +599 -366
- package/tui/widgets.py +2673 -116
- package/SECURITY.md +0 -88
- package/THIRD_PARTY_NOTICES.md +0 -100
package/agents/subagent_tool.py
CHANGED
|
@@ -13,12 +13,20 @@ Rev. 1 sketch's `depth: int` parameter and `allowed_tools=` kwarg are
|
|
|
13
13
|
both gone: depth lives on ToolContext.subagent_depth, and §15 replaced
|
|
14
14
|
allowed_tools with context= everywhere.
|
|
15
15
|
|
|
16
|
+
§47 added two more declared names, `memory` and `call_id`, and they are
|
|
17
|
+
what the child's thread records as its PARENT. The spawn already returned
|
|
18
|
+
`subagent_thread_id` to the model, so the edge existed -- as a repr
|
|
19
|
+
inside a JSON blob in one message row, which nothing could query and
|
|
20
|
+
replay skips. Stored on the child's own row, it survives the process and
|
|
21
|
+
lets a `▸ spawn_subagent` line still open its run tomorrow.
|
|
22
|
+
|
|
16
23
|
core.loop is imported INSIDE run(), not at module top: tools/registry.py
|
|
17
24
|
imports this module to register it, and core.loop imports tools.registry
|
|
18
25
|
-- a top-level import here would close that cycle at import time.
|
|
19
26
|
"""
|
|
20
27
|
|
|
21
28
|
import config
|
|
29
|
+
from core import agent_activity
|
|
22
30
|
from storage import THREAD_KIND_SUBAGENT
|
|
23
31
|
from tools.context import ToolContext
|
|
24
32
|
|
|
@@ -49,6 +57,38 @@ TOOL_SCHEMA = {
|
|
|
49
57
|
}
|
|
50
58
|
|
|
51
59
|
|
|
60
|
+
def has_agents() -> bool:
|
|
61
|
+
"""ToolSpec.available_check (TECHNICAL_DEBT 13, batch 110).
|
|
62
|
+
|
|
63
|
+
The schema above tells the model to name an "Agent name exactly as
|
|
64
|
+
listed in the Available agents catalog". With no SPAWNABLE agent
|
|
65
|
+
discovered there is no such catalog, so the tool's only possible
|
|
66
|
+
answer is `Unknown agent` -- a schema the model can see, choose, and
|
|
67
|
+
never get value from, which is the fetch_url damage class §15 exists
|
|
68
|
+
to fix. `load_skill.has_skills` is the same declaration for the same
|
|
69
|
+
reason, and `pin`, `unpin` and `remember` each carry one.
|
|
70
|
+
|
|
71
|
+
Reads the SAME function prompt assembly uses (agent_catalog_text, via
|
|
72
|
+
prompts/system_prompts.with_catalogs) rather than a parallel check, so
|
|
73
|
+
"advertised" and "catalogued" cannot drift apart. That is the whole
|
|
74
|
+
point of the choice: batch 51 shipped two spawnable agents, so the
|
|
75
|
+
live instance of this was gone and only the asymmetry remained.
|
|
76
|
+
|
|
77
|
+
ROSTER-WIDE, NOT PER-RUN, because `available_check` takes no context.
|
|
78
|
+
It answers "is there any spawnable agent at all". A run whose
|
|
79
|
+
`spawn_targets` empties the list is still the business of
|
|
80
|
+
`refusal_reason` and of `agent_catalog_text(targets)`, which read the
|
|
81
|
+
same restriction from the two sides it has.
|
|
82
|
+
|
|
83
|
+
Imported inside the function for the reason the module docstring
|
|
84
|
+
gives about core.loop: tools/registry.py imports this module, and
|
|
85
|
+
prompts/system_prompts.py imports the registry.
|
|
86
|
+
"""
|
|
87
|
+
from prompts import system_prompts
|
|
88
|
+
|
|
89
|
+
return bool(system_prompts.agent_catalog_text())
|
|
90
|
+
|
|
91
|
+
|
|
52
92
|
def refusal_reason(params: dict, context=None):
|
|
53
93
|
"""Why this spawn would be refused, or None (§32 A7, #70).
|
|
54
94
|
|
|
@@ -72,6 +112,12 @@ def refusal_reason(params: dict, context=None):
|
|
|
72
112
|
if parent.subagent_depth >= config.SUBAGENT_MAX_DEPTH:
|
|
73
113
|
return (f"Maximum subagent nesting depth "
|
|
74
114
|
f"({config.SUBAGENT_MAX_DEPTH}) reached")
|
|
115
|
+
# Depth first, which is the order the docstring above pins; then
|
|
116
|
+
# whether there are arguments to read at all (batch 146). A refusal
|
|
117
|
+
# rather than a raise, because this runs above dispatch()'s
|
|
118
|
+
# containment -- tools/base.py carries the one copy of what that costs.
|
|
119
|
+
if not isinstance(params, dict):
|
|
120
|
+
return "spawn_subagent requires an object of arguments."
|
|
75
121
|
name = params.get("agent_name")
|
|
76
122
|
task = params.get("task")
|
|
77
123
|
if not name or not task:
|
|
@@ -79,9 +125,58 @@ def refusal_reason(params: dict, context=None):
|
|
|
79
125
|
"'task'.")
|
|
80
126
|
from agents.manager import manager
|
|
81
127
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
128
|
+
agent = manager.get(name)
|
|
129
|
+
if agent is None:
|
|
130
|
+
# "the roster", not "the catalog", and the distinction is the one
|
|
131
|
+
# A16 turns on: `manager.get` reads the ROSTER (every agent the
|
|
132
|
+
# loader discovered) while `agent_catalog_text()` is the CATALOG
|
|
133
|
+
# (the spawnable subset). This message claimed the catalog was the
|
|
134
|
+
# membership test for as long as it was not -- so for an agent that
|
|
135
|
+
# was in the roster and off the catalog, the catalog's answer was
|
|
136
|
+
# "absent" and this function's was "spawn it", and the one string a
|
|
137
|
+
# model ever sees about membership described a test that was not
|
|
138
|
+
# being run. Defect shape 9 inside the function that owns the
|
|
139
|
+
# contract. The wording was wrong whichever way A16 had gone.
|
|
140
|
+
return (f"Unknown agent: {name!r} is not one of this harness's "
|
|
141
|
+
f"agents.")
|
|
142
|
+
# A16 (ROADMAP_v3 §62), which REVERSES §32 A3/A4's "advertisement
|
|
143
|
+
# only". Before this, `refusal_reason` never read `spawnable`, so
|
|
144
|
+
# `spawn_subagent` would spawn any agent the loader had discovered, by
|
|
145
|
+
# name -- including one that A3's asymmetry had deliberately left OFF
|
|
146
|
+
# the catalog. A3 argued that a stranger's silence must get the safe
|
|
147
|
+
# answer, and the measured consequence of "reads as false" was that the
|
|
148
|
+
# agent became INVISIBLE rather than unreachable: a project-tier agent
|
|
149
|
+
# omitting the field was absent from the prompt a user might read and
|
|
150
|
+
# callable by any text that named it. For the careless author the
|
|
151
|
+
# default was safe; for the adversarial one it was the quieter option,
|
|
152
|
+
# which is the opposite ranking from the one A3 argues.
|
|
153
|
+
#
|
|
154
|
+
# BEFORE spawn_targets and after the unknown-agent check: an unknown
|
|
155
|
+
# name must still report that it is unknown rather than that it is not
|
|
156
|
+
# permitted, and this is a property of the agent being spawned where
|
|
157
|
+
# spawn_targets is a property of the parent.
|
|
158
|
+
#
|
|
159
|
+
# `is not True` rather than `not`, because `None` means undeclared at
|
|
160
|
+
# the user and project tiers and A3's reading of silence is unchanged --
|
|
161
|
+
# only its consequence is.
|
|
162
|
+
if getattr(agent, "spawnable", None) is not True:
|
|
163
|
+
return (f"{name!r} is not a spawnable agent. It can be used by hand "
|
|
164
|
+
f"with /agent, which is unaffected.")
|
|
165
|
+
# LAST, because the checks above are the live contract this
|
|
166
|
+
# docstring describes and an unknown name must still report that it
|
|
167
|
+
# is unknown rather than that it is not permitted.
|
|
168
|
+
#
|
|
169
|
+
# A REFUSAL RATHER THAN A NARROWING, which is the whole point of the
|
|
170
|
+
# field. C6 caps the child's tools at the parent's, so without this
|
|
171
|
+
# a parent that should not be delegating the work at all gets a
|
|
172
|
+
# child that runs anyway with pieces missing -- `plan` spawning
|
|
173
|
+
# `build` came back unable to `write` or `edit`, and neither side
|
|
174
|
+
# could tell. Refusing says so in a sentence the model can act on,
|
|
175
|
+
# and A7 means it says so BEFORE a human is asked to sign anything.
|
|
176
|
+
if parent.spawn_targets is not None and name not in parent.spawn_targets:
|
|
177
|
+
return (f"{name!r} is not an agent this one may spawn. "
|
|
178
|
+
f"Available here: "
|
|
179
|
+
f"{', '.join(sorted(parent.spawn_targets)) or 'none'}.")
|
|
85
180
|
return None
|
|
86
181
|
|
|
87
182
|
|
|
@@ -131,12 +226,49 @@ def request_payload(params: dict, context=None) -> dict:
|
|
|
131
226
|
"candidates": manager.candidate_approvals(child)}
|
|
132
227
|
|
|
133
228
|
|
|
229
|
+
def _child_pair(agent, parent_run) -> tuple:
|
|
230
|
+
"""`(model, provider)` a spawned child runs on.
|
|
231
|
+
|
|
232
|
+
THREE TIERS, read top to bottom (ROADMAP_v3 §57, SM2):
|
|
233
|
+
|
|
234
|
+
* The agent's OWN pin, which is its identity: an agent that names a
|
|
235
|
+
model for being a different model must get it. A HALF pin keeps
|
|
236
|
+
today's rule exactly -- the named half, the other from the parent
|
|
237
|
+
run -- and opts the agent out of `/submodel` WHOLE (SM6), because
|
|
238
|
+
a pinned model name against the submodel's provider is a pair
|
|
239
|
+
nobody chose.
|
|
240
|
+
* `/submodel`'s pair, for an agent that pins neither half. It beats
|
|
241
|
+
the parent run's pair at every depth (SM7): it is the model for
|
|
242
|
+
subagents as a class, and a parent's pin is that parent's identity
|
|
243
|
+
rather than its children's. Read at SPAWN time, so a choice made
|
|
244
|
+
between turns reaches the next spawn without a restart.
|
|
245
|
+
* The parent run's pair, then the harness default -- what every
|
|
246
|
+
spawn got before §57, and still what one gets with nothing set.
|
|
247
|
+
"""
|
|
248
|
+
from core import pipeline_models
|
|
249
|
+
from core.loop import DEFAULT_PROVIDER
|
|
250
|
+
|
|
251
|
+
if not agent.pins_model:
|
|
252
|
+
chosen = pipeline_models.resolve("subagent")
|
|
253
|
+
if chosen is not None:
|
|
254
|
+
return chosen["model"], chosen["provider_name"]
|
|
255
|
+
model = agent.model or (parent_run.model if parent_run else None) \
|
|
256
|
+
or config.MODEL_NAME
|
|
257
|
+
provider = agent.provider \
|
|
258
|
+
or (parent_run.provider_name if parent_run else None) \
|
|
259
|
+
or DEFAULT_PROVIDER
|
|
260
|
+
return model, provider
|
|
261
|
+
|
|
262
|
+
|
|
134
263
|
def run(params: dict, parent_context=None, parent_run=None,
|
|
135
|
-
response_channel=None, signoff=None
|
|
264
|
+
response_channel=None, signoff=None, activity=None,
|
|
265
|
+
memory=None, call_id=None, cancel=None) -> dict:
|
|
266
|
+
from agents.manager import manager
|
|
136
267
|
from core.loop import (
|
|
137
|
-
|
|
268
|
+
DEFAULT_SYSTEM_PROMPT,
|
|
269
|
+
RunAgentLoop,
|
|
270
|
+
with_persona,
|
|
138
271
|
)
|
|
139
|
-
from agents.manager import manager
|
|
140
272
|
|
|
141
273
|
parent = parent_context or ToolContext()
|
|
142
274
|
# §32 A7. The SAME function the loop consulted before deciding
|
|
@@ -175,41 +307,166 @@ def run(params: dict, parent_context=None, parent_run=None,
|
|
|
175
307
|
# asked -- a headless run, where the child gets no grant anyway.
|
|
176
308
|
granted = set(signoff) if signoff else set()
|
|
177
309
|
|
|
178
|
-
|
|
179
|
-
#
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
or DEFAULT_PROVIDER
|
|
310
|
+
model, provider = _child_pair(agent, parent_run)
|
|
311
|
+
# The parent's level, unvalidated here on purpose: a child on its own
|
|
312
|
+
# pin or on the /submodel pair may be a model that refuses it, and
|
|
313
|
+
# core.client.effort_for drops a level the receiving model does not
|
|
314
|
+
# list at the send, with a warning. One validator at the wire rather
|
|
315
|
+
# than a guess at each site that can change the model.
|
|
185
316
|
effort = parent_run.effort if parent_run else None
|
|
186
317
|
|
|
187
|
-
|
|
188
|
-
|
|
318
|
+
# Batch 59. THE SPAN AND THE PASS-DOWN ARE ONE CHANGE, and the
|
|
319
|
+
# pass-down is the half that does the work: `activity=activity` on the
|
|
320
|
+
# call below is what lets the child's OWN spawn_subagent open a span
|
|
321
|
+
# too, so a shell sees depth 2 rather than only the spawn it can
|
|
322
|
+
# already infer from tool_call_start. Without it this reports exactly
|
|
323
|
+
# what the TUI knew before the batch.
|
|
324
|
+
#
|
|
325
|
+
# A context manager rather than a pair of calls, because the exit has
|
|
326
|
+
# to happen when the child RAISES -- a provider error inside a
|
|
327
|
+
# subagent must not leave a row on screen describing a run that is
|
|
328
|
+
# over. run_agent_conversation does not contain its own exceptions
|
|
329
|
+
# (core/events.py: "exceptions raised mid-loop propagate naturally"),
|
|
330
|
+
# so this is a reachable path rather than a defensive one.
|
|
331
|
+
#
|
|
332
|
+
# `child.subagent_depth` and not a local count: C3 already maintains
|
|
333
|
+
# that number and a second one would be free to disagree with it.
|
|
334
|
+
from core import shell_sessions
|
|
335
|
+
|
|
336
|
+
# ROADMAP_v3 §49 (SS9). Everything the child's first turn and any wake
|
|
337
|
+
# turn after it share. A wake IS that run continuing -- the same
|
|
338
|
+
# prompt, context, channel, grant and sink -- so the two calls take one
|
|
339
|
+
# dict rather than two argument lists that could drift apart.
|
|
340
|
+
common = dict(
|
|
189
341
|
model=model,
|
|
190
342
|
provider_name=provider,
|
|
191
343
|
max_steps=agent.max_steps or config.MAX_ITERATIONS,
|
|
192
344
|
context=child,
|
|
193
345
|
effort=effort,
|
|
194
|
-
# `child`, not the agent's own context: C6 intersects with
|
|
195
|
-
# parent, so a parent that excluded spawn_subagent must not
|
|
196
|
-
# the catalog re-invite its child to spawn one (review
|
|
346
|
+
# `child`, not the agent's own context: C6 intersects with
|
|
347
|
+
# the parent, so a parent that excluded spawn_subagent must not
|
|
348
|
+
# have the catalog re-invite its child to spawn one (review
|
|
349
|
+
# f19).
|
|
197
350
|
# #68: the child's own facts, not the parent's. A subagent
|
|
198
351
|
# spawned from a headless run inherits no channel, so its
|
|
199
352
|
# catalogs must be decided by what IT can call -- the same
|
|
200
|
-
# values handed to run_agent_conversation
|
|
353
|
+
# values handed to run_agent_conversation below.
|
|
201
354
|
system_prompt=manager.system_prompt_for(
|
|
202
|
-
agent, DEFAULT_SYSTEM_PROMPT,
|
|
355
|
+
agent, with_persona(DEFAULT_SYSTEM_PROMPT, model, provider),
|
|
356
|
+
context=child,
|
|
203
357
|
callable_only=response_channel is None,
|
|
204
358
|
granted=granted),
|
|
205
359
|
response_channel=response_channel,
|
|
206
360
|
granted_tools=granted if (response_channel is not None
|
|
207
361
|
and granted) else None,
|
|
208
|
-
#
|
|
209
|
-
#
|
|
210
|
-
|
|
362
|
+
# The recursion. Inherited exactly as response_channel is, and
|
|
363
|
+
# for the same reason: the child is a run in its own right and
|
|
364
|
+
# whatever is watching this stack is watching that one too.
|
|
365
|
+
activity=activity,
|
|
366
|
+
# ROADMAP_v3 §61 (CN7). Inherited exactly as `activity` above is,
|
|
367
|
+
# and for a sharper version of the same reason: the child is a
|
|
368
|
+
# run in its own right, and a stop aimed at the turn that spawned
|
|
369
|
+
# it has to reach it, or the parent waits out a child it has
|
|
370
|
+
# already asked to end.
|
|
371
|
+
cancel=cancel,
|
|
211
372
|
)
|
|
373
|
+
with agent_activity.span(activity, agent.name, child.subagent_depth,
|
|
374
|
+
call_id) as span:
|
|
375
|
+
# ROADMAP_v3 §49 (SS17). The child is a wake CONSUMER: a session it
|
|
376
|
+
# starts is reported inside this call and nowhere else, which is
|
|
377
|
+
# what makes starting one allowed at all in this run.
|
|
378
|
+
with shell_sessions.consuming():
|
|
379
|
+
try:
|
|
380
|
+
response = RunAgentLoop.run_agent_conversation(
|
|
381
|
+
user_goal=task,
|
|
382
|
+
# §27 AC1. A spawned agent's thread is not a
|
|
383
|
+
# conversation anyone will resume, and one goal-mode
|
|
384
|
+
# turn can spawn several.
|
|
385
|
+
thread_kind=THREAD_KIND_SUBAGENT,
|
|
386
|
+
# §47. WHO spawned this thread, stored on the child's
|
|
387
|
+
# own row.
|
|
388
|
+
#
|
|
389
|
+
# `memory` and `call_id` are injected by dispatch() the
|
|
390
|
+
# same way the values in `common` are -- the parent's
|
|
391
|
+
# live ConversationMemory, and the model's id for THIS
|
|
392
|
+
# call. Both are None on a path that reaches run()
|
|
393
|
+
# directly (every test that calls it by hand), and the
|
|
394
|
+
# child is then simply a thread with no recorded
|
|
395
|
+
# parent, which is what it was before that batch.
|
|
396
|
+
#
|
|
397
|
+
# THE CALL ID IS WHAT MAKES THE EDGE SPECIFIC. One turn
|
|
398
|
+
# can spawn `explore` three times, so the agent name
|
|
399
|
+
# identifies the roster entry and not the run; the call
|
|
400
|
+
# id is the only thing that ties one child to one
|
|
401
|
+
# `▸ spawn_subagent` line.
|
|
402
|
+
thread_parent=getattr(memory, "thread_id", None),
|
|
403
|
+
thread_parent_call=call_id,
|
|
404
|
+
thread_agent=agent.name,
|
|
405
|
+
**common,
|
|
406
|
+
)
|
|
407
|
+
# SS9. The child does not answer its parent while its own
|
|
408
|
+
# background sessions are still running: it sleeps HERE, is
|
|
409
|
+
# woken here, and returns once there is nothing left to
|
|
410
|
+
# report. D6 is untouched -- what crosses back is still one
|
|
411
|
+
# distilled answer.
|
|
412
|
+
response = _sleep_for_sessions(response, common)
|
|
413
|
+
except BaseException:
|
|
414
|
+
# A child that RAISED has no thread to report to, and its
|
|
415
|
+
# sessions would outlive the run that started them --
|
|
416
|
+
# holding slots against the process-wide cap for as long
|
|
417
|
+
# as their timeouts. The SPAN is the handle: it is frozen
|
|
418
|
+
# and carries no address, so the child's thread id may
|
|
419
|
+
# never have reached this frame, while every session
|
|
420
|
+
# records the span it was started inside.
|
|
421
|
+
shell_sessions.sessions.kill_by_span(
|
|
422
|
+
span.id, shell_sessions.KILL_OWNER_FAILED)
|
|
423
|
+
raise
|
|
212
424
|
return {
|
|
213
425
|
"result": response.text,
|
|
214
426
|
"subagent_thread_id": str(response.thread_id),
|
|
215
427
|
}
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
def _sleep_for_sessions(response, common: dict):
|
|
431
|
+
"""Stay inside the spawn while the child's sessions report (SS9, SS20).
|
|
432
|
+
|
|
433
|
+
Returns the response the child ends on: its first answer when it
|
|
434
|
+
started no sessions, or the answer to the last wake it was given.
|
|
435
|
+
|
|
436
|
+
THE LIMIT IS WHY THIS TERMINATES. A subagent has no user to type a
|
|
437
|
+
message, so the consecutive-wake count it shares with every other
|
|
438
|
+
owner can never be reset from outside -- past it the manager stops
|
|
439
|
+
handing out batches and holds them instead. SS20 makes that the end of
|
|
440
|
+
the run rather than a wait for something that cannot happen: the
|
|
441
|
+
remaining sessions are stopped, and the results of stopping them are
|
|
442
|
+
what the one final wake carries.
|
|
443
|
+
"""
|
|
444
|
+
from core import shell_sessions
|
|
445
|
+
|
|
446
|
+
sessions = shell_sessions.sessions
|
|
447
|
+
thread_id = response.thread_id
|
|
448
|
+
while True:
|
|
449
|
+
batch = sessions.wait_for_wake(thread_id)
|
|
450
|
+
if batch:
|
|
451
|
+
response = _wake(response, thread_id, batch, common)
|
|
452
|
+
continue
|
|
453
|
+
if not sessions.suspended(thread_id):
|
|
454
|
+
return response
|
|
455
|
+
sessions.kill_owned(thread_id, shell_sessions.KILL_WAKE_LIMIT)
|
|
456
|
+
held = sessions.take_held(thread_id)
|
|
457
|
+
if held:
|
|
458
|
+
response = _wake(response, thread_id, held, common)
|
|
459
|
+
# Anything that last turn started has nobody left to report to,
|
|
460
|
+
# and nothing after this point will ever wake this thread again.
|
|
461
|
+
sessions.kill_owned(thread_id, shell_sessions.KILL_WAKE_LIMIT)
|
|
462
|
+
return response
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
def _wake(response, thread_id, events, common: dict):
|
|
466
|
+
"""One wake turn in the child's own thread, under its own run."""
|
|
467
|
+
from core.loop import RunAgentLoop
|
|
468
|
+
from core.session_wake import build_wake
|
|
469
|
+
|
|
470
|
+
text, record = build_wake(events)
|
|
471
|
+
return RunAgentLoop.wake_conversation(
|
|
472
|
+
thread_id=thread_id, text=text, harness=record, **common)
|
package/agents/tui_commands.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"""
|
|
2
2
|
agents/tui_commands.py
|
|
3
3
|
|
|
4
|
-
ROADMAP_v2
|
|
5
|
-
register into
|
|
4
|
+
ROADMAP_v2 §18, D6 user-initiated half: /agent, /goal and /grill-me
|
|
5
|
+
register into §16's slash registry. The shell hosts the commands; this
|
|
6
6
|
section owns them -- the same mechanism-vs-policy split tools/registry.py
|
|
7
|
-
uses for tools. TUI-only for now (CLI stays unchanged per the
|
|
7
|
+
uses for tools. TUI-only for now (CLI stays unchanged per the §18 scope
|
|
8
8
|
decision); the model-initiated half lives in subagent_tool.py and works
|
|
9
9
|
in every shell.
|
|
10
10
|
|
|
@@ -13,8 +13,9 @@ deliberately does NOT import tui.app, so app.py can import it without a
|
|
|
13
13
|
cycle.
|
|
14
14
|
"""
|
|
15
15
|
|
|
16
|
-
from
|
|
17
|
-
from
|
|
16
|
+
from agents.manager import GRILL_ME_TASK, manager
|
|
17
|
+
from tui.commands import bind
|
|
18
|
+
from tui.commands import registry as commands
|
|
18
19
|
|
|
19
20
|
|
|
20
21
|
def _cmd_agent(app, args: str) -> None:
|
|
@@ -31,8 +32,9 @@ def _cmd_agent(app, args: str) -> None:
|
|
|
31
32
|
return
|
|
32
33
|
if args == "default":
|
|
33
34
|
app.active_agent = None
|
|
34
|
-
app._transcript.write_system("Active agent cleared
|
|
35
|
+
app._transcript.write_system("Active agent cleared — default harness.")
|
|
35
36
|
_note_skills_under_new_context(app)
|
|
37
|
+
_refresh_agent_panel(app)
|
|
36
38
|
return
|
|
37
39
|
agent = manager.get(args)
|
|
38
40
|
if agent is None:
|
|
@@ -43,15 +45,29 @@ def _cmd_agent(app, args: str) -> None:
|
|
|
43
45
|
return
|
|
44
46
|
app.active_agent = agent
|
|
45
47
|
app._transcript.write_system(
|
|
46
|
-
f"Active agent: {agent.name}
|
|
48
|
+
f"Active agent: {agent.name} — {agent.description}")
|
|
47
49
|
_note_skills_under_new_context(app)
|
|
50
|
+
_refresh_agent_panel(app)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _refresh_agent_panel(app) -> None:
|
|
54
|
+
"""Batch 59: the panel's root row IS the active agent, so a
|
|
55
|
+
switch has to repaint it.
|
|
56
|
+
|
|
57
|
+
getattr rather than a direct call because this module is driven
|
|
58
|
+
against stub apps in tests/test_agents.py that carry a transcript
|
|
59
|
+
and nothing else -- and /agent must not start depending on a
|
|
60
|
+
sidebar widget to do its actual job."""
|
|
61
|
+
refresh = getattr(app, "refresh_agent_panel", None)
|
|
62
|
+
if refresh is not None:
|
|
63
|
+
refresh()
|
|
48
64
|
|
|
49
65
|
|
|
50
66
|
def _note_skills_under_new_context(app) -> None:
|
|
51
67
|
"""K2's activation note is computed against the context active at
|
|
52
68
|
activation time; an /agent switch changes the context for every
|
|
53
69
|
subsequent turn, so re-check active skills and say what is now
|
|
54
|
-
denied (review
|
|
70
|
+
denied (review §19-20 f21). Advisory only -- enforcement still
|
|
55
71
|
happens per call via is_tool_allowed."""
|
|
56
72
|
from skills.manager import manager as skill_manager
|
|
57
73
|
|
|
@@ -104,7 +120,7 @@ def _cmd_grill(app, args: str) -> None:
|
|
|
104
120
|
prompt -- it reads the live history directly (no digest loss)."""
|
|
105
121
|
if app._busy:
|
|
106
122
|
app._transcript.write_error(
|
|
107
|
-
"Still working
|
|
123
|
+
"Still working — wait for this turn to finish.")
|
|
108
124
|
return
|
|
109
125
|
agent = manager.get("grill-me")
|
|
110
126
|
if agent is None:
|
|
@@ -114,23 +130,17 @@ def _cmd_grill(app, args: str) -> None:
|
|
|
114
130
|
# run_one_shot owns the WHOLE assembly (#170): the channel, the
|
|
115
131
|
# catalog facts and the run must come from one answer, so nothing is
|
|
116
132
|
# decided here. (Review f19's "no context, deliberately" answered a
|
|
117
|
-
# question
|
|
133
|
+
# question §25 R15 replaced -- what matters now is not which policy
|
|
118
134
|
# governs but whether anything can answer, and only the run knows.)
|
|
119
|
-
app.run_one_shot(
|
|
120
|
-
agent,
|
|
121
|
-
"Grill this thread: surface what still needs a decision.",
|
|
122
|
-
)
|
|
135
|
+
app.run_one_shot(agent, GRILL_ME_TASK)
|
|
123
136
|
|
|
124
137
|
|
|
125
138
|
def register_agent_commands() -> None:
|
|
126
|
-
"""Idempotent
|
|
139
|
+
"""Idempotent — registering by name overwrites, matching §16's
|
|
127
140
|
register_builtin_commands()."""
|
|
128
141
|
for command in (
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
_cmd_goal, "[text|clear]"),
|
|
133
|
-
SlashCommand("grill-me", "surface what still needs a decision",
|
|
134
|
-
_cmd_grill),
|
|
142
|
+
bind("agent", _cmd_agent),
|
|
143
|
+
bind("goal", _cmd_goal),
|
|
144
|
+
bind("grill-me", _cmd_grill),
|
|
135
145
|
):
|
|
136
146
|
commands.register(command)
|