Trim command tool summaries
This commit is contained in:
@@ -23,7 +23,6 @@ import (
|
|||||||
const (
|
const (
|
||||||
telegramDownloadLimit = 20 * 1024 * 1024
|
telegramDownloadLimit = 20 * 1024 * 1024
|
||||||
resumeThreadPageSize = 8
|
resumeThreadPageSize = 8
|
||||||
commandSummaryLimit = 120
|
|
||||||
telegramPhotoDirectiveStart = "<!-- telegram-photo "
|
telegramPhotoDirectiveStart = "<!-- telegram-photo "
|
||||||
telegramThreadRenameDirectiveStart = "<!-- codex-thread-rename "
|
telegramThreadRenameDirectiveStart = "<!-- codex-thread-rename "
|
||||||
telegramThreadCWDDirectiveStart = "<!-- codex-thread-cwd "
|
telegramThreadCWDDirectiveStart = "<!-- codex-thread-cwd "
|
||||||
@@ -1194,7 +1193,7 @@ func parseCodexThreadItem(raw json.RawMessage) (codexThreadItemView, error) {
|
|||||||
func renderCodexItemStarted(item codexThreadItemView) string {
|
func renderCodexItemStarted(item codexThreadItemView) string {
|
||||||
switch item.Type {
|
switch item.Type {
|
||||||
case "commandExecution":
|
case "commandExecution":
|
||||||
return SummaryDetailsRawHTMLLimited(joinNonEmpty("Tool call: command started", commandSummaryLine(item.Command)), commandStartedDetailsHTML(item), TelegramHTMLMessageLimit)
|
return SummaryDetailsRawHTMLLimited("Tool call: command started", commandStartedDetailsHTML(item), TelegramHTMLMessageLimit)
|
||||||
case "fileChange":
|
case "fileChange":
|
||||||
return "Tool call: file change started"
|
return "Tool call: file change started"
|
||||||
case "mcpToolCall":
|
case "mcpToolCall":
|
||||||
@@ -1221,7 +1220,7 @@ func renderCodexItemCompleted(item codexThreadItemView) string {
|
|||||||
if item.ExitCode != nil {
|
if item.ExitCode != nil {
|
||||||
status = fmt.Sprintf("Exit code: %d", *item.ExitCode)
|
status = fmt.Sprintf("Exit code: %d", *item.ExitCode)
|
||||||
}
|
}
|
||||||
return SummaryDetailsRawHTMLLimited(joinNonEmpty("Tool call: command finished", commandSummaryLine(item.Command), status), renderCodexItemDetailsHTML(item), TelegramHTMLMessageLimit)
|
return SummaryDetailsRawHTMLLimited(joinNonEmpty("Tool call: command finished", status), renderCodexItemDetailsHTML(item), TelegramHTMLMessageLimit)
|
||||||
case "fileChange":
|
case "fileChange":
|
||||||
return joinNonEmpty("Tool call: file change finished", fmt.Sprintf("Changed files: %d", len(item.Changes)), "Status: "+item.Status)
|
return joinNonEmpty("Tool call: file change finished", fmt.Sprintf("Changed files: %d", len(item.Changes)), "Status: "+item.Status)
|
||||||
case "mcpToolCall":
|
case "mcpToolCall":
|
||||||
@@ -1247,21 +1246,9 @@ func renderCodexItemCompleted(item codexThreadItemView) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func commandSummaryLine(command string) string {
|
|
||||||
command = strings.TrimSpace(command)
|
|
||||||
if command == "" {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
runes := []rune(command)
|
|
||||||
if len(runes) <= commandSummaryLimit {
|
|
||||||
return "Command: " + command
|
|
||||||
}
|
|
||||||
return "Command: " + string(runes[:commandSummaryLimit]) + "..."
|
|
||||||
}
|
|
||||||
|
|
||||||
func commandStartedDetailsHTML(item codexThreadItemView) string {
|
func commandStartedDetailsHTML(item codexThreadItemView) string {
|
||||||
var parts []string
|
var parts []string
|
||||||
if command := strings.TrimSpace(item.Command); command != "" && len([]rune(command)) > commandSummaryLimit {
|
if command := strings.TrimSpace(item.Command); command != "" {
|
||||||
parts = append(parts, "<b>Command</b>", CodeBlockHTML("bash", command))
|
parts = append(parts, "<b>Command</b>", CodeBlockHTML("bash", command))
|
||||||
}
|
}
|
||||||
if cwd := strings.TrimSpace(item.CWD); cwd != "" {
|
if cwd := strings.TrimSpace(item.CWD); cwd != "" {
|
||||||
@@ -1296,7 +1283,7 @@ func renderCodexItemDetailsHTML(item codexThreadItemView) string {
|
|||||||
switch item.Type {
|
switch item.Type {
|
||||||
case "commandExecution":
|
case "commandExecution":
|
||||||
appendField("CWD", item.CWD)
|
appendField("CWD", item.CWD)
|
||||||
if command := strings.TrimSpace(item.Command); command != "" && len([]rune(command)) > commandSummaryLimit {
|
if command := strings.TrimSpace(item.Command); command != "" {
|
||||||
parts = append(parts, "<b>Command</b>", CodeBlockHTML("bash", command))
|
parts = append(parts, "<b>Command</b>", CodeBlockHTML("bash", command))
|
||||||
}
|
}
|
||||||
appendInt("Exit code", item.ExitCode)
|
appendInt("Exit code", item.ExitCode)
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ func TestRenderCodexCommandExecutionItem(t *testing.T) {
|
|||||||
ExitCode: &exitCode,
|
ExitCode: &exitCode,
|
||||||
}
|
}
|
||||||
text := renderCodexItemCompleted(item)
|
text := renderCodexItemCompleted(item)
|
||||||
for _, want := range []string{"Tool call: command finished", "Command: go test ./...", "Exit code: 0", "<pre><code class=\"language-text\">line 1\nline 2</code></pre>"} {
|
for _, want := range []string{"Tool call: command finished", "<b>Command</b>", "<pre><code class=\"language-bash\">go test ./...</code></pre>", "Exit code: 0", "<pre><code class=\"language-text\">line 1\nline 2</code></pre>"} {
|
||||||
if !strings.Contains(text, want) {
|
if !strings.Contains(text, want) {
|
||||||
t.Fatalf("rendered command item missing %q in %q", want, text)
|
t.Fatalf("rendered command item missing %q in %q", want, text)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user