fix: shrink Telegram table width to 42 and suppress ASCII box-drawing
- markdownTableMaxWidth 90→42 to fit mobile monospace (~40 chars/line) - Add formatting rule to system prompt prohibiting ASCII art diagrams - Add strict table wrapping tests with exact expected output Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
433cacef39
commit
d5330b9f07
3 changed files with 89 additions and 5 deletions
|
|
@ -103,7 +103,13 @@ Your workspace is at: %s
|
||||||
## Context
|
## Context
|
||||||
<requirements, decisions, environment>
|
<requirements, decisions, environment>
|
||||||
- Keep each phase to 3-5 steps. Do NOT create plans without /plan.
|
- Keep each phase to 3-5 steps. Do NOT create plans without /plan.
|
||||||
- Always ask about build/test/lint commands during interview.`,
|
- Always ask about build/test/lint commands during interview.
|
||||||
|
|
||||||
|
4. **Response Formatting**
|
||||||
|
- NEVER use ASCII box-drawing characters (┌─┐│└─┘╔═╗║╚═╝ etc.) or ASCII art diagrams.
|
||||||
|
- Use markdown headings, bold, lists, and indentation for structure.
|
||||||
|
- Keep lines short — most users read on mobile.
|
||||||
|
- For architecture/flow, use arrow text: CLI → Pipeline → Adapters`,
|
||||||
now, runtime, workspacePath, workspacePath, workspacePath, workspacePath, toolsSection)
|
now, runtime, workspacePath, workspacePath, workspacePath, workspacePath, toolsSection)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ func (c *thinkingCancel) Cancel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const telegramMaxMessageChars = 3900
|
const telegramMaxMessageChars = 3900
|
||||||
const markdownTableMaxWidth = 90
|
const markdownTableMaxWidth = 42
|
||||||
const markdownTableMinColWidth = 6
|
const markdownTableMinColWidth = 6
|
||||||
|
|
||||||
var thinkBlockPattern = regexp.MustCompile(`(?is)<think>.*?</think>`)
|
var thinkBlockPattern = regexp.MustCompile(`(?is)<think>.*?</think>`)
|
||||||
|
|
|
||||||
|
|
@ -74,9 +74,87 @@ func TestMarkdownToTelegramHTML_TableWrapsLongCell(t *testing.T) {
|
||||||
if !strings.Contains(got, "| short") {
|
if !strings.Contains(got, "| short") {
|
||||||
t.Fatalf("expected data row with short cell, got: %q", got)
|
t.Fatalf("expected data row with short cell, got: %q", got)
|
||||||
}
|
}
|
||||||
// Wrapped content should include a prefix from the long sentence.
|
// With markdownTableMaxWidth=42 the long cell MUST be wrapped into
|
||||||
if !strings.Contains(got, "this is a very") {
|
// multiple visual lines. Verify the continuation line exists.
|
||||||
t.Fatalf("expected wrapped long cell content, got: %q", got)
|
if !strings.Contains(got, "long cell that should wrap") {
|
||||||
|
t.Fatalf("expected wrapped continuation line, got: %q", got)
|
||||||
|
}
|
||||||
|
// The continuation row must have an empty first column (padding only).
|
||||||
|
if !strings.Contains(got, "| | long cell") {
|
||||||
|
t.Fatalf("expected continuation row with empty first col, got: %q", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFormatMarkdownTable_Width42(t *testing.T) {
|
||||||
|
lines := []string{
|
||||||
|
"| col1 | col2 |",
|
||||||
|
"| --- | --- |",
|
||||||
|
"| short | this is a very very very very long cell that should wrap |",
|
||||||
|
}
|
||||||
|
got := formatMarkdownTable(lines)
|
||||||
|
|
||||||
|
// Every line must fit within markdownTableMaxWidth (42).
|
||||||
|
for i, line := range strings.Split(got, "\n") {
|
||||||
|
w := displayWidth(line)
|
||||||
|
if w > markdownTableMaxWidth {
|
||||||
|
t.Errorf("line %d width %d > %d: %q", i, w, markdownTableMaxWidth, line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Must produce more lines than a non-wrapped table (header + sep + 1 data = 3).
|
||||||
|
// With wrapping the data row becomes 2 visual lines → total 4.
|
||||||
|
lineCount := len(strings.Split(got, "\n"))
|
||||||
|
if lineCount < 4 {
|
||||||
|
t.Errorf("expected at least 4 lines (wrap must occur), got %d:\n%s", lineCount, got)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify continuation row has blank first column.
|
||||||
|
if !strings.Contains(got, "| | long cell that should wrap") {
|
||||||
|
t.Errorf("expected continuation row, got:\n%s", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestFormatMarkdownTable_MultiColWrap verifies that a multi-column,
|
||||||
|
// multi-row table correctly wraps one long cell while leaving other
|
||||||
|
// rows and columns unaffected.
|
||||||
|
// With markdownTableMaxWidth=42, col widths shrink to [7, 5, 20].
|
||||||
|
// Bob's "Needs more practice in writing" (30 chars) wraps at width 20.
|
||||||
|
func TestFormatMarkdownTable_MultiColWrap(t *testing.T) {
|
||||||
|
lines := []string{
|
||||||
|
"| Name | Score | Comment |",
|
||||||
|
"| --- | --- | --- |",
|
||||||
|
"| Alice | 95 | Great job |",
|
||||||
|
"| Bob | 72 | Needs more practice in writing |",
|
||||||
|
"| Charlie | 88 | Good |",
|
||||||
|
}
|
||||||
|
got := formatMarkdownTable(lines)
|
||||||
|
rows := strings.Split(got, "\n")
|
||||||
|
|
||||||
|
wantLines := []string{
|
||||||
|
"| Name | Score | Comment |",
|
||||||
|
"| ------- | ----- | -------------------- |",
|
||||||
|
"| Alice | 95 | Great job |",
|
||||||
|
"| Bob | 72 | Needs more practice |",
|
||||||
|
"| | | in writing |",
|
||||||
|
"| Charlie | 88 | Good |",
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(rows) != len(wantLines) {
|
||||||
|
t.Fatalf("line count: got %d, want %d\nactual:\n%s", len(rows), len(wantLines), got)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, want := range wantLines {
|
||||||
|
if rows[i] != want {
|
||||||
|
t.Errorf("line %d:\n got: %q\n want: %q", i, rows[i], want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Every line must be exactly markdownTableMaxWidth.
|
||||||
|
for i, line := range rows {
|
||||||
|
w := displayWidth(line)
|
||||||
|
if w != markdownTableMaxWidth {
|
||||||
|
t.Errorf("line %d: displayWidth=%d, want %d: %q", i, w, markdownTableMaxWidth, line)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue