Skip to content

Commit dd7b6ed

Browse files
committed
Merge branch 'fix/production-readiness'
2 parents 44118c4 + f928a71 commit dd7b6ed

76 files changed

Lines changed: 5878 additions & 578 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ Releases are cut by hand from a release PR; see [docs/RELEASING.md](docs/RELEASI
5252
- **Dead shell-injection surface removed**: `AssumptionTracker.VerifyCommandSucceeds` ran caller-supplied strings through `sh -c`, bypassing the permission stack; it had zero callers and is deleted. `SelfHealer.RunScript` no longer shell-evaluates the script path (double evaluation) and invokes it directly via `/bin/sh`.
5353

5454
### Fixed
55+
- Git snapshots now keep a separate history for each project. Earlier versions shared a history across projects. To inspect those older commits, run `git --git-dir="<state-dir>/snapshots/.git" log --stat`, using your Reflect state directory for `<state-dir>`.
56+
- The shell installer stages each upgrade under the install prefix. A failed launcher replacement preserves the previous launcher and cleans up its temporary files.
5557
- Simple greetings stay conversational without listing files or reading project instructions, including after earlier tool use; real requests such as "Hi fix bug" keep their tools.
5658
- Batch tool execution now runs post-processing, redaction, and completion hooks and emits one final result per call.
5759
- Plan and Review modes enforce read-only execution even after tool discovery. Loading a local skill uses its read-only permission policy.

‎api/openapi.yaml‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,66 @@ paths:
867867
schema:
868868
$ref: "#/components/schemas/Error"
869869

870+
/v1/sessions/{id}/steer:
871+
post:
872+
operationId: steerSession
873+
tags: [agent]
874+
summary: Steer an in-flight generation
875+
description: |
876+
Splices a guidance message into the session's active generation. The
877+
message is injected between tool batches; the run is not interrupted.
878+
Requires an in-flight generation for the session.
879+
parameters:
880+
- name: id
881+
in: path
882+
required: true
883+
schema:
884+
type: string
885+
requestBody:
886+
required: true
887+
content:
888+
application/json:
889+
schema:
890+
type: object
891+
required: [message]
892+
properties:
893+
message:
894+
type: string
895+
responses:
896+
"200":
897+
description: Guidance queued for the active generation
898+
content:
899+
application/json:
900+
schema:
901+
type: object
902+
properties:
903+
steered:
904+
type: boolean
905+
"400":
906+
description: Invalid session id or missing message
907+
content:
908+
application/json:
909+
schema:
910+
$ref: "#/components/schemas/Error"
911+
"401":
912+
description: Unauthorized
913+
content:
914+
application/json:
915+
schema:
916+
$ref: "#/components/schemas/Error"
917+
"404":
918+
description: No active generation for the session
919+
content:
920+
application/json:
921+
schema:
922+
$ref: "#/components/schemas/Error"
923+
"429":
924+
description: Rate limit exceeded
925+
content:
926+
application/json:
927+
schema:
928+
$ref: "#/components/schemas/Error"
929+
870930
/v1/sessions/{id}/graph:
871931
get:
872932
operationId: getSessionGraph

‎cmd/chat.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ func newChatModelWithRegistry(ref *progRef, systemPrompt string, settings reflec
374374

375375
if saved != nil {
376376
for _, message := range sessionfeature.Hydrate(saved).Display {
377-
m.messages = append(m.messages, displayMsg{role: message.Role, content: message.Content})
377+
m.messages = append(m.messages, displayFromHydrated(message))
378378
}
379379
}
380380

‎cmd/chat_activity.go‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,34 @@ import (
66
"unicode"
77

88
"github.com/GrayCodeAI/reflect/internal/engine"
9+
sessionfeature "github.com/GrayCodeAI/reflect/internal/features/session"
910
"github.com/GrayCodeAI/reflect/internal/ui/icons"
1011
)
1112

13+
// A saved call without an observed result is incomplete, not a live tool or
14+
// an assumed success. This is a host display state, never a Relay wire value.
15+
const toolStateIncomplete engine.ToolState = "incomplete"
16+
17+
func displayFromHydrated(message sessionfeature.HydratedDisplayMessage) displayMsg {
18+
msg := displayMsg{role: message.Role, content: message.Content}
19+
if message.Call != nil {
20+
msg.toolID, msg.toolName = message.Call.ID, message.Call.Name
21+
msg.summary = engine.ToolActivitySummary(message.Call.Name, message.Call.Arguments)
22+
if msg.role == "tool_use" {
23+
msg.content = message.Call.Name
24+
msg.toolState = toolStateIncomplete
25+
}
26+
}
27+
if message.Result != nil {
28+
msg.toolID = message.Result.ToolUseID
29+
msg.toolState = engine.ToolStateCompleted
30+
if message.Result.IsError {
31+
msg.toolState = engine.ToolStateFailed
32+
}
33+
}
34+
return msg
35+
}
36+
1237
func singleLineActivity(value string) string {
1338
value = strings.NewReplacer("\r", `\r`, "\n", `\n`, "\t", " ").Replace(sanitizeDisplay(value))
1439
return strings.Map(func(r rune) rune {
@@ -29,6 +54,8 @@ func renderToolActivity(msg displayMsg, width int) string {
2954
marker, style = "!", errorStyle
3055
case engine.ToolStateCancelled:
3156
marker, style = "×", statusDimStyle
57+
case toolStateIncomplete:
58+
marker, style = "?", warnStyle
3259
}
3360
heading := style.Render(marker + " " + singleLineActivity(msg.content))
3461
if detail := singleLineActivity(msg.summary); strings.TrimSpace(detail) != "" {

‎cmd/chat_activity_group.go‎

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"github.com/GrayCodeAI/reflect/internal/engine"
8+
"github.com/GrayCodeAI/reflect/internal/ui/icons"
9+
)
10+
11+
// displayBlock is a projection over the transcript, never a replacement for
12+
// it. Rendering and keyboard targeting use the same boundaries and indices.
13+
// Prompts, warnings, answers, and user messages always keep their own blocks.
14+
type displayBlock struct {
15+
start, end int
16+
activity bool
17+
}
18+
19+
func isToolMessage(msg displayMsg) bool {
20+
return msg.role == "tool_use" || msg.role == "tool_result"
21+
}
22+
23+
func nextDisplayBlock(messages []displayMsg, start, end int) displayBlock {
24+
block := displayBlock{start: start, end: start + 1, activity: isToolMessage(messages[start])}
25+
if block.activity {
26+
for block.end < end && isToolMessage(messages[block.end]) {
27+
block.end++
28+
}
29+
}
30+
return block
31+
}
32+
33+
type activityCall struct {
34+
name string
35+
state engine.ToolState
36+
}
37+
38+
// activityCalls joins results by call ID, keeping launch order even when calls
39+
// finish out of order. ID-less legacy messages pair with the latest pending
40+
// call of the same name. They never collapse distinct identified calls.
41+
func activityCalls(messages []displayMsg, block displayBlock) []activityCall {
42+
var calls []activityCall
43+
byID := make(map[string]int)
44+
pending := make([]bool, 0)
45+
for _, msg := range messages[block.start:block.end] {
46+
index, found := byID[msg.toolID]
47+
found = found && msg.toolID != ""
48+
if !found && msg.role == "tool_result" && msg.toolID == "" {
49+
for i := len(calls) - 1; i >= 0; i-- {
50+
if pending[i] && (msg.toolName == "" || calls[i].name == msg.toolName) {
51+
index, found = i, true
52+
break
53+
}
54+
}
55+
}
56+
if !found {
57+
name := msg.toolName
58+
if name == "" && msg.role == "tool_use" {
59+
name = msg.content
60+
}
61+
index = len(calls)
62+
calls = append(calls, activityCall{name: name, state: msg.toolState})
63+
pending = append(pending, msg.role == "tool_use")
64+
if msg.toolID != "" {
65+
byID[msg.toolID] = index
66+
}
67+
}
68+
if msg.role == "tool_result" {
69+
calls[index].state = msg.toolState
70+
if calls[index].state == "" {
71+
calls[index].state = engine.ToolStateCompleted
72+
}
73+
pending[index] = false
74+
}
75+
}
76+
return calls
77+
}
78+
79+
func activityCategory(name string) int {
80+
switch strings.ToLower(name) {
81+
case "read", "read_file":
82+
return 0
83+
case "grep", "glob", "ls", "code_search", "codesearch", "search":
84+
return 1
85+
case "bash", "powershell", "shell":
86+
return 2
87+
case "write", "edit", "multiedit", "notebookedit", "structurededit", "write_file", "edit_file", "apply_patch":
88+
return 3
89+
default:
90+
return 4
91+
}
92+
}
93+
94+
func renderActivityGroup(messages []displayMsg, block displayBlock, width int, expanded map[int]bool) string {
95+
calls := activityCalls(messages, block)
96+
var counts [5]int
97+
var running, failed, cancelled, incomplete int
98+
for _, call := range calls {
99+
counts[activityCategory(call.name)]++
100+
switch call.state {
101+
case engine.ToolStateCompleted:
102+
case engine.ToolStateFailed, engine.ToolStateTimedOut:
103+
failed++
104+
case engine.ToolStateCancelled:
105+
cancelled++
106+
case toolStateIncomplete:
107+
incomplete++
108+
default:
109+
running++
110+
}
111+
}
112+
marker, style := icons.Check(), statusDimStyle
113+
var parts []string
114+
if failed > 0 {
115+
marker, style = "!", errorStyle
116+
parts = append(parts, fmt.Sprintf("%d failed", failed))
117+
}
118+
if cancelled > 0 {
119+
if failed == 0 {
120+
marker = "×"
121+
}
122+
parts = append(parts, fmt.Sprintf("%d cancelled", cancelled))
123+
}
124+
if running > 0 {
125+
if failed == 0 {
126+
marker, style = "·", toolStyle
127+
}
128+
parts = append(parts, fmt.Sprintf("%d running", running))
129+
}
130+
if incomplete > 0 {
131+
if failed == 0 && running == 0 {
132+
marker, style = "?", warnStyle
133+
}
134+
parts = append(parts, fmt.Sprintf("%d incomplete", incomplete))
135+
}
136+
labels := [5][2]string{{"Read %d file", "Read %d files"}, {"%d search", "%d searches"}, {"Ran %d command", "Ran %d commands"}, {"%d edit", "%d edits"}, {"%d tool call", "%d tool calls"}}
137+
for category, count := range counts {
138+
if count > 0 {
139+
plural := 0
140+
if count != 1 {
141+
plural = 1
142+
}
143+
parts = append(parts, fmt.Sprintf(labels[category][plural], count))
144+
}
145+
}
146+
hint := "Tab, Enter: details"
147+
if expanded[block.start] {
148+
hint = "Enter: collapse"
149+
}
150+
heading := marker + " " + strings.Join(parts, " · ") + " · " + hint
151+
var b strings.Builder
152+
b.WriteString(style.Render(clipFooterLine(heading, max(1, width))))
153+
b.WriteByte('\n')
154+
if expanded[block.start] {
155+
// Keep individual results collapsed until the whole group is opened.
156+
// Opening reveals the existing bounded detail view, including commands.
157+
details := make(map[int]bool, block.end-block.start)
158+
for i := block.start; i < block.end; i++ {
159+
details[i] = true
160+
}
161+
for i := block.start; i < block.end; i++ {
162+
b.WriteString(renderDisplayMessage(messages[i], i, messages, width, details))
163+
}
164+
} else if failed > 0 {
165+
// A short diagnostic remains visible without opening routine output.
166+
for i := block.end - 1; i >= block.start; i-- {
167+
msg := messages[i]
168+
if msg.role == "tool_result" && (msg.toolState == engine.ToolStateFailed || msg.toolState == engine.ToolStateTimedOut) {
169+
lines := strings.Split(strings.TrimSpace(sanitizeDisplay(msg.content)), "\n")
170+
if tail := singleLineActivity(lines[len(lines)-1]); tail != "" {
171+
b.WriteString(errorStyle.Render(clipFooterLine(" "+tail, max(1, width))))
172+
b.WriteByte('\n')
173+
}
174+
break
175+
}
176+
}
177+
}
178+
b.WriteByte('\n')
179+
return b.String()
180+
}
181+
182+
func renderDisplayBlock(messages []displayMsg, block displayBlock, width int, expanded map[int]bool) string {
183+
if block.activity {
184+
return renderActivityGroup(messages, block, width, expanded)
185+
}
186+
return renderDisplayMessage(messages[block.start], block.start, messages, width, expanded)
187+
}

0 commit comments

Comments
 (0)