prompt

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const MaxNoteContentLen = 80

MaxNoteContentLen 笔记内容最大长度(rune),供 tool handler 参考 ~80 chars ≈ 40 tokens,对中文约40个汉字

Variables

View Source
var GetCurrentSessionID = session.GetCurrentSessionID

Functions

func BuildNotePrompt

func BuildNotePrompt(ctx context.Context) string

BuildNotePrompt 从近期笔记构建记忆线索提示词

func FormatTime

func FormatTime(t time.Time) string

FormatTime 格式化时间为简短形式

func GetDefaultPromptTemplate

func GetDefaultPromptTemplate(role string) string

GetDefaultPromptTemplate 获取内嵌的默认提示词模板 role: dev, expert, review

func GetPromptPath

func GetPromptPath(role string, global bool) (string, error)

GetPromptPath 获取提示词文件路径 global: true表示全局配置,false表示项目配置

func GetPromptSourceContent

func GetPromptSourceContent(name string, global bool) string

GetPromptSourceContent 获取用于初始化新提示词文件的种子内容。 非 global 作用域(项目):先尝试全局文件,再尝试内建模板。 global 作用域:只尝试内建模板(已知内建名才返回内容)。 无可用来源时返回空字符串,调用方创建空文件。

func GetPromptTemplate

func GetPromptTemplate(ctx context.Context, role string) string

GetPromptTemplate 获取当前生效的提示词模板 优先级:项目配置(.dscli/prompt/) > 全局配置 > 内嵌默认模板 GetPromptTemplate 获取当前生效的提示词模板。 优先级:项目配置(.dscli/prompt/) > 全局配置 > 内嵌默认模板。 当数据库中存在 role→prompt 映射时,使用映射后的 prompt 名称加载模板;

func GetSystemPrompt

func GetSystemPrompt(ctx context.Context) string

GetSystemPrompt 获取增强的系统提示词

func HandleNote

func HandleNote(ctx context.Context, content string) (result, warning string, err error)

func HandleRecall

func HandleRecall(ctx context.Context, keywordsStr string, days, limit int) (result, warning string, err error)

func HandleRecent

func HandleRecent(ctx context.Context, limit int, startID int64) (result, warning string, err error)

HandleRecent 格式化最近消息为表格,供 LLM 工具调用。

func HandleShow

func HandleShow(ctx context.Context, id int64) (result, warning string, err error)

HandleShow 根据消息 ID 返回完整内容(跳过 reasoning_content),供 LLM 工具调用。

func JudgeHistory

func JudgeHistory(messages []*Message)

JudgeHistory - Cleanup the history

func RenderPromptForRole

func RenderPromptForRole(ctx context.Context, role string) string

RenderPromptForRole renders the system prompt for a specific role (expert/review/dev) without requiring the role to be set in the context. This is useful for tool call handlers that need a one-shot prompt for a given role, such as ask_expert (role="expert") and code_review (role="review").

func ResolvePromptEditPath

func ResolvePromptEditPath(name string) (string, error)

ResolvePromptEditPath 确定编辑提示词的目标路径 优先编辑项目级别(若已存在);若不在项目中或文件不存在则使用全局 ResolvePromptEditPath 确定编辑提示词的目标路径 优先编辑项目级别(若已存在);若不在项目中或文件不存在则使用全局

func ResolvePromptRemovePath

func ResolvePromptRemovePath(name string) (string, error)

ResolvePromptRemovePath 确定删除提示词的目标路径 优先项目级别(若存在),否则全局

func SaveMessages

func SaveMessages(ctx context.Context, msgs ...Message) error

SaveMessages 保存消息,同时同步 FTS5 全文索引。

func SaveNote

func SaveNote(ctx context.Context, content string) error

SaveNote 保存一条对话笔记(限制 MaxNoteContentLen 字以内,超限报错)

func ToSQLNullString

func ToSQLNullString(tcs []ToolCall) (toolCalls sql.NullString)

func ToolCallsID

func ToolCallsID(tcs []ToolCall) string

func Truncate

func Truncate(content string, maxLen int) string

Truncate 截断内容用于预览。 短文本直接返回全文;长文本先清洗非语义词(Unicode 符号、装饰标点),再截断。

func UpdateContent

func UpdateContent(ctx context.Context, id int64, content string) (err error)

UpdateContent update message content

func UpdateHistory

func UpdateHistory(ctx context.Context, id int64) (err error)

UpdateHistory update message session_id to 0

func UpdateToolCalls

func UpdateToolCalls(ctx context.Context, id int64, tcs []ToolCall) (err error)

UpdateToolCalls update message content

Types

type Message

type Message struct {
	ID               int64      `json:"-"`
	SessionID        int64      `json:"-"`
	ModelID          int64      `json:"-"`
	Content          string     `json:"content"` // 始终输出,即使为空字符串
	Role             string     `json:"role"`
	ReasoningContent string     `json:"reasoning_content,omitzero"`
	ToolCalls        []ToolCall `json:"tool_calls,omitzero"`   // 仅当有工具调用时输出
	ToolCallID       string     `json:"tool_call_id,omitzero"` // 仅当 role="tool" 时输出
	CreatedAt        time.Time  `json:"-"`

	OK bool `json:"-"`
	// contains filtered or unexported fields
}

Message 扩展,支持工具调用(注意:Content 字段不再使用 omitempty)

func CleanupReverse

func CleanupReverse(messages []Message) (cleaned []Message)

CleanupReverse - make the messages clean, remove the mistake message

func ListHistory

func ListHistory(ctx context.Context) ([]*Message, error)

ListHistory 加载指定会话的所有历史消息,按时间升序返回

func LoadHistory

func LoadHistory(ctx context.Context) ([]Message, error)

LoadHistory 加载指定会话的所有历史消息,按时间升序返回

func LoadPrompts

func LoadPrompts(ctx context.Context) ([]Message, error)

LoadPrompts loads the system prompt combined with skill and note prompts. Only dev role gets skills and notes; expert/review roles skip them. LoadPrompts loads the system prompt combined with skill and note prompts. Skills are injected according to role config; when no config exists, only dev role gets skills (hardcoded fallback).

func RecentMessages

func RecentMessages(ctx context.Context, limit int, startID int64) ([]Message, error)

RecentMessages 返回当前 session 中最近的用户/助手消息(过滤 tool/tool_calls), 按 created_at 降序排列(最新在顶部)。 startID 默认为 math.MaxInt64(无穷大 = 从最新开始);传具体 ID 实现向前翻页。

func ShowMessage

func ShowMessage(ctx context.Context, id int64) (message *Message, err error)

func (*Message) GetTokens

func (m *Message) GetTokens() int

func (*Message) SetTokens

func (m *Message) SetTokens(tokens int)

type Note

type Note struct {
	ID        int64
	SessionID int64
	Content   string
	CreatedAt time.Time
}

Note 对话笔记,用于跨对话记忆

func LoadNotes

func LoadNotes(ctx context.Context, days int) ([]Note, error)

LoadNotes 加载当前项目最近N天的笔记,最多返回10条

type PromptInfo

type PromptInfo struct {
	Name        string
	Description string
	Source      string // "built-in", "project", "global"
}

PromptInfo 提示词基本信息

func ListPrompts

func ListPrompts() []PromptInfo

ListPrompts 列出所有可用提示词(去重,项目优先 > 全局 > 内嵌)

type Result

type Result struct {
	Message     Message
	ProjectPath string
}

Result 搜索结果

func SearchMessages

func SearchMessages(ctx context.Context, keywords []string, days, limit int) ([]Result, error)

SearchMessages 搜索消息,使用 FTS5 全文搜索(中文分词,按相关性排序)。 只搜索 role=user 和 role=assistant(无tool_calls) 的消息。 仅搜索当前 session(对应当前项目)的消息,避免跨项目回忆。 keywords: 搜索关键词(空格分隔,OR 逻辑,匹配任一即返回)。 days: 搜索最近N天,<=0 表示不限时间。 limit: 返回结果数量上限。

type ToolCall

type ToolCall struct {
	ID       string           `json:"id"`
	Type     string           `json:"type"`
	Function ToolCallFunction `json:"function"`
}

type ToolCallFunction

type ToolCallFunction struct {
	Name      string `json:"name"`
	Arguments string `json:"arguments"` // JSON 字符串
}

Jump to

Keyboard shortcuts

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