agent

package
v1.261022.2 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MPL-2.0 Imports: 18 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

Index

Constants

View Source
const (
	// AgentTypeClaudeCode represents Claude Code agent
	AgentTypeClaudeCode = aiagent.AgentTypeClaudeCode

	// AgentTypeOpenCode represents OpenCode IDE extension
	AgentTypeOpenCode = aiagent.AgentTypeOpenCode

	// AgentTypeCodex represents the OpenAI Codex CLI
	AgentTypeCodex = aiagent.AgentTypeCodex

	// AgentTypeDsh represents the DeepSeek Harness CLI
	AgentTypeDsh = aiagent.AgentTypeDsh
)

Re-export constants for backward compatibility

View Source
const DefaultClaudeCodeCoAuthoredBy = false

DefaultClaudeCodeCoAuthoredBy is Tingly's default for crediting Claude in commits and PRs. Unlike Claude Code's own default (on), tb leaves the Co-Authored-By trailer out unless the user turns it on.

View Source
const DefaultClaudeCodeDefaultMode = "acceptEdits"
View Source
const DefaultClaudeCodeShowThinkingSummaries = true

DefaultClaudeCodeShowThinkingSummaries mirrors Claude Code's own built-in default for the top-level showThinkingSummaries setting.

Variables

View Source
var (
	// ParseAgentType parses an agent type string, supporting aliases
	ParseAgentType = aiagent.ParseAgentType

	// ListAgentInfo returns information about all supported agent types
	ListAgentInfo = aiagent.ListAgentInfo

	// GetAgentInfo returns information about a specific agent type
	GetAgentInfo = aiagent.GetAgentInfo
)

Re-export functions for backward compatibility

View Source
var ClaudeCodeRequestModels = []string{
	"tingly/cc",
	"tingly/cc-haiku",
	"tingly/cc-sonnet",
	"tingly/cc-opus",
	"tingly/cc-default",
	"tingly/cc-subagent",
	"tingly/cc-fable",
}

ClaudeCodeRequestModels defines all request models for Claude Code scenario When applying claude-code agent, all these rules should be updated for convenience

View Source
var ClaudeCodeTierAliases = []string{"opus", "sonnet", "haiku", "fable"}

ClaudeCodeTierAliases are the --model aliases Claude Code maps to a tier env var. The default tier ("", no --model) is ANTHROPIC_MODEL.

View Source
var CodexRequestModels = []string{
	"tingly-codex",
}

CodexRequestModels defines the default request models for the Codex scenario. Users typically add additional rules with their own request_model names; this list only seeds the default rule when none exists yet.

View Source
var DshRequestModels = []string{
	"tingly-dsh",
}

DshRequestModels defines the default request models for the dsh scenario. Users typically add additional rules with their own request_model names; this list only seeds the default rule when none exists yet.

View Source
var OpenCodeRequestModels = []string{
	"tingly-opencode",
}

OpenCodeRequestModels defines all request models for OpenCode scenario

Functions

func BuildCCProfileSettings added in v0.260625.1

func BuildCCProfileSettings(profileID, scenarioPath, profileName string, env map[string]string, opts ...serverconfig.ApplyOption) (string, error)

BuildCCProfileSettings materializes one derived Claude Code profile under ~/.tingly-box/claude/. The local/default profile lives at default/, while a named profile lives at <profileID>--<profileName>/ so both its stable identity and human name are visible without aliases or platform-specific links.

Config remains the source of truth. The directory contains only rebuildable runtime artifacts: settings.json and its statusline.sh wrapper.

func BuildClaudeCodeModelConfig added in v0.260514.1

func BuildClaudeCodeModelConfig(unified bool) aiagent.ClaudeCodeModelConfig

BuildClaudeCodeModelConfig constructs the model configuration for Claude Code. This contains the business logic for unified vs separate mode. Exported for use by HTTP handlers.

func BuildOpenCodeConfig added in v0.260514.1

func BuildOpenCodeConfig(configBaseURL, apiKey string, models map[string]interface{}) map[string]interface{}

BuildOpenCodeConfig constructs the OpenCode configuration object. This function contains the business logic for OpenCode config structure.

func BuildOpenCodeModels added in v0.260819.0

func BuildOpenCodeModels(names []string) map[string]interface{}

BuildOpenCodeModels builds the OpenCode provider "models" map from a list of request-model names, declaring each as attachment/vision-capable (see openCodeModelEntry). An empty list falls back to the single default model "tingly-opencode" so a fresh setup with no routing rules yet still gets a usable config.

func CCProfileSettingsPath added in v0.260723.1

func CCProfileSettingsPath(profileID, profileName string) (string, error)

CCProfileSettingsPath derives the canonical generated settings path from current profile metadata. The path is never persisted; callers recompute it so profile renames and legacy-name fallbacks cannot leave stale locations.

func CollectCodexModels added in v0.260514.1

func CollectCodexModels(rules []string) []string

CollectCodexModels deduplicates and preserves order of model names. This helper processes routing rules to extract unique model names.

func DiffCCProfileConfig added in v0.260723.1

func DiffCCProfileConfig(base ClaudeCodePrefs, inheritedDefaultMode string, desired ClaudeCodePrefs, desiredDefaultMode string) (*typ.ClaudeCodeProfileConfig, error)

DiffCCProfileConfig stores a minimal, stable delta between the profile base and the full desired typed configuration submitted by the editor.

func GenerateCCEnv added in v0.260625.1

func GenerateCCEnv(cfg *serverconfig.Config, baseURL, apiKey, scenarioPath string, unified, isProfile bool) map[string]string

GenerateCCEnv builds the env map for Claude Code settings.json.

scenarioPath is "claude_code" for the main scenario or "claude_code:p1" for a profile. isProfile=true → tier models resolved from profile-scoped built-in UUIDs; isProfile=false → resolved from main-scenario built-in UUIDs (with legacy-UUID fallback for pre-migration configs).

Reading the rule's request_model (instead of assuming the seeded name) keeps the env aligned when a user renames a rule's model; the seeded name is the fallback when the rule is missing or inactive.

func InspectCCProfileSettings added in v0.260723.1

func InspectCCProfileSettings(profileID, profileName string) (string, bool, error)

InspectCCProfileSettings derives the canonical path and reports whether the generated settings file currently exists as a regular file.

func MaterializeCCProfileSettings added in v0.260723.1

func MaterializeCCProfileSettings(cfg *serverconfig.Config, baseURL, apiKey, scenarioPath string, profile typ.ProfileMeta) (string, error)

MaterializeCCProfileSettings resolves and writes one named profile using its persisted override delta. It is the shared path for HTTP mutations and CLI launch, preventing either surface from generating a different artifact.

func NormalizeClaudeCodeCoAuthoredBy added in v1.261022.2

func NormalizeClaudeCodeCoAuthoredBy(v *bool) bool

NormalizeClaudeCodeCoAuthoredBy applies the Tingly default (off) when the settings file has never said, and passes an explicit value through.

func NormalizeClaudeCodeDefaultMode added in v0.260723.1

func NormalizeClaudeCodeDefaultMode(mode string) (string, bool)

NormalizeClaudeCodeDefaultMode applies the Tingly default for an empty value and rejects values Claude Code does not recognize.

func NormalizeClaudeCodeShowThinkingSummaries added in v0.260819.0

func NormalizeClaudeCodeShowThinkingSummaries(v *bool) bool

NormalizeClaudeCodeShowThinkingSummaries applies the Tingly default when the setting has never been written (nil), and passes an explicit value through unchanged.

func ReadClaudeCodeSettingsEnv added in v1.261001.1

func ReadClaudeCodeSettingsEnv(path string) (map[string]string, error)

ReadClaudeCodeSettingsEnv returns the env block of a Claude Code settings file (a profile's materialized settings.json).

func RemoveCCProfileArtifacts added in v0.260716.1

func RemoveCCProfileArtifacts(profileID, profileName string) error

RemoveCCProfileArtifacts removes only files generated by Tingly-Box for the selected profile. If users added anything else to the directory, it is left in place rather than recursively deleted.

func RemoveRenamedCCProfileArtifacts added in v0.260716.1

func RemoveRenamedCCProfileArtifacts(profileID, oldName, newName string) error

RemoveRenamedCCProfileArtifacts removes the old derived directory after the new one has been materialized. os.SameFile protects case-only renames on case-insensitive filesystems, where both spellings identify the same path.

Types

type AgentApply

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

AgentApply handles agent configuration with routing rules (Tingly-Box specific)

func NewAgentApply

func NewAgentApply(cfg *serverconfig.Config, host string) *AgentApply

NewAgentApply creates a new AgentApply instance

func (*AgentApply) ApplyAgent

func (aa *AgentApply) ApplyAgent(req *ApplyAgentRequest) (*ApplyAgentResult, error)

ApplyAgent applies configuration including routing rules This is the main entry point for Tingly-Box agent configuration

func (*AgentApply) RestoreAgent added in v0.260507.1

func (aa *AgentApply) RestoreAgent(req *RestoreAgentRequest) (*RestoreAgentResult, error)

RestoreAgent restores configuration files from backup

type AgentInfo

type AgentInfo = aiagent.AgentInfo

AgentInfo provides information about an agent type

type AgentType

type AgentType = aiagent.AgentType

AgentType represents the type of AI agent to configure

type ApplyAgentRequest

type ApplyAgentRequest = aiagent.ApplyAgentRequest

ApplyAgentRequest represents a request to apply agent configuration

type ApplyAgentResult

type ApplyAgentResult = aiagent.ApplyAgentResult

ApplyAgentResult represents the result of applying agent configuration

type CCProfileSettingsResolution added in v0.260723.1

type CCProfileSettingsResolution struct {
	BasePreferences      ClaudeCodePrefs
	EffectivePreferences ClaudeCodePrefs
	InheritedDefaultMode string
	EffectiveDefaultMode string
	Env                  map[string]string
	HasOverrides         bool
}

CCProfileSettingsResolution contains both the inherited profile base and the effective result after persistent overrides. Env includes server-owned keys and is ready to materialize; the preference fields are safe for API output.

func ResolveCCProfileSettings added in v0.260723.1

func ResolveCCProfileSettings(cfg *serverconfig.Config, baseURL, apiKey, scenarioPath string, profile typ.ProfileMeta) (CCProfileSettingsResolution, error)

ResolveCCProfileSettings composes main settings, rule-derived profile model slots, stored runtime overrides, and protected connection values in that order. Legacy stored model-slot overrides are ignored.

type ClaudeCodePrefs added in v0.260531.1

type ClaudeCodePrefs struct {
	// Model routing
	AnthropicModel              string `json:"ANTHROPIC_MODEL,omitempty"`
	AnthropicDefaultHaikuModel  string `json:"ANTHROPIC_DEFAULT_HAIKU_MODEL,omitempty"`
	AnthropicDefaultSonnetModel string `json:"ANTHROPIC_DEFAULT_SONNET_MODEL,omitempty"`
	AnthropicDefaultOpusModel   string `json:"ANTHROPIC_DEFAULT_OPUS_MODEL,omitempty"`
	AnthropicDefaultFableModel  string `json:"ANTHROPIC_DEFAULT_FABLE_MODEL,omitempty"`
	ClaudeCodeSubagentModel     string `json:"CLAUDE_CODE_SUBAGENT_MODEL,omitempty"`

	// Limits — kept as strings so empty = omit (avoids the "0 means unset"
	// ambiguity that a *int would force callers to deal with).
	APITimeoutMs              string `json:"API_TIMEOUT_MS,omitempty"`
	ClaudeCodeMaxOutputTokens string `json:"CLAUDE_CODE_MAX_OUTPUT_TOKENS,omitempty"`
	MaxThinkingTokens         string `json:"MAX_THINKING_TOKENS,omitempty"`
	BashDefaultTimeoutMs      string `json:"BASH_DEFAULT_TIMEOUT_MS,omitempty"`
	BashMaxTimeoutMs          string `json:"BASH_MAX_TIMEOUT_MS,omitempty"`
	McpTimeout                string `json:"MCP_TIMEOUT,omitempty"`
	McpToolTimeout            string `json:"MCP_TOOL_TIMEOUT,omitempty"`
	MaxMcpOutputTokens        string `json:"MAX_MCP_OUTPUT_TOKENS,omitempty"`

	// Subagent concurrency — how many subagents Claude Code runs at once and
	// how it handles long-running or stalled background work. Names verified
	// against the Claude Code 2.1.289 binary.
	ClaudeCodeMaxConcurrentSubagents  string `json:"CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS,omitempty"`
	ClaudeCodeAutoBackgroundTimeoutMs string `json:"CLAUDE_CODE_AUTO_BACKGROUND_TIMEOUT_MS,omitempty"`
	ClaudeAutoBackgroundTasks         string `json:"CLAUDE_AUTO_BACKGROUND_TASKS,omitempty"`
	ClaudeAsyncAgentStallTimeoutMs    string `json:"CLAUDE_ASYNC_AGENT_STALL_TIMEOUT_MS,omitempty"`

	// Auto-compact settings — control context window compaction
	ClaudeCodeAutoCompactWindow  string `json:"CLAUDE_CODE_AUTO_COMPACT_WINDOW,omitempty"`
	ClaudeAutocompactPctOverride string `json:"CLAUDE_AUTOCOMPACT_PCT_OVERRIDE,omitempty"`

	// Privacy / behavior switches — "1" to enable, "" to omit.
	DisableTelemetry                     string `json:"DISABLE_TELEMETRY,omitempty"`
	DisableErrorReporting                string `json:"DISABLE_ERROR_REPORTING,omitempty"`
	ClaudeCodeDisableNonessentialTraffic string `json:"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC,omitempty"`
	DisableAutoupdater                   string `json:"DISABLE_AUTOUPDATER,omitempty"`
	UseBuiltinRipgrep                    string `json:"USE_BUILTIN_RIPGREP,omitempty"`

	// Network proxy. Backend accepts these; the current UI does not surface
	// them (too niche for the form, and they overlap with system-level proxy
	// settings managed elsewhere). Wire them up if/when a user asks.
	HTTPProxy  string `json:"HTTP_PROXY,omitempty"`
	HTTPSProxy string `json:"HTTPS_PROXY,omitempty"`
	NoProxy    string `json:"NO_PROXY,omitempty"`

	// Extra is an escape hatch for env vars not modeled above. Merged in
	// after marshaling; values here override the typed fields if keys collide.
	Extra map[string]string `json:"-"`
}

ClaudeCodePrefs is the user-tunable surface of Claude Code's env config. JSON tags map 1:1 to the env var names Claude Code reads, so marshaling produces exactly what should go under "env" in ~/.claude/settings.json. Empty fields are omitted — meaning "don't write this env, let Claude Code fall back to its own default".

func ClaudeCodePrefsFromEnv added in v0.260723.1

func ClaudeCodePrefsFromEnv(env map[string]string) (ClaudeCodePrefs, error)

ClaudeCodePrefsFromEnv selects the typed preference keys from an env map. Unknown and server-owned keys are ignored.

func DefaultClaudeCodePrefs added in v0.260531.1

func DefaultClaudeCodePrefs(unified bool) ClaudeCodePrefs

DefaultClaudeCodePrefs returns tb's canonical defaults for the given mode. Used by the CLI harness directly and as the seed value for the GUI quick-config form when no user customization exists yet.

func (ClaudeCodePrefs) ToEnv added in v0.260531.1

func (p ClaudeCodePrefs) ToEnv(baseURL, apiKey string) (map[string]string, error)

ToEnv materializes prefs into an env map ready to be written under "env" in settings.json. baseURL and apiKey are sourced from the server context (not from prefs) and are always injected.

func (ClaudeCodePrefs) Values added in v0.260723.1

func (p ClaudeCodePrefs) Values() (map[string]string, error)

Values returns only the typed, user-tunable env values. Unlike ToEnv it does not inject server-owned connection values.

type ClaudeCodeSettingsSnapshot added in v0.260723.1

type ClaudeCodeSettingsSnapshot struct {
	Exists                bool
	Env                   map[string]string
	DefaultMode           string
	StatusLine            bool
	ShowThinkingSummaries *bool
	// CoAuthoredBy is whether Claude credits itself in commits; nil when the
	// file sets neither attribution nor includeCoAuthoredBy.
	CoAuthoredBy *bool
}

ClaudeCodeSettingsSnapshot is the relevant subset of a Claude Code settings file. Env may contain keys outside the typed preference surface; callers that expose data through the API must convert it with ClaudeCodePrefsFromEnv.

func ReadMainClaudeCodeSettings added in v0.260723.1

func ReadMainClaudeCodeSettings() (ClaudeCodeSettingsSnapshot, error)

ReadMainClaudeCodeSettings reads the user's source-of-truth settings file.

type ClaudeCodeTier added in v1.261001.1

type ClaudeCodeTier struct {
	Alias string
	Model string
}

ClaudeCodeTier is one model Claude Code can be asked for: the alias passed as --model ("" for the default) and the gateway model id it requests.

type ClaudeCodeTiers added in v1.261001.1

type ClaudeCodeTiers struct {
	Unified bool
	Tiers   []ClaudeCodeTier
}

ClaudeCodeTiers is what a Claude Code env offers. Unified means every tier requests the same model; Tiers then holds just the default.

func ClaudeCodeTiersFromEnv added in v1.261001.1

func ClaudeCodeTiersFromEnv(env map[string]string) ClaudeCodeTiers

ClaudeCodeTiersFromEnv reads the tiers from the env Claude Code is given (GenerateCCEnv's output, the main env or a profile's settings file), so they are exactly what the process will request. The "[1m]" marker is dropped: Claude Code strips it before sending, so the gateway never sees it.

type RestoreAgentRequest added in v0.260507.1

type RestoreAgentRequest = aiagent.RestoreAgentRequest

RestoreAgentRequest represents a request to restore agent configuration

type RestoreAgentResult added in v0.260507.1

type RestoreAgentResult = aiagent.RestoreAgentResult

RestoreAgentResult represents the result of restoring agent configuration

Jump to

Keyboard shortcuts

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