store

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 7 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 store 把用户设置和界面状态落到磁盘。

目录由调用方给(桌面包传 mygo 的用户数据目录),所以这个包不依赖 mygo, 测试里给个 t.TempDir() 就能完整跑。

三条约定:

  • 读文件失败(第一次启动没有文件、JSON 损坏)一律当作空,绝不因此 让应用起不来 —— 配置文件坏了可以重建,应用打不开就全完了。
  • 写入先落临时文件再 rename:中途崩掉也不会留下半个 JSON。
  • 有 API key,config.json 用 0600。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Providers []llm.Provider `json:"providers,omitempty"`
	// Active 是当前使用的供应商下标。
	Active int `json:"active,omitempty"`
	// CodeSize 是代码字号,0 表示用默认值。
	CodeSize float32 `json:"codeSize,omitempty"`
	// Split 为 true 时用左右对照视图。
	Split bool `json:"split,omitempty"`
	// Unified 为 true 时用单栏统一视图(默认左右对照)。
	Unified bool `json:"unified,omitempty"`
	// SidebarOff 而不是 SidebarOn:侧栏默认是开的,零值正好表示这个默认。
	SidebarOff bool `json:"sidebarOff,omitempty"`
	// SidebarWidth 是侧栏宽度,0 表示默认值。
	SidebarWidth float32 `json:"sidebarWidth,omitempty"`
	// FilePaneWidth 是主区文件列表栏宽度,0 表示默认值。
	FilePaneWidth float32 `json:"filePaneWidth,omitempty"`
	// ThemeMode 是外观模式偏好:"" 或 "system"(跟随系统)、"light"(浅色模式)、"dark"(暗黑模式)。
	ThemeMode string `json:"themeMode,omitempty"`
	// Locale 是界面语言设定:"" 或 "zh"(简体中文)、"en"(English)。
	Locale string `json:"locale,omitempty"`
	// AppIcon 是应用图标风格:"black"(纯黑曜石)或 "white"(纯白极简)。
	AppIcon string `json:"appIcon,omitempty"`
	// CommitPrompt 是自定义 Git 提交信息提示词,留空使用内置预设。
	CommitPrompt string `json:"commitPrompt,omitempty"`
	// BranchPrompt 是自定义 Git 分支名生成提示词,留空使用内置预设。
	BranchPrompt string `json:"branchPrompt,omitempty"`
	// GraphPreset 是提交拓扑图的配色方案名,留空使用内置默认那一套。
	GraphPreset string `json:"graphPreset,omitempty"`
	// GraphLanesDark / GraphLanesLight 是拓扑图 8 个色号的自定义覆盖
	// ("#rgb" / "#rrggbb" 这样的写法),按明暗各存一份:同一支色落在
	// 深色底和浅色底上的可读性差得很远,用户调的是他当时看的那个外观。
	// 留空、条数不够或写错的条目都表示「这一号还用方案自带的颜色」。
	GraphLanesDark  []string `json:"graphLanesDark,omitempty"`
	GraphLanesLight []string `json:"graphLanesLight,omitempty"`
	// TermFontFamily 是内置终端的字体族,界面上是从一列常见等宽字体里下拉选一个。
	// 手写逗号分隔的候选表也认(用的是 ui.Element.Font 那套写法),用的时候还会
	// 再补一个 monospace 兜底:选了台机器上没装的字体时退到系统等宽,而不是让
	// 引擎换一支比例字体、把终端搞错行。留空表示系统等宽。
	TermFontFamily string `json:"termFontFamily,omitempty"`
	// TermFontSize 是内置终端的字号(DIP),0 表示默认值。
	TermFontSize float32 `json:"termFontSize,omitempty"`
}

Config 是用户设置。

func (Config) EffectiveBranchPrompt

func (c Config) EffectiveBranchPrompt(preset string) string

EffectiveBranchPrompt 返回生效的 Git 分支名生成系统提示词。

func (Config) EffectiveCommitPrompt

func (c Config) EffectiveCommitPrompt(preset string) string

EffectiveCommitPrompt 返回生效的 Git 提交信息生成系统提示词。

func (Config) Provider

func (c Config) Provider() *llm.Provider

Provider 是当前选中的供应商配置。没有配置任何供应商时返回 nil, 此时 StreamExplanation 会走 Anthropic 的环境变量凭证链。

type State

type State struct {
	LastRepo    string   `json:"lastRepo,omitempty"`
	RecentRepos []string `json:"recentRepos,omitempty"`
	OpenRepos   []string `json:"openRepos,omitempty"`
	// Viewed 是「已 review」标记:文件路径 -> 当时的内容指纹。
	Viewed map[string]string `json:"viewed,omitempty"`
	// Drafts 是各仓库的提交信息草稿:仓库根路径 -> 还没提交出去的消息。
	// 消息写到一半切去看别的仓库、或者关掉窗口,回来还应该在。
	Drafts map[string]string `json:"drafts,omitempty"`
}

State 是跟着仓库走的界面状态。

type Store

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

Store 是两份文件(设置、状态)的门面,可被多个 goroutine 同时使用。

func Open

func Open(dir string) *Store

Open 从 dir 读取已有的设置和状态。文件不存在或读不动都当作空, 返回值不会是 nil。dir 为空表示「没有数据目录」:读写都变成空操作, 应用照常能跑,只是这次的改动不会被保存。

func (*Store) AddRecentRepo

func (s *Store) AddRecentRepo(path string)

AddRecentRepo 将 path 记为最近打开的仓库(最新的在最前),并更新 LastRepo。

func (*Store) ClearRecentRepos

func (s *Store) ClearRecentRepos()

ClearRecentRepos 清空最近打开的仓库列表。

func (*Store) Config

func (s *Store) Config() Config

Config 返回设置的副本。

func (*Store) Dir

func (s *Store) Dir() string

Dir 是这个 store 的数据目录。

func (*Store) Provider

func (s *Store) Provider() *llm.Provider

Provider 是当前选中的供应商,没配置就是 nil(走环境变量凭证链)。

func (*Store) Save

func (s *Store) Save() error

Save 把两份文件写回磁盘。

用法是「改完就存」:文件都很小,写一次在毫秒级,不值得为它做脏标记或者 防抖。整段加锁,所以并发调用是安全的(后一次写覆盖前一次,结果一致)。

func (*Store) SetConfig

func (s *Store) SetConfig(c Config)

SetConfig 替换设置。

func (*Store) SetDraft

func (s *Store) SetDraft(repo, msg string)

SetDraft 记下某个仓库的提交信息草稿。msg 为空就把这条删掉 —— 空草稿留在文件里没有任何用处。

func (*Store) SetLastRepo

func (s *Store) SetLastRepo(path string)

SetLastRepo 记住最后打开的仓库,下次启动直接打开。

func (*Store) SetOpenRepos

func (s *Store) SetOpenRepos(paths []string)

SetOpenRepos 记住当前打开的多个项目仓库路径列表。

func (*Store) SetViewed

func (s *Store) SetViewed(m map[string]string)

SetViewed 替换「已 review」标记。

func (*Store) State

func (s *Store) State() State

State 返回状态,Viewed 和 Drafts 都是新的一份 map,改它们不会影响 store。

Jump to

Keyboard shortcuts

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