@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.
Files changed (130) hide show
  1. package/.env.example +19 -14
  2. package/CONFIG_ARCHITECTURE.md +2002 -0
  3. package/NOTICE +1 -1
  4. package/README.md +249 -93
  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 +280 -23
  12. package/agents/tui_commands.py +31 -21
  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 +256 -0
  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 +1249 -82
  29. package/core/commands.py +454 -0
  30. package/core/compaction.py +1735 -959
  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 +2566 -1353
  38. package/core/memory.py +482 -370
  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 +315 -167
  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 +1672 -198
  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 +21 -14
  70. package/package.json +303 -73
  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 +149 -100
  80. package/requirements.txt +252 -29
  81. package/safety/policy_enforcement.py +1082 -682
  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 +1338 -1005
  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 +374 -29
  118. package/tui/app.py +5281 -397
  119. package/tui/app.tcss +290 -9
  120. package/tui/commands.py +26 -61
  121. package/tui/diffs.py +286 -265
  122. package/tui/history.py +128 -0
  123. package/tui/hosted_driver.py +102 -0
  124. package/tui/markdown.py +1329 -0
  125. package/tui/meters.py +364 -0
  126. package/tui/screens.py +346 -92
  127. package/tui/themes.py +599 -366
  128. package/tui/widgets.py +2673 -116
  129. package/SECURITY.md +0 -88
  130. package/THIRD_PARTY_NOTICES.md +0 -100
package/core/replay.py CHANGED
@@ -1,167 +1,315 @@
1
- """
2
- core/replay.py
3
-
4
- Turns a stored thread back into something a shell can display
5
- (ROADMAP_v2 §27, bug 1).
6
-
7
- WHY THIS EXISTS AT ALL. Resuming a thread loaded its history correctly and
8
- showed NOTHING: `ConversationMemory(thread_id=...)` reads the full history
9
- at construction, but the TUI's picker callback swapped the object and wrote
10
- one line, and `main.py --thread` printed "Resuming thread: <uuid>" and
11
- dropped straight into the prompt. In the TUI it was worse than blank -- the
12
- PREVIOUS thread's transcript stayed on screen under the new thread's id, so
13
- the screen actively lied about which conversation was loaded.
14
-
15
- WHY IT IS ONE FUNCTION AND NOT TWO RENDERERS. D12 makes the CLI a permanent
16
- fallback, so both shells replay (§27 T5, §26's L6 again). What may be shown,
17
- and in what form, is a policy decision that must not differ between them --
18
- so the policy lives here and each shell only decides how to paint the
19
- entries it is handed. §26 spent a decision (L2, "one translation site") on
20
- exactly this shape.
21
-
22
- THE ARCHIVE, NEVER THE DERIVED VIEW (T3). `storage.archive_history()`
23
- returns every message ever written, compaction or not.
24
- `ConversationMemory.messages` on a compacted thread BEGINS with the
25
- synthesized summary that §21's M8 says must never be mistaken for something
26
- a person said -- and replaying it would render harness-generated text under
27
- a `you ›` label, which is precisely the mistake M8 exists to prevent. It
28
- also means a replayed thread shows what was originally said rather than a
29
- condensation of it, which is what a human resuming a conversation is looking
30
- for.
31
-
32
- THE LIVE VIEW SHOWS MORE THAN THIS ONE, DELIBERATELY (§41). Since batch 41
33
- the TUI renders a `write` or an `edit` as an inline diff, and a REPLAYED one
34
- here still shows `param_digest`. That is not a gap to close: a replay reads
35
- the archive, which records what was called and never what the file held at
36
- the time, so the digest is genuinely all this function has. The live view is
37
- better informed because it was there.
38
-
39
- REASONING IS REPLAYED, SINCE §44. §38 captured thinking for display and
40
- persisted none of it, so reopening a thread showed the answers with the
41
- reasoning silently missing -- the same conversation rendered two different
42
- ways depending on whether the session had been closed. The blocks are
43
- stored now (storage.MessageLog.thinking) and _reasoning_text pulls the
44
- prose back out of them. What a shell does with the entry is still the
45
- shell's: the TUI honours tui.show_thinking, because that is a display
46
- setting rather than a fact about the thread.
47
-
48
- TOOL RESULTS ARE SKIPPED, TOOL CALLS ARE ONE LINE (T4). A grounding-heavy
49
- thread carries hundreds of kilobytes of fetched page text in its
50
- `tool_result` rows; replaying that would bury the conversation in the
51
- material the conversation was about. The call is what says what happened,
52
- and `param_digest` says WHICH url or query -- redacted, because a tool
53
- argument can carry a credential and this is now the third place one could
54
- surface.
55
- """
56
-
57
- from __future__ import annotations
58
-
59
- from typing import List, Optional, Tuple
60
- from uuid import UUID
61
-
62
- from tools.registry import registry
63
- from storage import archive_history
64
-
65
- #: One replayed entry: (role, text). The roles are transcript palette roles
66
- #: (tui/themes.role_styles), so the TUI can paint them with what it already
67
- #: has and the CLI can label them. Deliberately NOT the neutral message
68
- #: shape -- a caller of this function is rendering, not reasoning about
69
- #: history, and handing it messages would invite a second policy decision
70
- #: about tool results at the call site.
71
- ReplayEntry = Tuple[str, str]
72
-
73
-
74
- def replay_entries(thread_id: UUID) -> List[ReplayEntry]:
75
- """A stored thread as display entries, oldest first (§27 T3/T4).
76
-
77
- Empty for a thread with no messages -- a `/new` thread that was never
78
- used is a real state, and the shells write their own "nothing here yet"
79
- line rather than this function inventing one.
80
- """
81
- entries: List[ReplayEntry] = []
82
- for message in archive_history(thread_id):
83
- role = message.get("role")
84
- if role == "user":
85
- text = _as_text(message.get("content"))
86
- if text:
87
- entries.append(("user", text))
88
- elif role == "assistant":
89
- # BEFORE the answer, because that is the order it happened in
90
- # and the order the live transcript drew it in (§43 RM1 puts
91
- # one `venastine ›` above whichever came first). A replay that
92
- # reordered the turn would be the same defect as one that
93
- # reflowed it.
94
- reasoning = _reasoning_text(message.get("thinking"))
95
- if reasoning:
96
- entries.append(("thinking", reasoning))
97
- text = _as_text(message.get("text"))
98
- if text:
99
- entries.append(("assistant", text))
100
- for call in message.get("tool_calls") or []:
101
- entries.append(("tool", _tool_marker(call)))
102
- # role == "tool": skipped by T4. Not a gap -- see the module
103
- # docstring. The CALL above is the record that it happened.
104
- return entries
105
-
106
-
107
- def _reasoning_text(record) -> str:
108
- """The displayable prose out of a stored thinking record (§44).
109
-
110
- The record holds the PROVIDER'S blocks, because that is what goes back
111
- on the wire; this is the other half of the same data, for a human. Two
112
- shapes reach here -- Anthropic's `thinking` blocks and the
113
- v1-compatible `reasoning_content` one -- and both are read by field
114
- name rather than by provider, so a third costs a name and not a
115
- branch.
116
-
117
- `redacted_thinking` contributes NOTHING and that is correct: it is
118
- opaque ciphertext meaningful only to the model, so rendering it would
119
- put a wall of base64 under a `venastine ›` label. It still travels on
120
- the wire; this function is about what a person sees.
121
- """
122
- if not isinstance(record, dict):
123
- return ""
124
- parts = []
125
- for block in record.get("blocks") or []:
126
- if not isinstance(block, dict):
127
- continue
128
- value = block.get("thinking") or block.get("text")
129
- if isinstance(value, str) and value.strip():
130
- parts.append(value.strip())
131
- return "\n\n".join(parts)
132
-
133
-
134
- def _tool_marker(call: dict) -> str:
135
- """One line for one tool call: name, then a redacted param digest.
136
-
137
- The digest comes from `registry.call_digest` rather than from a
138
- local copy -- it redacts BEFORE truncating, and a second
139
- implementation is how that ordering regresses in one place and
140
- not the other (§27's note on _param_digest, and the project's
141
- canonical producer/consumer bug).
142
-
143
- Through the REGISTRY since §42 (RA3), not `param_digest` direct,
144
- because dropping a tool's declared rationale param is part of the
145
- same rule and belongs at the same producer. Importing the registry
146
- here costs nothing measurable: `main.py` is this module's only
147
- caller and has already imported it, so it is in `sys.modules`
148
- (1.9s cold at process start, 0.0s here).
149
- """
150
- name = call.get("name") or "tool"
151
- digest = registry.call_digest(name, call.get("input"))
152
- # Standardised to ▸ like the live transcript (tui/app.py both modes).
153
- # Replay stays redacted via param_digest, same producer as live.
154
- return f"▸ {name} {digest}".rstrip() if digest else f"▸ {name}"
155
-
156
-
157
- def _as_text(value: Optional[object]) -> str:
158
- """Message content as a displayable string.
159
-
160
- `content` is whatever was persisted through json.dumps, so it is
161
- normally a string but need not be; str() rather than a type assertion,
162
- because a replay that raises on one odd row would take the whole resumed
163
- conversation with it.
164
- """
165
- if value is None:
166
- return ""
167
- return value.strip() if isinstance(value, str) else str(value)
1
+ """
2
+ core/replay.py
3
+
4
+ Turns a stored thread back into something a shell can display
5
+ (ROADMAP_v2 §27, bug 1).
6
+
7
+ WHY THIS EXISTS AT ALL. Resuming a thread loaded its history correctly and
8
+ showed NOTHING: `ConversationMemory(thread_id=...)` reads the full history
9
+ at construction, but the TUI's picker callback swapped the object and wrote
10
+ one line, and `main.py --thread` printed "Resuming thread: <uuid>" and
11
+ dropped straight into the prompt. In the TUI it was worse than blank -- the
12
+ PREVIOUS thread's transcript stayed on screen under the new thread's id, so
13
+ the screen actively lied about which conversation was loaded.
14
+
15
+ WHY IT IS ONE FUNCTION AND NOT TWO RENDERERS. D12 makes the CLI a permanent
16
+ fallback, so both shells replay (§27 T5, §26's L6 again). What may be shown,
17
+ and in what form, is a policy decision that must not differ between them --
18
+ so the policy lives here and each shell only decides how to paint the
19
+ entries it is handed. §26 spent a decision (L2, "one translation site") on
20
+ exactly this shape.
21
+
22
+ THE ARCHIVE, NEVER THE DERIVED VIEW (T3). `storage.archive_history()`
23
+ returns every message ever written, compaction or not.
24
+ `ConversationMemory.messages` on a compacted thread BEGINS with the
25
+ synthesized summary that §21's M8 says must never be mistaken for something
26
+ a person said -- and replaying it would render harness-generated text under
27
+ a `you ›` label, which is precisely the mistake M8 exists to prevent. It
28
+ also means a replayed thread shows what was originally said rather than a
29
+ condensation of it, which is what a human resuming a conversation is looking
30
+ for.
31
+
32
+ THE LIVE VIEW SHOWS MORE THAN THIS ONE, DELIBERATELY (§41). Since batch 41
33
+ the TUI renders a `write` or an `edit` as an inline diff, and a REPLAYED one
34
+ here still shows `param_digest`. That is not a gap to close: a replay reads
35
+ the archive, which records what was called and never what the file held at
36
+ the time, so the digest is genuinely all this function has. The live view is
37
+ better informed because it was there.
38
+
39
+ REASONING IS REPLAYED, SINCE §44. §38 captured thinking for display and
40
+ persisted none of it, so reopening a thread showed the answers with the
41
+ reasoning silently missing -- the same conversation rendered two different
42
+ ways depending on whether the session had been closed. The blocks are
43
+ stored now (storage.MessageLog.thinking) and _reasoning_text pulls the
44
+ prose back out of them. What a shell does with the entry is still the
45
+ shell's: the TUI honours tui.show_thinking, because that is a display
46
+ setting rather than a fact about the thread.
47
+
48
+ TOOL RESULTS ARE SKIPPED, TOOL CALLS ARE ONE LINE (T4). A grounding-heavy
49
+ thread carries hundreds of kilobytes of fetched page text in its
50
+ `tool_result` rows; replaying that would bury the conversation in the
51
+ material the conversation was about. The call is what says what happened,
52
+ and `param_digest` says WHICH url or query -- redacted, because a tool
53
+ argument can carry a credential and this is now the third place one could
54
+ surface.
55
+
56
+ T4 IS UNCHANGED BY §55, AND §55 IS WHY IT CAN STAY. A result is still not
57
+ replayed into the conversation; it is now REACHABLE from the line that
58
+ produced it, because every tool line carries `(OPENS_CALL, call id)` and
59
+ `core/call_view.py` reads the same archive on demand (TR6/TR7). That is
60
+ the distinction worth keeping straight if either side is ever revisited:
61
+ T4 is about what a replay PUTS IN FRONT of a reader, and §55 is about what
62
+ a reader can ask for. A feature that inlined the output would be T4 undone
63
+ rather than extended.
64
+ """
65
+
66
+ from __future__ import annotations
67
+
68
+ from typing import Optional
69
+ from uuid import UUID
70
+
71
+ from storage import archive_history
72
+ from tools.registry import registry
73
+
74
+ #: One replayed entry: (role, text, links). The roles are transcript palette
75
+ #: roles (tui/themes.role_styles), so the TUI can paint them with what it
76
+ #: already has and the CLI can label them. Deliberately NOT the neutral
77
+ #: message shape -- a caller of this function is rendering, not reasoning
78
+ #: about history, and handing it messages would invite a second policy
79
+ #: decision about tool results at the call site.
80
+ #:
81
+ #: `links` is batch 65's, and it does not narrow the sentence above: a
82
+ #: click target is a RENDERING fact about a line, not part of what was
83
+ #: said. It is here because the alternative is worse -- a tool line's
84
+ #: digest truncates a long URL, so without it a resumed thread would draw
85
+ #: the same characters as a live turn and quietly refuse to open them,
86
+ #: which is the one conversation rendered two ways that Section 44 removed
87
+ #: for thinking spans. Empty for every entry that is not a tool call.
88
+ #:
89
+ #: `opens` is §47's, widened by ROADMAP_v3 §49 (SS14) and again by §55
90
+ #: (TR7): `(kind, call id)` for a tool line, and `()` only where there is
91
+ #: no call id to carry. The id is the model's own id for the call that
92
+ #: drew the line, and the kind is `OPENS_THREAD`, `OPENS_SESSION` or
93
+ #: `OPENS_CALL` -- the registry is asked, so this file does not have to
94
+ #: know that `spawn_subagent` is special and cannot come to disagree with
95
+ #: the TUI about which lines are openable.
96
+ #:
97
+ #: SINCE §55 THE GATE IS THE ID, NOT THE KIND. `registry.opens()` has no
98
+ #: empty answer any more, so an unarmed line is one whose call the archive
99
+ #: cannot be asked about rather than one whose tool declared nothing.
100
+ #: It does not widen the sentence above either: a caller is still
101
+ #: rendering rather than reasoning about history, and what a line opened
102
+ #: is a fact about the LINE. Without it a resumed conversation would draw
103
+ #: `▸ spawn_subagent` exactly as the live turn did and refuse to open it
104
+ #: -- the same divergence §44 removed for thinking spans, and batch 65
105
+ #: for a truncated URL.
106
+ #:
107
+ #: IT CARRIES THE KIND, not just the id, and that is what SS14 needed:
108
+ #: a `▸ shell_background` line opens a SESSION, which is read from the
109
+ #: manager or rebuilt from the wake rows it wrote rather than replayed
110
+ #: from the archive. A bare id would have left the reader on the other
111
+ #: side of the click guessing, and guessing by tool name there is the
112
+ #: second copy this slot exists to avoid.
113
+ ReplayEntry = tuple[str, str, tuple[str, ...], tuple]
114
+
115
+
116
+ def replay_entries(thread_id: UUID) -> list[ReplayEntry]:
117
+ """A stored thread as display entries, oldest first (§27 T3/T4).
118
+
119
+ Empty for a thread with no messages -- a `/new` thread that was never
120
+ used is a real state, and the shells write their own "nothing here yet"
121
+ line rather than this function inventing one.
122
+ """
123
+ entries: list[ReplayEntry] = []
124
+ for message in archive_history(thread_id):
125
+ role = message.get("role")
126
+ if role == "user":
127
+ text = _as_text(message.get("content"))
128
+ if message.get("harness"):
129
+ # ROADMAP_v3 §49 (SS5). The HARNESS wrote this row -- a
130
+ # background session's result -- so it must not replay under
131
+ # `you ›`, which is M8's mistake for the compaction summary.
132
+ # Its first line only, for T4's reason: the rest is program
133
+ # output the model was given, which can run to thousands of
134
+ # lines and would bury the conversation it interrupted.
135
+ header = text.split("\n", 1)[0].strip()
136
+ if header:
137
+ entries.append(("wake", header, (), ()))
138
+ elif text:
139
+ entries.append(("user", text, (), ()))
140
+ # Batch 91. The run this message started FAILED, and why. Right
141
+ # after it, because nothing else from that run was ever written:
142
+ # without this a subagent whose first call failed replays as its
143
+ # task and nothing else, which is indistinguishable from a run
144
+ # still thinking. `error` is a harness voice (META_ROLES), so
145
+ # /copy conversation leaves it out as it leaves out the live
146
+ # `[error: ...]` line.
147
+ failure = message.get("error")
148
+ if failure:
149
+ entries.append(("error", f"This run failed: {failure}", (), ()))
150
+ elif role == "assistant":
151
+ entries.extend(step_entries(
152
+ _reasoning_text(message.get("thinking")),
153
+ _as_text(message.get("text")),
154
+ message.get("tool_calls") or []))
155
+ # role == "tool": skipped by T4. Not a gap -- see the module
156
+ # docstring. The CALL above is the record that it happened.
157
+ return entries
158
+
159
+
160
+ def step_entries(reasoning: str, text: str, tool_calls) -> list[ReplayEntry]:
161
+ """One model step as display entries: its reasoning, its text, then a
162
+ line per tool call.
163
+
164
+ BEFORE the answer, because that is the order it happened in and the
165
+ order the live transcript drew it in (§43 RM1 puts one `venastine ›`
166
+ above whichever came first). A replay that reordered the turn would be
167
+ the same defect as one that reflowed it.
168
+
169
+ PUBLIC SINCE ROADMAP_v3 §86 (A81), because the CLI's live turn prints
170
+ each step through this as it finishes. A replay and the turn it
171
+ replays are then one function's output over the same three things,
172
+ which is what keeps the CLI from showing a turn one way while it runs
173
+ and another way when its thread is resumed (#225).
174
+ """
175
+ entries: list[ReplayEntry] = []
176
+ if reasoning:
177
+ entries.append(("thinking", reasoning, (), ()))
178
+ if text:
179
+ entries.append(("assistant", text, (), ()))
180
+ for call in tool_calls:
181
+ entries.append(("tool", *_tool_marker(call)))
182
+ return entries
183
+
184
+
185
+ def reasoning_text(record) -> str:
186
+ """`_reasoning_text`, for a caller outside this module (§86, A81): the
187
+ CLI reads a live response's reasoning with the replay's own reader."""
188
+ return _reasoning_text(record)
189
+
190
+
191
+ def _reasoning_text(record) -> str:
192
+ """The displayable prose out of a stored thinking record (§44).
193
+
194
+ The record holds the PROVIDER'S blocks, because that is what goes back
195
+ on the wire; this is the other half of the same data, for a human. Two
196
+ shapes reach here -- Anthropic's `thinking` blocks and the
197
+ v1-compatible `reasoning_content` one -- and both are read by field
198
+ name rather than by provider, so a third costs a name and not a
199
+ branch.
200
+
201
+ `redacted_thinking` contributes NOTHING and that is correct: it is
202
+ opaque ciphertext meaningful only to the model, so rendering it would
203
+ put a wall of base64 under a `venastine ›` label. It still travels on
204
+ the wire; this function is about what a person sees.
205
+
206
+ The third shape arrived with ROADMAP_v3 §83 and cost the name it was
207
+ promised: a ChatGPT plan's `reasoning` item keeps its readable part in
208
+ `summary`, a list of `summary_text` parts, beside `encrypted_content`,
209
+ which contributes nothing for `redacted_thinking`'s reason.
210
+ """
211
+ if not isinstance(record, dict):
212
+ return ""
213
+ parts = []
214
+ for block in record.get("blocks") or []:
215
+ if not isinstance(block, dict):
216
+ continue
217
+ values = [block.get("thinking") or block.get("text")]
218
+ values += [part.get("text") for part in block.get("summary") or []
219
+ if isinstance(part, dict)]
220
+ parts.extend(value.strip() for value in values
221
+ if isinstance(value, str) and value.strip())
222
+ return "\n\n".join(parts)
223
+
224
+
225
+ def _tool_marker(call: dict) -> tuple[str, tuple[str, ...], str]:
226
+ """One line for one tool call, its click targets, and its own id.
227
+
228
+ The line is the name, then a redacted param digest.
229
+
230
+ The digest comes from `registry.call_digest` rather than from a
231
+ local copy -- it redacts BEFORE truncating, and a second
232
+ implementation is how that ordering regresses in one place and
233
+ not the other (§27's note on _param_digest, and the project's
234
+ canonical producer/consumer bug).
235
+
236
+ Through the REGISTRY since §42 (RA3), not `param_digest` direct,
237
+ because dropping a tool's declared rationale param is part of the
238
+ same rule and belongs at the same producer. Importing the registry
239
+ here costs nothing measurable: `main.py` is this module's only
240
+ caller and has already imported it, so it is in `sys.modules`
241
+ (1.9s cold at process start, 0.0s here).
242
+ """
243
+ name = call.get("name") or "tool"
244
+ params = call.get("input")
245
+ digest = registry.call_digest(name, params)
246
+ # Standardised to ▸ like the live transcript (tui/app.py both modes).
247
+ # Replay stays redacted via param_digest, same producer as live.
248
+ #
249
+ # And the click targets from the same producer for the same reason
250
+ # (batch 65): a resumed thread that armed fewer URLs than the live
251
+ # turn would be the archive disagreeing with the screen it came from.
252
+ line = f"▸ {name} {digest}".rstrip() if digest else f"▸ {name}"
253
+ # §47, widened by §49 (SS14) and §55 (TR7). The registry is what says
254
+ # WHICH kind -- naming `spawn_subagent` here would be a second copy of
255
+ # a fact the tool already declares, free to disagree with the TUI's
256
+ # copy. `str()` because it crosses into style metadata.
257
+ #
258
+ # `if opens` SURVIVES AS A GUARD WITH NOTHING LEFT TO GUARD: TR7 gave
259
+ # `opens()` a fallback kind, so it is never empty now and the id below
260
+ # is the only thing that can leave a line unarmed. Kept rather than
261
+ # deleted because the tuple is indexed on the next line, and a reader
262
+ # who has not met TR7 should find the shape intact.
263
+ opens = registry.opens(name)
264
+ call_id = str(call.get("id") or "") if opens else ""
265
+ return (line, registry.call_links(name, params),
266
+ (opens[0], call_id) if call_id else ())
267
+
268
+
269
+ def _as_text(value: Optional[object]) -> str:
270
+ """Message content as a displayable string.
271
+
272
+ `content` is whatever was persisted through json.dumps, so it is
273
+ normally a string but need not be; str() rather than a type assertion,
274
+ because a replay that raises on one odd row would take the whole resumed
275
+ conversation with it.
276
+ """
277
+ if value is None:
278
+ return ""
279
+ return value.strip() if isinstance(value, str) else str(value)
280
+
281
+
282
+ def tool_lines(thread_id: UUID) -> list[tuple[str, tuple]]:
283
+ """Every tool-call line a replay of `thread_id` draws, in order, with
284
+ what each one opens: `(line, (kind, call_id))`, the second slot empty
285
+ for a call with no id (ROADMAP_v3 §89, register item 45).
286
+
287
+ THE CLI'S ROUTE TO A CALL, and read off `replay_entries` rather than
288
+ walked separately: `/call` numbers these lines, and a second walk that
289
+ drew one line differently, or skipped one, would number a call the
290
+ reader cannot match to the line they are looking at.
291
+ """
292
+ return [(entry[1], entry[3]) for entry in replay_entries(thread_id)
293
+ if entry[0] == "tool"]
294
+
295
+
296
+ def thread_row(thread: dict) -> str:
297
+ """One row of a thread list: timestamp, first message, id (§27).
298
+
299
+ The TUI's picker draws it and the CLI's `/threads` prints it, so a
300
+ conversation reads the same in either list (moved from tui/screens.py
301
+ by §89).
302
+
303
+ `created_at` and `id` are INDEXED deliberately, not .get: a row
304
+ without either has nothing honest to render -- storage.list_threads()
305
+ always supplies both, and the id is the row's whole payload on
306
+ selection. Only `preview` is optional (.get): §27 added it, so
307
+ hand-built test rows predate it, and a missing preview degrades to an
308
+ id-only row rather than a KeyError in a test-only construction.
309
+ """
310
+ created = thread["created_at"]
311
+ stamp = (f"{created:%Y-%m-%d %H:%M}"
312
+ if hasattr(created, "strftime") else str(created))
313
+ preview = (thread.get("preview") or "").strip()
314
+ return f"{stamp} {preview} ({thread['id']})" if preview \
315
+ else f"{stamp} {thread['id']}"
package/core/session.py CHANGED
@@ -58,10 +58,27 @@ not extra_data, not anywhere. Restarting the harness is the guaranteed
58
58
  way back to the derived number.
59
59
 
60
60
  MODULE STATE, written from the UI thread and read from worker threads.
61
- Same posture as core/compaction.py's `_compacting` flag and for the same
62
- reason: these are single assignments of an int or a tuple, so there is no
63
- half-set state to observe. Tests clear it in an autouse fixture, which is
64
- the rule every other module-level cache in this project follows.
61
+ What makes a concurrent read safe here is not serialisation but the pair
62
+ binding: every entry is a single assignment of a tuple, and a peer run
63
+ reading it gets a value only if the (provider, model) it asks about is the
64
+ one that was set -- so another agent's number is not merely unlikely to be
65
+ read, it does not match. Tests clear it in an autouse fixture, which is the
66
+ rule every other module-level cache in this project follows.
67
+
68
+ THIS USED TO CITE core/compaction.py's `_compacting` FLAG as the same
69
+ posture, and that symbol has not existed since batch 75 -- which batch 148
70
+ is where anyone noticed. It was replaced by
71
+ `_reentrancy = threading.local()` with `_is_compacting()` /
72
+ `_set_compacting()`, deliberately NOT aliased -- the comment there says why:
73
+ "`if _compacting:` against a callable is always true, so a reader left
74
+ holding the old name has to fail at import instead of quietly disabling
75
+ every compaction in the process". So the precedent had been reversed from a
76
+ module flag to per-thread state, because NA9 removed the premise that one
77
+ agent runs at a time, and a reader checking this module against its stated
78
+ example found an argument against the sentence that sent them there. The
79
+ precedent is still worth citing -- for the DIFFERENCE: compaction's state is
80
+ a re-entrancy flag, where a second reader must see what the first did, and
81
+ these are per-pair bindings, where it must not.
65
82
  """
66
83
 
67
84
  import logging
@@ -113,14 +130,21 @@ def trigger_any() -> Optional[int]:
113
130
  """The trigger override IGNORING the pair binding.
114
131
 
115
132
  Exists for exactly one caller: compaction.pin_measurements, which
116
- computes #89's cap as PIN_MAX_TRIGGER_FRACTION x the trigger and has
117
- no model in scope to match against. That caller takes the MINIMUM of
118
- this and the configured trigger, which is safe under every binding --
119
- a raised session trigger leaves the cap stricter than it needs to be,
120
- and a lowered one pulls the cap down with it. Reading the configured
121
- trigger alone would let `/trigger 12k` leave pins capped at 20k, able
122
- to floor a thread permanently above its own trigger, which is the
123
- defect #89 exists to prevent.
133
+ computes #89's cap as PIN_MAX_TRIGGER_FRACTION x the trigger. That
134
+ caller takes the MINIMUM of this and the configured trigger, which is
135
+ safe under every binding -- a raised session trigger leaves the cap
136
+ stricter than it needs to be, and a lowered one pulls the cap down with
137
+ it. Reading the configured trigger alone would let `/trigger 12k` leave
138
+ pins capped at 20k, able to floor a thread permanently above its own
139
+ trigger, which is the defect #89 exists to prevent.
140
+
141
+ ITS FALLBACK, SINCE BATCH 148, rather than its only answer. That caller
142
+ had no model in scope and now takes an optional one, because #89's cap
143
+ is a fraction of the trigger that FIRES and since batch 44 that is
144
+ derived per model (batch 148). With the pair it resolves the trigger
145
+ through thresholds(), which reads the correctly-BOUND session override;
146
+ this read is what remains for a call from outside a run, where there is
147
+ no pair to bind against.
124
148
 
125
149
  Do not reach for this anywhere the pair IS available.
126
150
  """