Documentation
¶
Overview ¶
Package openclaw replicates OpenClaw's agent behavior on Thane's plumbing.
When a request arrives with model "thane:openclaw", this package handles workspace file injection, skill discovery, and system prompt assembly following OpenClaw v2026.2.9 conventions. The core types are defined in config.OpenClawConfig; this package provides runtime behavior.
Index ¶
- func BuildSystemPrompt(cfg *config.OpenClawConfig, subagent bool) (string, error)
- func FormatSkillsBlock(skills []SkillEntry) string
- func ShouldFlush(tokenCount, compactionThreshold, softThresholdTokens int) bool
- func TruncateFile(content string, maxChars int) string
- type MemoryFlushConfig
- type SkillEntry
- type WorkspaceFile
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildSystemPrompt ¶
func BuildSystemPrompt(cfg *config.OpenClawConfig, subagent bool) (string, error)
BuildSystemPrompt assembles an OpenClaw-style system prompt from workspace files and skills. The prompt structure matches OpenClaw v2026.2.9's buildAgentSystemPrompt().
When subagent is true, only AGENTS.md and TOOLS.md are injected and skill/memory/heartbeat sections are suppressed.
func FormatSkillsBlock ¶
func FormatSkillsBlock(skills []SkillEntry) string
FormatSkillsBlock produces the <available_skills> XML block that the system prompt references for skill discovery.
func ShouldFlush ¶
ShouldFlush returns true when context tokens are approaching the compaction threshold and a memory flush should run before the next turn.
The formula matches OpenClaw v2026.2.9:
tokenCount >= compactionThreshold - softThresholdTokens
where compactionThreshold = maxTokens * triggerRatio.
func TruncateFile ¶
TruncateFile truncates content to approximately maxChars (byte count) using OpenClaw's 70/20 head/tail strategy: keep 70% from the start and 20% from the end, with a truncation marker in between (consuming the remaining 10%). Slice points are adjusted to avoid splitting UTF-8 runes.
Types ¶
type MemoryFlushConfig ¶
type MemoryFlushConfig struct {
// SoftThresholdTokens is subtracted from the compaction threshold
// to determine when the flush fires. The flush runs when:
// tokenCount >= compactionThreshold - SoftThresholdTokens.
// Default: 4000 (matching OpenClaw v2026.2.9).
SoftThresholdTokens int
// Prompt is the user message sent for the flush turn.
Prompt string
// SystemPromptSuffix is appended to the system prompt for flush turns.
SystemPromptSuffix string
}
MemoryFlushConfig holds settings for the pre-compaction memory flush.
func DefaultMemoryFlushConfig ¶
func DefaultMemoryFlushConfig() MemoryFlushConfig
DefaultMemoryFlushConfig returns flush settings matching OpenClaw v2026.2.9.
type SkillEntry ¶
type SkillEntry struct {
// Name is the skill directory name (e.g., "healthcheck").
Name string
// Description is extracted from YAML frontmatter.
Description string
// Location is the absolute path to the SKILL.md file.
Location string
}
SkillEntry represents a discovered SKILL.md file.
func DiscoverSkills ¶
func DiscoverSkills(dirs []string) []SkillEntry
DiscoverSkills scans directories for SKILL.md files and returns entries sorted by name. Directories are searched in priority order; skills in earlier directories override same-named skills in later ones.
type WorkspaceFile ¶
type WorkspaceFile struct {
// Name is the filename (e.g., "AGENTS.md").
Name string
// Path is the path to the file on disk, constructed by joining the
// workspace directory and Name. It is absolute only when the directory
// passed to LoadWorkspaceFiles is absolute.
Path string
// Content is the file content, possibly truncated.
Content string
// Missing is true when the file does not exist on disk or is
// effectively missing (empty or whitespace-only content).
Missing bool
}
WorkspaceFile represents a loaded workspace bootstrap file.
func LoadWorkspaceFiles ¶
func LoadWorkspaceFiles(dir string, subagent bool, maxChars int) []WorkspaceFile
LoadWorkspaceFiles reads OpenClaw bootstrap files from dir in the canonical injection order. When subagent is true, only AGENTS.md and TOOLS.md are loaded (matching OpenClaw's SUBAGENT_BOOTSTRAP_ALLOWLIST).
Files that do not exist are included with Missing=true and a placeholder content, unless they are optional (mustExist=false), in which case they are silently omitted. Files exceeding maxChars are truncated using the 70/20 head/tail strategy.