goal

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package goal implements the persistent goal system. Mirrors Codex's ThreadGoal / ThreadGoalStatus from protocol.rs and the goal-management tools (create_goal, get_goal, update_goal).

Index

Constants

View Source
const MaxObjectiveChars = 4_000

MaxObjectiveChars mirrors Codex's MAX_THREAD_GOAL_OBJECTIVE_CHARS.

Variables

This section is empty.

Functions

func BudgetLimitPrompt

func BudgetLimitPrompt(g *Goal) string

BudgetLimitPrompt returns the prompt injected when a goal's token budget is exhausted. Mirrors Codex's budget_limit_prompt() + budget_limit.md template.

func ContinuationPrompt

func ContinuationPrompt(g *Goal) string

ContinuationPrompt returns the hidden prompt injected after each turn of an active goal. Mirrors Codex's continuation_prompt() + continuation.md template.

func IsFinal

func IsFinal(s Status) bool

IsFinal returns true for terminal statuses where the goal is no longer actionable.

func ObjectiveUpdatedPrompt

func ObjectiveUpdatedPrompt(g *Goal) string

ObjectiveUpdatedPrompt returns the prompt injected when a goal's objective is edited mid-session. Mirrors Codex's objective_updated_prompt() + objective_updated.md.

func ValidateObjective

func ValidateObjective(objective string) error

ValidateObjective returns an error when the objective violates the Codex constraints.

Types

type Goal

type Goal struct {
	SessionID       string `json:"session_id"`
	Objective       string `json:"objective"`
	Status          Status `json:"status"`
	TokenBudget     *int64 `json:"token_budget,omitempty"`
	TokensUsed      int64  `json:"tokens_used"`
	TimeUsedSeconds int64  `json:"time_used_seconds"`
	CreatedAt       int64  `json:"created_at"`
	UpdatedAt       int64  `json:"updated_at"`
	// contains filtered or unexported fields
}

Goal mirrors Codex's ThreadGoal struct (protocol.rs:3651). Keyed by SessionID in the Store.

func (*Goal) IsOverBudget

func (g *Goal) IsOverBudget() bool

IsOverBudget returns true when the token budget is exhausted.

func (*Goal) RemainingTokens

func (g *Goal) RemainingTokens() int64

RemainingTokens returns how many tokens are left in the budget, or -1 if unbounded.

type Status

type Status string

Status mirrors Codex's ThreadGoalStatus.

const (
	StatusActive        Status = "active"
	StatusPaused        Status = "paused"
	StatusBlocked       Status = "blocked"
	StatusUsageLimited  Status = "usageLimited"
	StatusBudgetLimited Status = "budgetLimited"
	StatusComplete      Status = "complete"
)

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is the in-memory goal registry keyed by SessionID. Thread-safe. Mirrors Codex's server-side goal state per thread.

func GetDefaultStore

func GetDefaultStore() *Store

GetDefaultStore returns the process-level singleton GoalStore.

func NewStore

func NewStore() *Store

func (*Store) Clear

func (s *Store) Clear(sessionID string)

Clear removes the goal for sessionID. Mirrors Codex's ThreadGoalClearParams.

func (*Store) Get

func (s *Store) Get(sessionID string) (*Goal, bool)

Get returns the current goal for sessionID, or false if none.

func (*Store) RecordTokenUsage

func (s *Store) RecordTokenUsage(sessionID string, tokens int64)

RecordTokenUsage adds tokens to the running counter and auto-transitions to budgetLimited when the budget is exceeded. Called by the runner after each turn.

func (*Store) Set

func (s *Store) Set(sessionID, objective string, tokenBudget *int64) *Goal

Set creates or replaces the goal for sessionID. Always sets status=active and resets usage counters. Mirrors Codex's ThreadGoalSetParams (new objective → create).

func (*Store) Update

func (s *Store) Update(sessionID string, newStatus *Status, newObjective *string) (*Goal, bool)

Update mutates the goal's status and/or objective. Returns the updated goal, or false if no goal exists. Mirrors Codex's ThreadGoalSetParams (update existing goal).

Jump to

Keyboard shortcuts

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