Skip to content

Commit b53ae97

Browse files
committed
auto-markdown for AI agents
I might regret this, but let's see how it goes.
1 parent af6d372 commit b53ae97

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

commands/root/table.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
// Copyright © 2015-2017,2025 Phil Pennock.
1+
// Copyright © 2015-2017,2025,2026 Phil Pennock.
22
// All rights reserved, except as granted under license.
33
// Licensed per file LICENSE.txt
44

55
package root
66

77
import (
8+
"os"
9+
810
"github.com/philpennock/character/internal/table"
911
)
1012

1113
func init() {
1214
// flagSet: match the logic from root.go
1315
flagSet := characterCmd.PersistentFlags()
16+
if table.MarkdownStyle != "" && isInsideAIAgent() {
17+
table.RenderStyle = table.MarkdownStyle
18+
}
1419
if table.AvailableStyles != nil {
1520
flagSet.StringVar(&table.RenderStyle, "table-style", table.RenderStyle, "style option for table")
1621
}
@@ -24,3 +29,19 @@ func tableRequestedList() bool {
2429
return false
2530
}
2631
}
32+
33+
func isInsideAIAgent() bool {
34+
for _, v := range []string{
35+
"AGENT", // multiple tools, emerging standard, name of agent as value, 'Goose', 'Amp'; <https://github.com/agentsmd/agents.md/issues/136>
36+
"AI_AGENT", // promoted by Vercel's detect-agent package
37+
"OPENCODE_AGENT", // Open source multi-model client; set to '1'
38+
"CLAUDECODE", // Anthropic's Claude Code, set to '1'
39+
"CURSOR_AGENT", // OpenAI's Cursor, set to '1'
40+
"GEMINI_CLI", // Google's Gemini, set to '1'
41+
} {
42+
if os.Getenv(v) != "" {
43+
return true
44+
}
45+
}
46+
return false
47+
}

internal/table/api_features.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2015,2016 Phil Pennock.
1+
// Copyright © 2015,2016,2026 Phil Pennock.
22
// All rights reserved, except as granted under license.
33
// Licensed per file LICENSE.txt
44

@@ -20,6 +20,9 @@ const (
2020
// RenderStyle represents how the table should be styled.
2121
var RenderStyle string
2222

23+
// MarkdownStyle is set non-empty if it is an available style for Markdown
24+
var MarkdownStyle string
25+
2326
// AvailableStyles when non-nil, indicates that we can set style options, and
2427
// lists those styles. Should be sorted.
2528
var AvailableStyles []string

internal/table/tabular.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2016,2025 Phil Pennock.
1+
// Copyright © 2016,2025,2026 Phil Pennock.
22
// All rights reserved, except as granted under license.
33
// Licensed per file LICENSE.txt
44

@@ -109,4 +109,5 @@ func (t *Table) SetOmitColumnName(name string) error {
109109
func init() {
110110
AvailableStyles = tb.ListStyles()
111111
RenderStyle = defaultRenderStyle
112+
MarkdownStyle = "markdown"
112113
}

0 commit comments

Comments
 (0)