Documentation
¶
Index ¶
- Constants
- Variables
- func AppendMessage(path string, msg Message) error
- func ArchiveSummary(st SessionTasks) string
- func BuildCompactionSummary(messages []Message) string
- func BuildCompactionSummaryWithOptions(messages []Message, opts CompactionSummaryOptions) string
- func EstimateMessageTokenCost(msg Message) int
- func EstimateTokens(messages []Message) int
- func EvidenceTypeLabel(kind string) string
- func FormatTasksForInjection(st SessionTasks) string
- func IsTasksInjectionMessage(msg Message) bool
- func NextEvidenceID(tasks []Task) string
- func NextTaskID(tasks []Task) string
- func NormalizeAutoResumeModes(values []string) []string
- func NowRFC3339() string
- func RewriteMessages(path string, messages []Message) error
- func TaskSummary(tasks []Task) map[string]int
- func ValidEvidenceType(kind string) bool
- func ValidPlanStatus(s string) bool
- func ValidTaskStatus(status string) bool
- type CompactOptions
- type CompactResult
- type CompactionSummaryOptions
- type ForkOptions
- type ForkPromotionCandidate
- type ForkPromotionOptions
- type HistorySnapshot
- type Message
- type PendingCriticFeedback
- type Plan
- type Session
- type SessionAutomationConsent
- type SessionCritic
- type SessionGoal
- type SessionStyleControl
- type SessionTasks
- type SessionToolConfig
- type SessionWithPlanTasks
- type Store
- func (s *Store) ClearGoal(id string) (Session, error)
- func (s *Store) Create(title string) (Session, error)
- func (s *Store) CreateWithOptions(title string, kind string, hidden bool) (Session, error)
- func (s *Store) Delete(id string) error
- func (s *Store) EligibleCwds(id string) ([]string, error)
- func (s *Store) EnsureMain() (Session, error)
- func (s *Store) EnsureWorker(projectID string) (Session, error)
- func (s *Store) ForkFromMessage(parentID string, messageID string, opts ForkOptions) (Session, error)
- func (s *Store) Get(id string) (Session, error)
- func (s *Store) GetCurrentDir(id string) (string, error)
- func (s *Store) GetTasks(sessionID string) (SessionTasks, error)
- func (s *Store) Latest() (Session, error)
- func (s *Store) LatestAll() (Session, error)
- func (s *Store) List() ([]Session, error)
- func (s *Store) ListAll() ([]Session, error)
- func (s *Store) ListSessionsWithPlans(includeHidden bool, activeOnly bool) ([]SessionWithPlanTasks, error)
- func (s *Store) SaveTasks(sessionID string, tasks SessionTasks) error
- func (s *Store) SetArchived(id string, archived bool) (Session, error)
- func (s *Store) SetAutomationConsent(id string, consent *SessionAutomationConsent) error
- func (s *Store) SetCritic(id string, critic *SessionCritic) (Session, error)
- func (s *Store) SetCurrentDir(id string, dir string) error
- func (s *Store) SetGoal(id string, goal *SessionGoal) (Session, error)
- func (s *Store) SetLastCompactionMode(id string, mode string) error
- func (s *Store) SetPinned(id string, pinned bool) (Session, error)
- func (s *Store) SetPromptOverride(id string, override string) error
- func (s *Store) SetStyleControl(id string, style *SessionStyleControl) error
- func (s *Store) SetTasksSavedHook(hook func(sessionID string, tasks SessionTasks))
- func (s *Store) SetTitle(id string, title string) error
- func (s *Store) SetToolConfig(id string, config *SessionToolConfig) error
- func (s *Store) SetUpstreamSessionID(id string, upstreamID string) error
- func (s *Store) SetWorkDirs(id string, dirs []string, currentDir string) error
- func (s *Store) TakePendingCriticFeedback(id string) (PendingCriticFeedback, error)
- func (s *Store) Touch(id string, updatedAt time.Time) error
- func (s *Store) TranscriptPath(id string) string
- func (s *Store) UpdateCriticProgress(id string, mutate func(*SessionCritic) *SessionCritic) (Session, error)
- func (s *Store) UpdateGoalProgress(id string, mutate func(*SessionGoal) *SessionGoal) (Session, error)
- func (s *Store) WorkspaceDir() string
- type Task
- type TaskContract
- type TaskEvidence
- type TaskProofPolicy
Constants ¶
const ( DefaultKeepRecentMessages = 20 MinKeepRecentMessages = 5 MaxKeepRecentMessages = 200 DefaultKeepRecentTokens = 12000 MinKeepRecentTokens = 1 MaxKeepRecentTokens = 64000 DefaultKeepRecentFraction = 0.30 MinKeepRecentFraction = 0.05 MaxKeepRecentFraction = 0.90 )
const ( SessionGoalStatusActive = "active" SessionGoalStatusSatisfied = "satisfied" SessionGoalStatusExhausted = "exhausted" DefaultGoalMaxAutoContinues = 3 MaxGoalMaxAutoContinues = 20 MaxGoalDescriptionLen = 2000 )
Session goal status values.
const ( DefaultAutoResumeAfterMinutes = 30 AutoResumeModeProceedWithAssumption = "proceed_with_assumption" AutoResumeModeMoveToNextTask = "move_to_next_task" AutoResumeModeRecordAssumptionAndProceed = "record_assumption_and_proceed" )
const ( SessionCriticStatusIdle = "idle" SessionCriticStatusReviewing = "reviewing" SessionCriticStatusSatisfied = "satisfied" SessionCriticStatusExhausted = "exhausted" // DefaultCriticMaxIterations is the default per-plan-transition review // budget. Three rounds matches the goal-judge default and is the value // users see in the wizard prose. DefaultCriticMaxIterations = 3 // MaxCriticMaxIterations caps the configurable budget. Five is generous // for a single plan transition; anything higher tends to be a runaway // rather than productive critique. MaxCriticMaxIterations = 5 // MaxCriticFeedbackLen bounds the feedback string we persist so the // transcript JSON does not balloon when a reviewer emits a very long // bullet list. MaxCriticFeedbackLen = 4000 )
SessionCritic status values.
const ( DefaultAutoContinueMaxIterations = 5 AutoContinueIterationsHardCap = 10 AutoContinueIterationWindow = 24 * time.Hour )
Auto-continue iteration limits. The hard upper bound is enforced regardless of per-plan overrides, and the rolling window is the period over which audit-log entries are counted toward the cap.
const ( PlanStatusDrafting = "drafting" PlanStatusProposed = "proposed" PlanStatusExecuting = "executing" PlanStatusPaused = "paused" PlanStatusCompleted = "completed" PlanStatusAborted = "aborted" )
Plan status constants — enumerate the states a plan can be in.
const ( ContractStatusDraft = "draft" ContractStatusApproved = "approved" )
const ( EvidenceTypeTestResult = "test_result" EvidenceTypeImage = "image" EvidenceTypeLogExcerpt = "log_excerpt" EvidenceTypePRLink = "pr_link" EvidenceTypeReleaseTag = "release_tag" EvidenceTypeCommandOutputSummary = "command_output_summary" )
const ( // TasksInjectionHeader marks task state that was deliberately reinserted // after context compression so later compactions can replace stale copies. TasksInjectionHeader = "## Active Plan (preserved across compression)" )
Variables ¶
var ErrCwdNotEligible = errors.New("session: cwd not in eligible work_dirs")
ErrCwdNotEligible is returned by SetCurrentDir when the supplied directory is not present in the session's normalized work_dirs (i.e. neither the artifact dir nor any user-registered work_dir).
var ErrSessionKindUnsupported = errors.New("session: kind does not support goals")
ErrSessionKindUnsupported is returned by goal mutations when the session kind does not permit a goal (currently only "main" kind sessions support goals).
var ErrSessionNotFound = errors.New("session not found")
ErrSessionNotFound is returned when a session ID does not resolve to an entry in the index. The message is intentionally kept stable for callers that match on the substring "session not found".
Functions ¶
func AppendMessage ¶
AppendMessage appends a single message as one JSON line to the JSONL file at path.
func ArchiveSummary ¶ added in v0.20.0
func ArchiveSummary(st SessionTasks) string
ArchiveSummary returns a human-readable summary of the plan and tasks for memory archival.
func BuildCompactionSummary ¶
func BuildCompactionSummaryWithOptions ¶ added in v0.10.2
func BuildCompactionSummaryWithOptions(messages []Message, opts CompactionSummaryOptions) string
func EstimateMessageTokenCost ¶ added in v0.27.0
EstimateMessageTokenCost is the exported wrapper for single-message token estimation.
func EstimateTokens ¶
func EvidenceTypeLabel ¶ added in v0.31.100
func FormatTasksForInjection ¶ added in v0.20.0
func FormatTasksForInjection(st SessionTasks) string
FormatTasksForInjection renders active tasks for system prompt injection after context compression. Only includes pending and in_progress tasks.
func IsTasksInjectionMessage ¶ added in v0.31.16
IsTasksInjectionMessage reports whether msg is a previously injected active plan block. Compaction replaces these blocks with fresh task state.
func NextEvidenceID ¶ added in v0.31.100
func NextTaskID ¶ added in v0.20.0
NextTaskID returns the next sequential task ID based on existing tasks.
func NormalizeAutoResumeModes ¶ added in v0.31.114
func NowRFC3339 ¶ added in v0.20.0
func NowRFC3339() string
NowRFC3339 returns current time in RFC3339 format.
func RewriteMessages ¶
RewriteMessages replaces the transcript contents with the provided messages.
func TaskSummary ¶ added in v0.20.0
TaskSummary returns a compact summary of task statuses.
func ValidEvidenceType ¶ added in v0.31.100
func ValidPlanStatus ¶ added in v0.31.10
ValidPlanStatus reports whether s is a recognized plan status.
func ValidTaskStatus ¶ added in v0.20.0
ValidTaskStatus checks if a status string is valid.
Types ¶
type CompactOptions ¶
type CompactOptions struct {
BeforeRewrite func(summary string, compactedCount int, originalCount int) error
SummaryBuilder func(messages []Message, previousContext string) (string, error)
PostSummaryMessages []Message
KeepRecentTokens int
KeepRecentFraction float64
SummaryInstructions string
// PreloadedMessages supplies already-read messages to avoid a second ReadMessages
// call on the same path. When set, ReadMessages is skipped, preventing a
// reentrant-lock deadlock when the caller already holds the path lock.
PreloadedMessages []Message
}
CompactOptions configures CompactTranscriptWithOptions.
KeepRecent strategies are tried in priority order — the first non-zero option wins, lower options are ignored:
- KeepRecentFraction (if > 0): retain the most recent X% of total transcript tokens (clamped to MinKeepRecentFraction..MaxKeepRecentFraction).
- KeepRecentTokens (if > 0): retain a specific token budget (clamped to MinKeepRecentTokens..MaxKeepRecentTokens).
- keepRecent positional argument: retain a specific message count (clamped to MinKeepRecentMessages..MaxKeepRecentMessages, default DefaultKeepRecentMessages = 20).
Setting both KeepRecentFraction and KeepRecentTokens is supported but the fraction wins — set only the strategy you want.
type CompactResult ¶
type CompactResult struct {
Compacted bool
OriginalCount int
FinalCount int
CompactedCount int
Summary string
}
func CompactTranscript ¶
func CompactTranscriptWithOptions ¶
func CompactTranscriptWithOptions(path string, keepRecent int, now time.Time, opts CompactOptions) (CompactResult, error)
type CompactionSummaryOptions ¶ added in v0.10.2
type ForkOptions ¶ added in v0.31.105
ForkOptions controls how a child session is created from an existing transcript message.
type ForkPromotionCandidate ¶ added in v0.31.107
type ForkPromotionCandidate struct {
ID string `json:"id"`
SessionID string `json:"session_id"`
ParentSessionID string `json:"parent_session_id"`
RootSessionID string `json:"root_session_id,omitempty"`
ForkedFromMessageID string `json:"forked_from_message_id,omitempty"`
ForkedFromIndex *int `json:"forked_from_index,omitempty"`
MessageID string `json:"message_id"`
MessageIndex int `json:"message_index"`
Role string `json:"role"`
Category string `json:"category"`
Summary string `json:"summary"`
CreatedAt time.Time `json:"created_at"`
}
ForkPromotionCandidate is a reviewable insight from a forked session that can be queued into Memory Inbox for explicit user approval.
func DetectForkPromotionCandidates ¶ added in v0.31.107
func DetectForkPromotionCandidates(sess Session, messages []Message, opts ForkPromotionOptions) []ForkPromotionCandidate
DetectForkPromotionCandidates extracts reusable post-fork insights without mutating any session transcript. It is intentionally deterministic so the UI can refresh and submit stable candidate IDs.
type ForkPromotionOptions ¶ added in v0.31.107
ForkPromotionOptions controls deterministic candidate extraction from a fork.
type HistorySnapshot ¶
HistorySnapshot captures the portion of transcript loaded into model context.
func LoadHistorySnapshot ¶
func LoadHistorySnapshot(path string, maxTokens int) (HistorySnapshot, error)
LoadHistorySnapshot reads transcript history and returns the loaded messages together with token and compaction-boundary metadata.
type Message ¶
type Message struct {
ID string `json:"id,omitempty"`
Role string `json:"role"`
Content string `json:"content"`
Timestamp time.Time `json:"timestamp"`
ToolName string `json:"tool_name,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
ToolArgs string `json:"tool_args,omitempty"`
ToolIsError bool `json:"tool_is_error,omitempty"`
}
Message represents a single chat message in a session transcript. Tool fields are optional (omitempty) for backward compatibility with existing transcripts.
func LoadHistory ¶
LoadHistory reads messages from a JSONL file, returning only the most recent messages that fit within the given token budget. Tokens are estimated as len(content)/4. Messages are returned in chronological order (oldest first). Returns an empty slice if the file does not exist.
func ReadMessages ¶
ReadMessages reads all messages from a JSONL file. Returns an empty slice if the file does not exist or is empty.
type PendingCriticFeedback ¶ added in v0.32.50
PendingCriticFeedback is the structured payload returned by TakePendingCriticFeedback: the raw feedback string, the trigger that produced it, and the round number recorded when it was queued.
type Plan ¶ added in v0.20.0
type Plan struct {
Goal string `json:"goal"`
Constraints string `json:"constraints,omitempty"`
CreatedAt string `json:"created_at"`
Status string `json:"status,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
// AutoContinueEnabled, when true, lets pulse auto-continue this session
// after the current plan completes — either by proposing a follow-up
// plan or marking the goal achieved. The hard iteration cap is enforced
// via the automation audit log (counting successful auto-continue turns
// in a rolling window) so it survives plan replacement. Opt-in (default
// false).
AutoContinueEnabled bool `json:"auto_continue_enabled,omitempty"`
// AutoContinueMaxIterations caps how many auto-continue turns may run
// for this session in the rolling AutoContinueIterationWindow. Zero
// means use DefaultAutoContinueMaxIterations.
AutoContinueMaxIterations int `json:"auto_continue_max_iterations,omitempty"`
}
Plan represents a high-level goal for the current session. At most one plan is active per session; setting a new plan archives the previous one.
Status follows a small state machine:
drafting ──plan_propose──► proposed ──plan_approve──► executing ▲ │ │ │ plan_pause │ ▼ │ paused │ │ │ user edit plan_resume │ └──────────────────── ◄───────────────┘ executing ─(all tasks completed/cancelled)──► completed any (except completed/aborted) ──plan_abort──► aborted
Empty Status (legacy plans saved before this field existed) is treated as "executing" on load so existing sessions keep their prior behavior.
func (*Plan) EffectiveAutoContinueMaxIterations ¶ added in v0.31.145
EffectiveAutoContinueMaxIterations returns the cap that applies to this plan, clamping to the hard upper bound and falling back to the default when unset.
type Session ¶
type Session struct {
ID string `json:"id"`
Title string `json:"title"`
Kind string `json:"kind,omitempty"`
Hidden bool `json:"hidden,omitempty"`
ParentSessionID string `json:"parent_session_id,omitempty"`
RootSessionID string `json:"root_session_id,omitempty"`
ForkedFromMessageID string `json:"forked_from_message_id,omitempty"`
ForkedFromIndex *int `json:"forked_from_index,omitempty"`
ForkReason string `json:"fork_reason,omitempty"`
ToolConfig *SessionToolConfig `json:"tool_config,omitempty"`
AutomationConsent *SessionAutomationConsent `json:"automation_consent,omitempty"`
StyleControl *SessionStyleControl `json:"style_control,omitempty"`
LastCompactionMode string `json:"last_compaction_mode,omitempty"`
PromptOverride string `json:"prompt_override,omitempty"`
WorkDirs []string `json:"work_dirs,omitempty"`
CurrentDir string `json:"current_dir,omitempty"`
// UpstreamSessionID is an opaque handle exposed by certain LLM providers
// (currently only claude-code-cli) that lets a follow-up turn resume the
// remote session instead of replaying the full transcript. Empty for
// stateless providers or fresh sessions. Persisted so the next turn can
// pass it back via llm.ChatOptions.ResumeSessionID.
UpstreamSessionID string `json:"upstream_session_id,omitempty"`
ArchivedAt *time.Time `json:"archived_at,omitempty"`
PinnedAt *time.Time `json:"pinned_at,omitempty"`
Goal *SessionGoal `json:"goal,omitempty"`
Critic *SessionCritic `json:"critic,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type SessionAutomationConsent ¶ added in v0.31.108
type SessionAutomationConsent struct {
AutoResume bool `json:"auto_resume,omitempty"`
AutoResumeEnabled bool `json:"auto_resume_enabled,omitempty"`
AutoResumeAfterMinutes int `json:"auto_resume_after_minutes,omitempty"`
AllowedResumeModes []string `json:"allowed_resume_modes,omitempty"`
GitMutations bool `json:"git_mutations,omitempty"`
AutonomousMutations bool `json:"autonomous_mutations,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
}
func (*SessionAutomationConsent) AllowsAutoResume ¶ added in v0.31.114
func (c *SessionAutomationConsent) AllowsAutoResume() bool
func (*SessionAutomationConsent) AllowsAutonomousMutation ¶ added in v0.31.108
func (c *SessionAutomationConsent) AllowsAutonomousMutation() bool
func (*SessionAutomationConsent) EffectiveAllowedResumeModes ¶ added in v0.31.114
func (c *SessionAutomationConsent) EffectiveAllowedResumeModes() []string
func (*SessionAutomationConsent) EffectiveAutoResumeAfterMinutes ¶ added in v0.31.114
func (c *SessionAutomationConsent) EffectiveAutoResumeAfterMinutes() int
type SessionCritic ¶ added in v0.32.42
type SessionCritic struct {
Enabled bool `json:"enabled"`
MaxIterations int `json:"max_iterations,omitempty"`
CurrentIteration int `json:"current_iteration,omitempty"`
Status string `json:"status,omitempty"`
LastFeedback string `json:"last_feedback,omitempty"`
LastTrigger string `json:"last_trigger,omitempty"`
LastReviewedPlanSig string `json:"last_reviewed_plan_sig,omitempty"`
// LastReviewedTurnSig tracks the assistant_turn signature already reviewed
// so we don't queue duplicate feedback if the same response is re-evaluated.
LastReviewedTurnSig string `json:"last_reviewed_turn_sig,omitempty"`
// PendingFeedback holds critic output produced by the async reviewer that
// has not yet been delivered to the main LLM. It is consumed (and cleared)
// when the next user turn builds its prompt.
PendingFeedback string `json:"pending_feedback,omitempty"`
PendingFeedbackTrigger string `json:"pending_feedback_trigger,omitempty"`
PendingFeedbackRound int `json:"pending_feedback_round,omitempty"`
PendingFeedbackAt *time.Time `json:"pending_feedback_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
}
SessionCritic captures the per-session critic-agent configuration plus the runtime state for the active review cycle. The chat handler reads/writes this through Store.SetCritic / Store.UpdateCriticProgress, so all mutation paths share one normalization routine.
Lifecycle:
- User toggles Enabled = true (status starts "idle", iteration 0).
- On a plan transition (Proposed or Completed) the hook bumps CurrentIteration, sets Status = "reviewing", records LastTrigger and the plan signature used to dedupe a single transition.
- When the reviewer returns Acceptable=true the hook sets Status = "satisfied" and resets CurrentIteration.
- When CurrentIteration reaches MaxIterations without acceptance, the hook sets Status = "exhausted" and stops issuing feedback until the next plan transition.
func InheritCriticConfig ¶ added in v0.32.49
func InheritCriticConfig(source *SessionCritic) *SessionCritic
InheritCriticConfig returns a fresh SessionCritic that carries the user-tunable fields (Enabled, MaxIterations) from source while resetting all runtime state to "idle". Returns nil when source is nil or disabled so a disabled parent does not register a stub on the child.
func NormalizeCritic ¶ added in v0.32.42
func NormalizeCritic(c *SessionCritic) *SessionCritic
NormalizeCritic trims and clamps fields and defaults Status when unset. Returns nil when the input is nil so callers can store-or-clear with a single statement.
func (*SessionCritic) EffectiveMaxIterations ¶ added in v0.32.42
func (c *SessionCritic) EffectiveMaxIterations() int
EffectiveMaxIterations clamps the configured budget into [1, MaxCriticMaxIterations] and falls back to DefaultCriticMaxIterations on zero/negative input.
func (*SessionCritic) IsEnabled ¶ added in v0.32.42
func (c *SessionCritic) IsEnabled() bool
IsEnabled reports whether the critic agent should run for this session.
type SessionGoal ¶ added in v0.32.41
type SessionGoal struct {
Description string `json:"description"`
CreatedAt time.Time `json:"created_at"`
MaxAutoContinues int `json:"max_auto_continues"`
AutoContinueCount int `json:"auto_continue_count"`
LastJudgedAt *time.Time `json:"last_judged_at,omitempty"`
Status string `json:"status"`
}
SessionGoal captures a single active goal for a chat session. When set, the chat handler appends the goal to the system prompt and runs an independent judge LLM after each turn; if the judge says "not satisfied" the loop may auto-continue up to MaxAutoContinues times.
func NormalizeGoal ¶ added in v0.32.41
func NormalizeGoal(goal *SessionGoal) *SessionGoal
NormalizeGoal trims and clamps fields, defaulting status/max where unset. Returns nil when the description is empty (treated as "no goal").
func (*SessionGoal) IsActive ¶ added in v0.32.41
func (g *SessionGoal) IsActive() bool
IsActive reports whether the goal is in the active state and should be surfaced to the LLM / agent loop.
type SessionStyleControl ¶ added in v0.31.120
type SessionStyleControl struct {
Directness *int `json:"directness,omitempty"`
Humor *int `json:"humor,omitempty"`
Caution *int `json:"caution,omitempty"`
Autonomy *int `json:"autonomy,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
}
func NormalizeStyleControl ¶ added in v0.31.120
func NormalizeStyleControl(style *SessionStyleControl) *SessionStyleControl
type SessionTasks ¶ added in v0.20.0
type SessionTasks struct {
Plan *Plan `json:"plan,omitempty"`
Contract *TaskContract `json:"contract,omitempty"`
Tasks []Task `json:"tasks"`
}
SessionTasks holds the current plan and its associated tasks for a session.
func (SessionTasks) MarshalJSON ¶ added in v0.23.0
func (st SessionTasks) MarshalJSON() ([]byte, error)
MarshalJSON keeps the API contract stable by always emitting tasks as an array.
type SessionToolConfig ¶ added in v0.16.0
type SessionToolConfig struct {
ToolsEnabled []string `json:"tools_enabled,omitempty"`
ToolsCustom bool `json:"tools_custom,omitempty"`
ToolsDisabled []string `json:"tools_disabled,omitempty"`
ToolsAllowGroups []string `json:"tools_allow_groups,omitempty"`
ToolsDenyGroups []string `json:"tools_deny_groups,omitempty"`
SkillsEnabled []string `json:"skills_enabled,omitempty"`
SkillsCustom bool `json:"skills_custom,omitempty"`
CommandsEnabled []string `json:"commands_enabled,omitempty"`
CommandsCustom bool `json:"commands_custom,omitempty"`
MCPEnabled []string `json:"mcp_enabled,omitempty"`
MCPCustom bool `json:"mcp_custom,omitempty"`
}
SessionToolConfig holds per-session tool/skill/MCP configuration. nil slices mean "inherit all from system defaults".
type SessionWithPlanTasks ¶ added in v0.31.90
type SessionWithPlanTasks struct {
Session Session `json:"session"`
Plan *Plan `json:"plan,omitempty"`
Contract *TaskContract `json:"contract,omitempty"`
Tasks []Task `json:"tasks"`
Summary map[string]int `json:"summary"`
UpdatedAt time.Time `json:"updated_at"`
StaleCompleted bool `json:"stale_completed"`
}
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func (*Store) ClearGoal ¶ added in v0.32.41
ClearGoal removes the session's goal regardless of status. Safe to call when no goal is set.
func (*Store) CreateWithOptions ¶
func (*Store) EligibleCwds ¶ added in v0.31.162
EligibleCwds returns the canonical list of directories the session may use as its current working directory. The result always contains the session's artifact dir (as element 0) followed by any user-registered work_dirs in insertion order, deduplicated. The slice is a defensive copy.
func (*Store) EnsureMain ¶
func (*Store) ForkFromMessage ¶ added in v0.31.105
func (s *Store) ForkFromMessage(parentID string, messageID string, opts ForkOptions) (Session, error)
ForkFromMessage creates a new visible session whose transcript contains the parent transcript prefix through the selected message.
func (*Store) GetCurrentDir ¶ added in v0.31.162
GetCurrentDir returns the session's active cwd, falling back to the artifact dir when no explicit current_dir is set.
func (*Store) GetTasks ¶ added in v0.20.0
func (s *Store) GetTasks(sessionID string) (SessionTasks, error)
GetTasks reads the tasks file for a session. Returns empty SessionTasks if not found.
func (*Store) ListSessionsWithPlans ¶ added in v0.31.90
func (s *Store) ListSessionsWithPlans(includeHidden bool, activeOnly bool) ([]SessionWithPlanTasks, error)
func (*Store) SaveTasks ¶ added in v0.20.0
func (s *Store) SaveTasks(sessionID string, tasks SessionTasks) error
SaveTasks writes the tasks file for a session.
func (*Store) SetArchived ¶ added in v0.32.7
func (*Store) SetAutomationConsent ¶ added in v0.31.108
func (s *Store) SetAutomationConsent(id string, consent *SessionAutomationConsent) error
SetAutomationConsent updates the per-session automation consent policy.
func (*Store) SetCritic ¶ added in v0.32.42
func (s *Store) SetCritic(id string, critic *SessionCritic) (Session, error)
SetCritic replaces the session's critic configuration. Any session kind is permitted — worker/subagent sessions still benefit from review on the assistant_turn trigger even when no user-visible plan exists. A nil critic clears the configuration entirely.
func (*Store) SetCurrentDir ¶ added in v0.22.0
SetCurrentDir updates only the current working directory for a session.
func (*Store) SetGoal ¶ added in v0.32.41
func (s *Store) SetGoal(id string, goal *SessionGoal) (Session, error)
SetGoal replaces the session's active goal. Only "main" sessions are permitted. Passing nil or a goal with empty description clears it.
func (*Store) SetLastCompactionMode ¶ added in v0.25.0
func (*Store) SetPromptOverride ¶ added in v0.16.0
SetPromptOverride updates the per-session prompt override.
func (*Store) SetStyleControl ¶ added in v0.31.120
func (s *Store) SetStyleControl(id string, style *SessionStyleControl) error
SetStyleControl updates the per-session behavioral style override.
func (*Store) SetTasksSavedHook ¶ added in v0.35.0
func (s *Store) SetTasksSavedHook(hook func(sessionID string, tasks SessionTasks))
SetTasksSavedHook installs a best-effort observer that runs synchronously after tasks.json has been replaced atomically. The observer cannot turn a successful legacy save into a retryable error; callers that need error reporting should log or persist it inside the hook.
func (*Store) SetToolConfig ¶ added in v0.16.0
func (s *Store) SetToolConfig(id string, config *SessionToolConfig) error
SetToolConfig updates the per-session tool configuration.
func (*Store) SetUpstreamSessionID ¶ added in v0.32.58
SetUpstreamSessionID records the opaque upstream handle returned by a provider that supports resumable sessions (currently only claude-code-cli). Passing an empty string clears the field. No-op when the value is unchanged so we don't bump UpdatedAt on every turn.
func (*Store) SetWorkDirs ¶ added in v0.22.0
SetWorkDirs updates the per-session working directories and current directory.
func (*Store) TakePendingCriticFeedback ¶ added in v0.32.50
func (s *Store) TakePendingCriticFeedback(id string) (PendingCriticFeedback, error)
TakePendingCriticFeedback atomically reads and clears the pending feedback on the session's critic. Returns an empty PendingCriticFeedback when no critic is configured or no feedback is queued. Used by the chat handler to drain the async reviewer's output into the next user turn.
func (*Store) TranscriptPath ¶
func (*Store) UpdateCriticProgress ¶ added in v0.32.42
func (s *Store) UpdateCriticProgress(id string, mutate func(*SessionCritic) *SessionCritic) (Session, error)
UpdateCriticProgress applies a mutation to the session's critic state. The mutator may return nil to clear runtime state (typically only useful in tests). A no-op when no critic config is present.
func (*Store) UpdateGoalProgress ¶ added in v0.32.41
func (s *Store) UpdateGoalProgress(id string, mutate func(*SessionGoal) *SessionGoal) (Session, error)
UpdateGoalProgress applies a mutation to the session's goal (e.g. to bump AutoContinueCount or change Status). If the mutator returns nil the goal is cleared. If no goal is present the call is a no-op.
func (*Store) WorkspaceDir ¶
type Task ¶ added in v0.20.0
type Task struct {
ID string `json:"id"`
Title string `json:"title"`
Status string `json:"status"` // pending, in_progress, completed, cancelled
Description string `json:"description,omitempty"`
Evidence []TaskEvidence `json:"evidence,omitempty"`
// RunID, when set, names the agentruntime run that is (or was) executing
// this task. Set when the run is spawned with a task_id; read-only
// metadata for UI consumers that want to navigate from a task to the
// run that worked on it.
RunID string `json:"run_id,omitempty"`
}
Task represents a single work item linked to the session plan.
type TaskContract ¶ added in v0.31.98
type TaskContract struct {
Goal string `json:"goal,omitempty"`
Scope string `json:"scope,omitempty"`
DoneCriteria []string `json:"done_criteria,omitempty"`
VerificationCommands []string `json:"verification_commands,omitempty"`
Artifacts []string `json:"artifacts,omitempty"`
ProofPolicy *TaskProofPolicy `json:"proof_policy,omitempty"`
Status string `json:"status,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
}
TaskContract makes the implicit work agreement explicit for a session plan. It is stored next to the active plan/tasks so reload, compaction, and archive flows can keep success criteria attached to the work rather than only in chat.
type TaskEvidence ¶ added in v0.31.100
type TaskEvidence struct {
ID string `json:"id"`
Type string `json:"type"`
Title string `json:"title,omitempty"`
Summary string `json:"summary,omitempty"`
URL string `json:"url,omitempty"`
Command string `json:"command,omitempty"`
Path string `json:"path,omitempty"`
Status string `json:"status,omitempty"`
ProofState string `json:"proof_state,omitempty"`
ProofOrigin string `json:"proof_origin,omitempty"`
ReporterID string `json:"reporter_id,omitempty"`
VerifierID string `json:"verifier_id,omitempty"`
Verifier string `json:"verifier,omitempty"`
EnvironmentJSON json.RawMessage `json:"environment,omitempty"`
InputJSON json.RawMessage `json:"input,omitempty"`
ArtifactDigestsJSON json.RawMessage `json:"artifact_digests,omitempty"`
SubjectDigest string `json:"subject_digest,omitempty"`
Rationale string `json:"rationale,omitempty"`
ObservedAt string `json:"observed_at,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
}
type TaskProofPolicy ¶ added in v0.35.0
type TaskProofPolicy struct {
Required bool `json:"required"`
Verifier string `json:"verifier,omitempty"`
FailureState string `json:"failure_state,omitempty"`
AllowLLMFallback bool `json:"allow_llm_fallback,omitempty"`
MaxLLMTokens int64 `json:"max_llm_tokens,omitempty"`
MaxLLMCostUSD float64 `json:"max_llm_cost_usd,omitempty"`
}