@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
package/agents/manager.py CHANGED
@@ -1,195 +1,261 @@
1
- """
2
- agents/manager.py
3
-
4
- ROADMAP_v2 §18. AgentManager discovers agent `.md` files across the three
5
- tiers and exposes lookup by name plus the §18 scope-composition rules.
6
-
7
- Thin by design: discovery, frontmatter parsing, and tier precedence
8
- (D29: harness > user > project) all live in core/config_loader.py, which
9
- runs at initialize() time. This file adds only the agent-specific policy
10
- composition that §18 owns and that §20 (subagent review) will call:
11
-
12
- * active_context() -- the ToolContext for a session-scoped active
13
- agent (/agent switch): the agent's own restrictions at depth 0.
14
- * child_context() -- the ToolContext for a spawned subagent: C6's
15
- intersection-with-parent (never union) plus a depth increment (C3).
16
- * system_prompt_for() -- base + catalogs + the agent's body + opt-in
17
- project context, assembled in one place so the TUI worker and
18
- spawn_subagent cannot drift apart.
19
- """
20
-
21
- from typing import Optional
22
-
23
- from core import config_loader
24
- from core.config_loader import AgentDef
25
- from memories.manager import manager as memory_manager
26
- from tools.context import ToolContext
27
-
28
-
29
- class AgentManager:
30
- """Lookup + scope composition over the loader's discovered agents."""
31
-
32
- def get(self, name: str) -> Optional[AgentDef]:
33
- return config_loader.get_agent(name)
34
-
35
- def names(self) -> list:
36
- return sorted(config_loader.get_agents())
37
-
38
- def all(self) -> dict:
39
- return config_loader.get_agents()
40
-
41
- @staticmethod
42
- def active_context(agent: AgentDef) -> ToolContext:
43
- """ToolContext for running AS this agent (session-scoped /agent
44
- switch). The agent's own restrictions at depth 0 -- no parent to
45
- intersect with, no nesting."""
46
- allowed = (
47
- set(agent.allowed_tools)
48
- if agent.allowed_tools is not None else None
49
- )
50
- return ToolContext(
51
- allowed_tools=allowed,
52
- approval_overrides=dict(agent.approval_overrides),
53
- subagent_depth=0,
54
- )
55
-
56
- @staticmethod
57
- def child_context(
58
- agent: AgentDef, parent_context: Optional[ToolContext],
59
- ) -> ToolContext:
60
- """ToolContext for a subagent spawned WHILE running under
61
- parent_context. C6: intersection, never union -- a restricted
62
- parent must not escape its restriction by spawning a permissive
63
- child. C3: depth increments so the nesting limit is enforceable.
64
-
65
- An agent that declares no allowed_tools inherits the parent's
66
- restriction unchanged (it may not widen it either).
67
-
68
- APPROVAL COMPOSES THE SAME WAY (§14-§18 review f12, decision S2).
69
- §18's spec sketch built the child's overrides from the agent
70
- definition alone, which drops the parent's. C6 reasoned about
71
- allowed_tools and never considered the approval axis, so the same
72
- escalation it exists to prevent was open one field over: a parent
73
- declaring `approval_overrides: {web_search: true}` prompts on
74
- every search, then spawns a child that computes
75
- approval_needed(web_search) == False and runs it ungated.
76
-
77
- Union rather than replace. Only True entries carry -- a False is
78
- indistinguishable from absent under D14's OR, so unioning can
79
- only ever tighten, which is what makes it safe to do silently."""
80
- parent = parent_context or ToolContext()
81
- if agent.allowed_tools is not None:
82
- own = set(agent.allowed_tools)
83
- child_allowed = own & (
84
- parent.allowed_tools if parent.allowed_tools is not None
85
- else own
86
- )
87
- else:
88
- child_allowed = (
89
- set(parent.allowed_tools)
90
- if parent.allowed_tools is not None else None
91
- )
92
- overrides = {k: v for k, v in parent.approval_overrides.items() if v}
93
- overrides.update(agent.approval_overrides)
94
- return ToolContext(
95
- allowed_tools=child_allowed,
96
- approval_overrides=overrides,
97
- subagent_depth=parent.subagent_depth + 1,
98
- )
99
-
100
- @staticmethod
101
- def candidate_approvals(child_context: ToolContext) -> list:
102
- """Tools the subagent could reach that would each need approval.
103
-
104
- ONE helper, TWO callers -- the sign-off prompt's notice text and
105
- the grant the child actually receives. Computing the list twice
106
- would let what the user approved drift from what the child got,
107
- which is the whole substance of the sign-off.
108
-
109
- Params are empty because there are none yet: a path-dependent
110
- approval_check (file_ops outside the workspace, shell on a
111
- non-inert command) cannot be resolved before the call exists, so
112
- those still prompt at call time through the inherited channel.
113
-
114
- §25 (R2) filters those tools OUT of the list rather than merely
115
- letting them re-prompt. They were never grantable by name, and the
116
- loop now enforces that -- so leaving them here would make the
117
- sign-off notice promise authority the grant does not carry, which
118
- is worse than not offering it. What the user reads and what the
119
- child receives have to be the same list; that is the whole
120
- substance of a sign-off, and this helper exists to keep them one.
121
-
122
- §25 (R13) adds the second filter, and #67 is why it is here rather
123
- than only in core/reasoning/authorization.py. Both functions
124
- answer "what may be pre-granted", both were built from
125
- headless_hidden + grantable, and only the pipeline's one then
126
- subtracted an exclusion list -- which lived in the pipeline's
127
- module where this one could not see it. So this list offered
128
- `spawn_subagent` and `remember`, the two tools R4 and M17 exist to
129
- keep out of a grant, and R4's argument is ABOUT this sign-off.
130
- Now both read one per-tool declaration.
131
-
132
- The LOOSE half of the pair: GRANT_SIGNOFF_ONLY passes here and is
133
- refused by the pipeline. A human answering in the moment, about
134
- one named agent, for one turn, is the consent write_project_doc's
135
- notice was written for; ten unattended passes on one launch-time
136
- tick is not.
137
- """
138
- from tools.base import GRANT_NEVER
139
- from tools.registry import registry
140
-
141
- return sorted(
142
- name for name in registry.headless_hidden(child_context)
143
- if registry.grantable(name)
144
- and registry.grant_policy(name) != GRANT_NEVER
145
- )
146
-
147
- @staticmethod
148
- def system_prompt_for(agent: AgentDef, base_prompt: str,
149
- active_skills=None, context=None,
150
- callable_only: bool = False,
151
- granted=None) -> str:
152
- """The full system prompt for a run AS this agent: base + skill /
153
- agent catalogs, then the agent's own body, then the project's
154
- AGENTS.md iff the agent opts in (use_project_context). One
155
- assembly point so every caller produces the same prompt.
156
-
157
- active_skills (§19) reaches only the catalog, where it MARKS the
158
- skills whose bodies the shell pins separately. Bodies are not
159
- added here -- see with_catalogs' K6 note.
160
-
161
- context (§20 review f19, generalised): the ToolContext this run
162
- will actually use. It reaches with_catalogs, which suppresses a
163
- catalog whose tool the context excludes -- otherwise a restricted
164
- agent is told to "call the load_skill tool" it does not have.
165
- Pass the SAME context the run gets: child_context() for a spawned
166
- subagent, so a parent's restriction suppresses the invitation too;
167
- active_context() for a /agent switch. None means the run is under
168
- global policy only, and both catalogs apply."""
169
- import prompts.system_prompts as system_prompts
170
-
171
- # callable_only / granted (#68): forwarded, not decided here.
172
- # This function knows which agent is running; whether anything
173
- # can answer an approval question is the RUN's fact, and the
174
- # caller is the one holding it. Defaulting to the attended
175
- # answer keeps both TUI call sites correct with no argument.
176
- prompt = system_prompts.with_catalogs(
177
- base_prompt, active_skills, context,
178
- callable_only=callable_only, granted=granted)
179
- prompt = f"{prompt}\n\n## Agent: {agent.name}\n\n{agent.body}"
180
- context = config_loader.context_for_agent(agent)
181
- if context:
182
- prompt = f"{prompt}\n\n## Project context\n\n{context}"
183
- # ROADMAP_v2 §21b: durable memories, the third context tier beside
184
- # the project's AGENTS.md and gated the same way (use_memory).
185
- # Appended HERE and not inside with_catalogs, which feeds
186
- # pass_prompt() -- injecting there would put every memory into all
187
- # ten research passes, which is §19's K6 trap in its second
188
- # instance.
189
- memories = memory_manager.prompt_fragment(agent)
190
- if memories:
191
- prompt = f"{prompt}\n\n{memories}"
192
- return prompt
193
-
194
-
195
- manager = AgentManager()
1
+ """
2
+ agents/manager.py
3
+
4
+ ROADMAP_v2 §18. AgentManager discovers agent `.md` files across the three
5
+ tiers and exposes lookup by name plus the §18 scope-composition rules.
6
+
7
+ Thin by design: discovery, frontmatter parsing, and tier precedence
8
+ (D29: harness > user > project) all live in core/config_loader.py, which
9
+ runs at initialize() time. This file adds only the agent-specific policy
10
+ composition that §18 owns and that §20 (subagent review) will call:
11
+
12
+ * active_context() -- the ToolContext for a session-scoped active
13
+ agent (/agent switch): the agent's own restrictions at depth 0.
14
+ * child_context() -- the ToolContext for a spawned subagent: C6's
15
+ intersection-with-parent (never union) plus a depth increment (C3).
16
+ * system_prompt_for() -- base + catalogs + the agent's body + opt-in
17
+ project context, assembled in one place so the TUI worker and
18
+ spawn_subagent cannot drift apart.
19
+ """
20
+
21
+ from typing import Optional
22
+
23
+ from core import config_loader
24
+ from core.config_loader import AgentDef
25
+ from memories.manager import manager as memory_manager
26
+ from tools.context import ToolContext
27
+
28
+ #: What /grill-me asks, in either shell (§18; shared since ROADMAP_v3 §89).
29
+ GRILL_ME_TASK = "Grill this thread: surface what still needs a decision."
30
+
31
+
32
+ class AgentManager:
33
+ """Lookup + scope composition over the loader's discovered agents."""
34
+
35
+ def get(self, name: str) -> Optional[AgentDef]:
36
+ return config_loader.get_agent(name)
37
+
38
+ def names(self) -> list:
39
+ return sorted(config_loader.get_agents())
40
+
41
+ def all(self) -> dict:
42
+ return config_loader.get_agents()
43
+
44
+ @staticmethod
45
+ def active_context(agent: AgentDef) -> ToolContext:
46
+ """ToolContext for running AS this agent (session-scoped /agent
47
+ switch). The agent's own restrictions at depth 0 -- no parent to
48
+ intersect with, no nesting."""
49
+ allowed = (
50
+ set(agent.allowed_tools)
51
+ if agent.allowed_tools is not None else None
52
+ )
53
+ targets = (
54
+ set(agent.spawn_targets)
55
+ if agent.spawn_targets is not None else None
56
+ )
57
+ return ToolContext(
58
+ allowed_tools=allowed,
59
+ approval_overrides=dict(agent.approval_overrides),
60
+ subagent_depth=0,
61
+ spawn_targets=targets,
62
+ )
63
+
64
+ @staticmethod
65
+ def child_context(
66
+ agent: AgentDef, parent_context: Optional[ToolContext],
67
+ ) -> ToolContext:
68
+ """ToolContext for a subagent spawned WHILE running under
69
+ parent_context. C6: intersection, never union -- a restricted
70
+ parent must not escape its restriction by spawning a permissive
71
+ child. C3: depth increments so the nesting limit is enforceable.
72
+
73
+ An agent that declares no allowed_tools inherits the parent's
74
+ restriction unchanged (it may not widen it either).
75
+
76
+ APPROVAL COMPOSES THE SAME WAY (§14-§18 review f12, decision S2).
77
+ §18's spec sketch built the child's overrides from the agent
78
+ definition alone, which drops the parent's. C6 reasoned about
79
+ allowed_tools and never considered the approval axis, so the same
80
+ escalation it exists to prevent was open one field over: a parent
81
+ declaring `approval_overrides: {web_search: true}` prompts on
82
+ every search, then spawns a child that computes
83
+ approval_needed(web_search) == False and runs it ungated.
84
+
85
+ Union rather than replace. Only True entries carry -- a False is
86
+ indistinguishable from absent under D14's OR, so unioning can
87
+ only ever tighten, which is what makes it safe to do silently.
88
+
89
+ BOTH SIDES ARE FILTERED, and batch 150 is why. The parent's dict
90
+ was filtered and the agent's was merged over it raw, so a `False`
91
+ in the child's frontmatter OVERWROTE the parent's `True` and the
92
+ sentence above was false of the line below it: a parent that
93
+ prompts on every search spawned a child that did not, which is
94
+ the exact escalation the paragraph before this one describes.
95
+ It did not heal one hop further out either -- the next `if v`
96
+ dropped the False rather than restoring the True, so the
97
+ tightening was gone permanently rather than suspended for one
98
+ run. Three of the four quadrants had tests; the one the code got
99
+ wrong was the one with none.
100
+
101
+ The cost is not only the gate. `candidate_approvals` reads this
102
+ same dict, and it is BOTH the sign-off notice and the grant the
103
+ child receives -- measured, the loosened tool left the candidate
104
+ list entirely, so the user was neither asked at call time nor
105
+ told at sign-off time.
106
+
107
+ `active_context` needs no filter and deliberately has none: at
108
+ depth 0 there is no parent to overwrite, a False is inert under
109
+ D14's OR, and the next hop's filter drops it. Measured both
110
+ ways rather than reasoned about, because "the other composer
111
+ looks similar" is how a fix grows past its finding."""
112
+ parent = parent_context or ToolContext()
113
+ if agent.allowed_tools is not None:
114
+ own = set(agent.allowed_tools)
115
+ child_allowed = own & (
116
+ parent.allowed_tools if parent.allowed_tools is not None
117
+ else own
118
+ )
119
+ else:
120
+ child_allowed = (
121
+ set(parent.allowed_tools)
122
+ if parent.allowed_tools is not None else None
123
+ )
124
+ overrides = {k: v for k, v in parent.approval_overrides.items() if v}
125
+ overrides.update(
126
+ {k: v for k, v in agent.approval_overrides.items() if v})
127
+ # SPAWN TARGETS COMPOSE THE SAME WAY, for C6's own reason one
128
+ # field further out. The refusal that reads this field is checked
129
+ # against the context a run holds, so a field that applied only at
130
+ # depth 0 would be escapable by nesting: an agent forbidden to
131
+ # reach `build` could spawn something that was not, and have that
132
+ # one spawn it. Intersection makes the restriction survive the
133
+ # hop, and an agent declaring none inherits its parent's roster
134
+ # unchanged rather than widening back to everything.
135
+ if agent.spawn_targets is not None:
136
+ own_targets = set(agent.spawn_targets)
137
+ child_targets = own_targets & (
138
+ parent.spawn_targets if parent.spawn_targets is not None
139
+ else own_targets
140
+ )
141
+ else:
142
+ child_targets = (
143
+ set(parent.spawn_targets)
144
+ if parent.spawn_targets is not None else None
145
+ )
146
+ return ToolContext(
147
+ allowed_tools=child_allowed,
148
+ approval_overrides=overrides,
149
+ subagent_depth=parent.subagent_depth + 1,
150
+ spawn_targets=child_targets,
151
+ )
152
+
153
+ @staticmethod
154
+ def candidate_approvals(child_context: ToolContext) -> list:
155
+ """Tools the subagent could reach that would each need approval.
156
+
157
+ ONE helper, TWO callers -- the sign-off prompt's notice text and
158
+ the grant the child actually receives. Computing the list twice
159
+ would let what the user approved drift from what the child got,
160
+ which is the whole substance of the sign-off.
161
+
162
+ Params are empty because there are none yet: a path-dependent
163
+ approval_check (file_ops outside the workspace, shell on a
164
+ non-inert command) cannot be resolved before the call exists, so
165
+ those still prompt at call time through the inherited channel.
166
+
167
+ §25 (R2) filters those tools OUT of the list rather than merely
168
+ letting them re-prompt. They were never grantable by name, and the
169
+ loop now enforces that -- so leaving them here would make the
170
+ sign-off notice promise authority the grant does not carry, which
171
+ is worse than not offering it. What the user reads and what the
172
+ child receives have to be the same list; that is the whole
173
+ substance of a sign-off, and this helper exists to keep them one.
174
+
175
+ §25 (R13) adds the second filter, and #67 is why it is here rather
176
+ than only in core/reasoning/authorization.py. Both functions
177
+ answer "what may be pre-granted", both were built from
178
+ headless_hidden + grantable, and only the pipeline's one then
179
+ subtracted an exclusion list -- which lived in the pipeline's
180
+ module where this one could not see it. So this list offered
181
+ `spawn_subagent` and `remember`, the two tools R4 and M17 exist to
182
+ keep out of a grant, and R4's argument is ABOUT this sign-off.
183
+ Now both read one per-tool declaration.
184
+
185
+ EMPTY FOR EVERY SHIPPED AGENT, on every install, and that is a
186
+ ruled scope rather than a gap (TECHNICAL_DEBT 83, batch 139).
187
+ The pool this returns from is the gated-with-no-approval_check
188
+ set -- the MCP tools plus `write_project_doc` -- and the
189
+ intersection with `child_context` is what empties it: all six
190
+ spawnable shipped agents narrow `allowed_tools` to built-ins,
191
+ and an agent file cannot name `mcp__server__tool` for a server
192
+ that did not exist when it was written. So the sign-off's
193
+ PICKER branch belongs to an agent that declines to narrow, or
194
+ one naming a gated tool outright, which is a user- or
195
+ project-tier file. A shipped spawn gets the no-candidates
196
+ branch, which `tui/screens.py` builds deliberately.
197
+
198
+ The LOOSE half of the pair: GRANT_SIGNOFF_ONLY passes here and is
199
+ refused by the pipeline. A human answering in the moment, about
200
+ one named agent, for one turn, is the consent write_project_doc's
201
+ notice was written for; ten unattended passes on one launch-time
202
+ tick is not.
203
+ """
204
+ from tools.base import GRANT_NEVER
205
+ from tools.registry import registry
206
+
207
+ return sorted(
208
+ name for name in registry.headless_hidden(child_context)
209
+ if registry.grantable(name)
210
+ and registry.grant_policy(name) != GRANT_NEVER
211
+ )
212
+
213
+ @staticmethod
214
+ def system_prompt_for(agent: AgentDef, base_prompt: str,
215
+ active_skills=None, context=None,
216
+ callable_only: bool = False,
217
+ granted=None) -> str:
218
+ """The full system prompt for a run AS this agent: base + skill /
219
+ agent catalogs, then the agent's own body, then the project's
220
+ AGENTS.md iff the agent opts in (use_project_context). One
221
+ assembly point so every caller produces the same prompt.
222
+
223
+ active_skills (§19) reaches only the catalog, where it MARKS the
224
+ skills whose bodies the shell pins separately. Bodies are not
225
+ added here -- see with_catalogs' K6 note.
226
+
227
+ context (§20 review f19, generalised): the ToolContext this run
228
+ will actually use. It reaches with_catalogs, which suppresses a
229
+ catalog whose tool the context excludes -- otherwise a restricted
230
+ agent is told to "call the load_skill tool" it does not have.
231
+ Pass the SAME context the run gets: child_context() for a spawned
232
+ subagent, so a parent's restriction suppresses the invitation too;
233
+ active_context() for a /agent switch. None means the run is under
234
+ global policy only, and both catalogs apply."""
235
+ import prompts.system_prompts as system_prompts
236
+
237
+ # callable_only / granted (#68): forwarded, not decided here.
238
+ # This function knows which agent is running; whether anything
239
+ # can answer an approval question is the RUN's fact, and the
240
+ # caller is the one holding it. Defaulting to the attended
241
+ # answer keeps both TUI call sites correct with no argument.
242
+ prompt = system_prompts.with_catalogs(
243
+ base_prompt, active_skills, context,
244
+ callable_only=callable_only, granted=granted)
245
+ prompt = f"{prompt}\n\n## Agent: {agent.name}\n\n{agent.body}"
246
+ context = config_loader.context_for_agent(agent)
247
+ if context:
248
+ prompt = f"{prompt}\n\n## Project context\n\n{context}"
249
+ # ROADMAP_v2 §21b: durable memories, the third context tier beside
250
+ # the project's AGENTS.md and gated the same way (use_memory).
251
+ # Appended HERE and not inside with_catalogs, which feeds
252
+ # pass_prompt() -- injecting there would put every memory into all
253
+ # ten research passes, which is §19's K6 trap in its second
254
+ # instance.
255
+ memories = memory_manager.prompt_fragment(agent)
256
+ if memories:
257
+ prompt = f"{prompt}\n\n{memories}"
258
+ return prompt
259
+
260
+
261
+ manager = AgentManager()