promptfacts

package
v1.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package promptfacts is the registry of short, labeled facts injected into an agent's system prompt under a "Current environment" heading. It is the Go counterpart of lib/tasks/prompt_facts.rb.

Each fact is toggled with a `prompt.<name> = on|off` config key; presentation order follows Registry, not map iteration, because the block is a rendered document and two runs that listed the facts in different orders would be two different system prompts.

A provider that fails or returns blank is omitted silently, so a flaky future source (weather, a calendar, …) can never abort an agent run.

Index

Constants

This section is empty.

Variables

View Source
var FactName = regexp.MustCompile(`\A[a-z][a-z0-9_-]*\z`)

FactName is PromptFacts::FACT_NAME — what a `prompt.<name>` key may spell.

View Source
var Registry = []Fact{
	{
		Name:    "datetime",
		Default: true,
		Render:  func(s Sources) (string, error) { return FormatDatetime(s.clock()), nil },
	},
	{
		Name:    "hostname",
		Default: true,
		Render:  func(s Sources) (string, error) { return s.hostname() },
	},
}

Registry is PromptFacts::REGISTRY, in its order.

Functions

func Defaults

func Defaults() map[string]bool

Defaults is the name → default-state map, derived from Registry so the two cannot drift. internal/config carries its own copy for the resolution it owns; TestConfigAndRegistryAgreeOnTheFactSet pins them together.

func FormatDatetime

func FormatDatetime(when time.Time) string

FormatDatetime is `time.strftime("%Y-%m-%d %a %H:%M %Z")`. The zone abbreviation is the last field, so an agent reading "09:00" knows which 09:00 it is without a second question.

func ParseToggle

func ParseToggle(value string) (bool, bool)

ParseToggle is PromptFacts.parse_toggle: a strict three-way answer. The second result is false for a value that names neither state, which the config parser treats as "say nothing" rather than as off — a typo must not silently disable a fact the user meant to enable.

func Render

func Render(enabled map[string]bool, sources Sources) string

Render builds the "Current environment" block, or "" when nothing is enabled or every provider failed. `enabled` is the resolved name → bool map; a nil map means "nothing was resolved", which resolves to the registry defaults the way `paths.prompt_facts || PromptFacts.resolve` does in Ruby.

func Resolve

func Resolve(overrides map[string]bool) map[string]bool

Resolve is PromptFacts.resolve: the effective on/off map for every REGISTERED fact. `overrides` comes from config (`prompt.*`); an absent key keeps the registry default and an unknown key is dropped, because only a fact this binary can render may claim to be on.

Types

type Fact

type Fact struct {
	Name    string
	Default bool
	// Render answers the fact's value. An error omits this line only — never
	// the block, and never the run.
	Render func(Sources) (string, error)
}

Fact is one registry entry: its config name, whether it is on when nothing says otherwise, and how it renders.

type Sources

type Sources struct {
	Clock    func() time.Time
	Hostname func() (string, error)
}

Sources are the injectable providers a fact renders from. Production uses time.Now and os.Hostname, which is what lib/tasks/prompt_facts.rb defaults to (Time.now / Socket.gethostname).

Deliberately NOT wired to internal/determinism: Ruby's `tasks -p` builds the context with the defaults and never passes a harness pin, so pinning here would make the Go system prompt differ from the Ruby one on exactly the runs a conformance harness performs. The block never reaches stdout, so there is nothing to gain and a difference to lose.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL