bots-garden/mini-mepublic Fork
⑂ v0.8.0
Commits
⬇ Clone ▾
git clone https://git.rickub.com/bots-garden/mini-me.git
git clone ssh://git@rickub.com/bots-garden/mini-me.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP
🛟 Updated. fefc32cUnverified · on v0.8.0 · k33g · 13d ago
agentsmd_banner.go · 57 lines · 2.2 KBGo Blame HistoryRaw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main

import (
	"fmt"

	"mm/internal/agentsmd"
	"mm/internal/config"
)

// largeAgentsMdShare is the share of the context window (in percent) from
// which the banner warns about the size of AGENTS.md: the file rides in the
// system message of every request, for the whole conversation.
const largeAgentsMdShare = 20

// agentsMdBanner returns the banner's `agents.md:` column (with its leading
// " | ", or "" when there is nothing to say) and the warnings about the file.
// window is the context window in tokens, 0 when unknown. In ACP mode each
// session reads the file of its own cwd, which no session has given yet: the
// column only says where it will be looked for.
//
//	col, warnings := agentsMdBanner(false, 16384)
//	// " | agents.md: /home/me/project/AGENTS.md (~350 tokens)", nil
func agentsMdBanner(acpMode bool, window int) (string, []string) {
	settings := config.Cfg.AgentsMd
	if !settings.Enabled {
		return "", nil
	}
	if acpMode {
		return " | agents.md: <session cwd>/" + settings.Path, nil
	}
	f := agentsmd.Load("")
	switch f.Status {
	case agentsmd.Loaded:
		return fmt.Sprintf(" | agents.md: %s (~%d tokens)", f.Path, f.Tokens()), largeAgentsMdWarning(f, window)
	case agentsmd.Ignored:
		// Neutral, not a warning: a structured agent skips it on purpose.
		return " | agents.md: ignored (structured output)", nil
	case agentsmd.Skipped:
		return " | agents.md: skipped (too long)", []string{fmt.Sprintf(
			"%s skipped: %d characters > agentsMd.maxChars %d — it is not read at all (shorten it, or raise the limit)",
			f.Path, f.Chars(), settings.MaxChars)}
	case agentsmd.Unreadable:
		return "", []string{fmt.Sprintf("%s cannot be read: %v — no project instructions", f.Path, f.Err)}
	}
	return "", nil
}

// largeAgentsMdWarning says when the file takes a large share of a known
// context window. Nothing is cut: the user decides (agentsMd.maxChars).
func largeAgentsMdWarning(f agentsmd.File, window int) []string {
	if window <= 0 || f.Tokens()*100 < window*largeAgentsMdShare {
		return nil
	}
	return []string{fmt.Sprintf(
		"%s is ~%d tokens, %d %% of the %d-token context window — every request carries it (shorten it, or set agentsMd.maxChars)",
		f.Path, f.Tokens(), f.Tokens()*100/window, window)}
}