Documentation
¶
Overview ¶
Package agentcontext assembles the system-context string handed to any agent. It is the Go counterpart of lib/tasks/agent_context.rb, and it is the single assembler: the CLI `tasks -p` path and (later) the TUI queue both build through here, so they can never disagree about what an agent sees.
In order:
- the repository TASK_AGENT.md contract (list-agent instructions),
- a short "Current environment" block (datetime, hostname, …) when enabled,
- the absolute file locations for this run (CLI, task files, memory),
- a short pointer to the task-set memory policy, and
- the current contents of agent-memory.md, clearly delimited as user-approved defaults, when that sidecar exists and is nonempty.
Coding-agent instructions live in AGENTS.md and are intentionally not injected here — workspace tools load that file separately.
The memory sidecar is read fresh on every call — never cached — so a default saved by one request is visible to the next, and an external edit or a git pull is picked up without restarting. An absent file simply omits the memory section; the builder never creates the file as a side effect.
Index ¶
Constants ¶
const ( MemoryHeader = "User-approved task-set defaults from agent-memory.md. These are " + "durable defaults for this task set; the current request still wins." MemoryBegin = "----- BEGIN AGENT MEMORY -----" MemoryEnd = "----- END AGENT MEMORY -----" // MemoryPointer is a short pointer only. The full policy prose lives in // TASK_AGENT.md (item 1), the versioned list-agent contract, so it is never // duplicated as a string that would drift out of sync. MemoryPointer = "Task-set memory: apply the agent-memory.md defaults per the memory " + "policy in TASK_AGENT.md — add, change, or remove them only on an " + "explicit request, and report any change alongside task changes." )
const Contract = "TASK_AGENT.md"
Contract is the source name of the versioned list-agent contract embedded in every binary. Installed builds must not depend on a source checkout.
const MemoryMaxBytes = 16 * 1024 // 16 KiB
MemoryMaxBytes is the prompt-injection budget for the memory sidecar. A larger file is a configuration mistake, so it fails loudly with the path instead of silently truncating a default the agent would then only half-apply.
Variables ¶
This section is empty.
Functions ¶
func Build ¶
Build assembles the whole context. cliExecutable is the installed tasks command — distinct from the task-data directory the harness runs in.
func FileLocations ¶
FileLocations is Config::Paths#agent_context: the block that lets a headless harness find the CLI and the task files even when they live outside the repo. Provider-agnostic — every backend uses it unchanged.
The memory sidecar path is always listed, even when the file does not exist yet, so an agent can create or edit it without guessing.
The CLI it names is the resolved executable path. That keeps agent prompts correct for Homebrew, make install, symlinks, and development builds.
func MemorySection ¶
MemorySection is the delimited memory block, or "" when the sidecar is absent or empty. An unreadable, invalid-UTF-8, oversize, or delimiter-carrying file is a hard error carrying the path — never a silent skip that would run the agent without the user's saved defaults.
Types ¶
type Error ¶
type Error struct{ Message string }
Error is raised when the memory sidecar exists but cannot be safely injected (unreadable, invalid UTF-8, oversize, or carrying a reserved delimiter). Callers surface the message and abort the run rather than proceed without the user's defaults — a half-applied default is worse than a refused request.