store

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AgentEventTool = "tool" // 一次工具调用刚结束(说明智能体还在干活)
	AgentEventStop = "stop" // 一轮对话结束了(正常收尾、被中止或出错)
)

汇报事件的种类。

View Source
const (
	StopCompleted = "completed"
	StopAborted   = "aborted"
	StopError     = "error"
	StopOther     = "other"
)

一轮对话的结束状态。其他取值一律记为 StopOther。

View Source
const (
	// AuditRetention 是审计保留时长(180 天)。
	AuditRetention = 180 * 24 * time.Hour
	// AuditCrossReadDedupe 是跨界读取的去重窗口:同一主体 + 范围 30 分钟内只记一条。
	AuditCrossReadDedupe = 30 * time.Minute
)
View Source
const (
	CredentialTokenPrefix = "rm-"
	CredentialTokenBytes  = 32
	CredentialNameMaxLen  = 128
	CredentialNoteMaxLen  = 512
	CredentialMaxCount    = 50
)
View Source
const (
	CredentialMaxTerminalHosts = 100
	CredentialMaxCIDRs         = 50
	CredentialMaxAllowedDirs   = 50
	CredentialMaxAllowedPaths  = termproto.MaxFileRoots
)

凭据终端相关字段的上限。它们只是「防写坏」的结构性边界,不是对模型行为的限制。

View Source
const (
	// MaxDraftImageChars 单张草稿图片正文的长度上限(约 30MB 的原图)。
	MaxDraftImageChars = 40 << 20
	// MaxDraftImagesPerWorkflow 一个工作流同时能存放的草稿图片张数。
	MaxDraftImagesPerWorkflow = 60
	// MaxDraftImageCharsPerWorkflow 一个工作流所有草稿图片正文的总长度上限。
	MaxDraftImageCharsPerWorkflow = 160 << 20
)

草稿图片(云存储)的配额。图片正文是 Base64 文本,所以限额都按文本长度计。

View Source
const (
	GroupMaxMembers    = 12              // 含你
	GroupMaxBodyBytes  = 8 * 1024        // 单条消息
	GroupRatePerMinute = 10              // 每个 Agent 每群
	GroupRatePerHour   = 120             // 每个 Agent 每群
	GroupHopLimit      = 4               // 回复链到这一跳就丢弃
	GroupHopWindow     = 3 * time.Minute // 处理某条 @ 之后多久内发出的消息算回复链
	GroupCoolWindow    = 5 * time.Minute
	GroupCoolThreshold = 12 // 窗口内 Agent→Agent 消息数
	GroupTitleMaxRunes = 80
	// GroupHumanRef 是群里「你」的成员引用与已读读者引用。
	GroupHumanRef = "user"
)

群聊的限额与安全阈值(设计稿 03 §3.3 / §3.4)。

View Source
const (
	// InboxExpireAfter 是未被取走的追加的保留期;超过后标为 expired,不再送达。
	InboxExpireAfter = 7 * 24 * time.Hour
	// InboxMaxReminders 是每条消息最多让 hook 提醒几次。
	InboxMaxReminders = 3
	// InboxRecentWindow 是智能体用 inbox recent=true 找回「最近已确认的追加」时回看多久。
	InboxRecentWindow = 24 * time.Hour
	// InboxListMax 是一次最多返回给 Web 的条数。追加信息在会话页里是对话中的永久气泡(不再是几天后消失的底部提示条),
	// 要能回看整个工作流的历史,所以放宽到 200;超出时保留最近的。
	InboxListMax = 200
	// InboxMaxPending 是同一个工作流里未确认的追加条数上限(防止误操作或脚本无限堆积)。
	InboxMaxPending = 100
	// InboxPreviewRunes 是提示行 / hook 里给出的预览长度。
	InboxPreviewRunes = 160
)
View Source
const (
	InboxViaFeedback = "feedback" // 智能体发起交互时随「秒回」带走
	InboxViaHook     = "hook"     // Cursor hook 提醒后读取
	InboxViaReceipt  = "receipt"  // 工具回执里的 inbox: 提示行提醒后读取
	InboxViaTool     = "tool"     // 智能体自己调用 inbox 读取
)

一条追加是经哪条路径被智能体发现的。

View Source
const (
	NormNameMaxLen    = 128
	NormSummaryMaxLen = 500
	NormContentMaxLen = 20000
	NormMaxCount      = 50
)
View Source
const (
	GlobalSettingsKey  = "app_settings"
	AuthCredentialsKey = "auth_credentials"
)
View Source
const (
	// HeadlessPostureAllowlist(默认):不带 --force,智能体只能做 CLI 自己的 permissions.allow 白名单放行的事
	// (例如 Mcp(relaymesh:*)、Shell(git status));白名单之外的 shell 命令会被拒绝。
	HeadlessPostureAllowlist = "allowlist"
	// HeadlessPostureForce:带 --force,等于放开全部命令;只在你明确接受时使用。
	HeadlessPostureForce = "force"
)

非交互唤醒的权限姿态。

View Source
const (
	// 唤醒记录最多保留这么久、这么多条:它用来算「今天唤醒了几次」和「上次唤醒有没有进展」,不是审计日志。
	GuardWakeKeep    = 7 * 24 * time.Hour
	GuardWakeKeepMax = 20
)
View Source
const (
	GuardProgressYes  = "progress" // 唤醒之后智能体有了新的活动
	GuardProgressNone = "none"     // 观察窗口过完了,仍然没有任何新的活动
)

一次唤醒之后智能体有没有动静(GuardWakeRecord.Progress)。空 = 还没结论(观察窗口没过完)。

View Source
const (
	// AutoResumePending:已排期,到点(Due)开跑;到点前可以取消。
	AutoResumePending = "pending"
	// AutoResumeStarted:已经续跑,RunID 是续跑出来的新运行。
	AutoResumeStarted = "started"
	// AutoResumeStopped:你在到点前取消了这次自动续跑。
	AutoResumeStopped = "stopped"
	// AutoResumeSkipped:这次出事不自动续跑,或到点时条件不满足(你已经重新运行了、预设改了……);Why 写明原因。
	AutoResumeSkipped = "skipped"
	// AutoResumeGaveUp:本该续跑但预算用完、连续没有进展或没法提交,放弃并通知;Why 写明原因。
	AutoResumeGaveUp = "gaveup"
)

非交互运行异常退出后自动续跑(#151,D-260)的登记状态(AutoResumeRecord.State)。

View Source
const (
	// AutoResumeKeep、AutoResumeKeepMax:登记最多保留这么久、这么多条。它用来算「24 小时内续跑了几次」「这一串续跑有没有进展」,
	// 也让界面能说明上一次出事之后发生了什么;不是审计日志。待开跑的登记不受时间限制(到点没跑成会被标成跳过)。
	AutoResumeKeep    = 7 * 24 * time.Hour
	AutoResumeKeepMax = 30
)
View Source
const (
	// LauncherKindTerminal 是默认类型:点「启动」在主机上开一个终端会话并自动输入命令。
	// 旧存档没有 kind 字段,都是这种;存盘时规整成空串。
	LauncherKindTerminal = "terminal"
	// LauncherKindHeadless 是「非交互续聊」(#126):点「运行」经主机的执行通道跑一次
	// `agent -p --resume <对话编号> …`,不开终端;运行配置见 HeadlessRun。
	LauncherKindHeadless = "headless"
)

启动器预设的类型(TerminalLauncher.Kind)。

View Source
const (
	MaxHeadlessPromptRunes = 600
	MaxHeadlessModelRunes  = 64
	MaxHeadlessBinRunes    = 128
	// DefaultHeadlessBin 是没填可执行文件时用的命令名。
	DefaultHeadlessBin = "agent"
)

非交互续聊预设的取值范围(按字符数)。

View Source
const (
	// MinHeadlessRunMinutes 是下限:再短连智能体启动的时间都不够,没有意义。
	MinHeadlessRunMinutes = 1
	// MaxHeadlessRunMinutes 是上限,也是没填时的默认值:平台单次运行上限 7 天。
	// 它与 termproto.MaxRunTimeoutSec 同值(store 不依赖协议包,由 terminal 包的测试守住这一点)。
	MaxHeadlessRunMinutes = 7 * 24 * 60
)

非交互续聊预设「最长运行时间」的取值范围(分钟,#141)。

View Source
const (
	// DefaultAutoResumeOKMinutes 是没填时的默认值:续跑出来的运行连续跑满 10 分钟,就算这次续跑成功。
	DefaultAutoResumeOKMinutes = 10
	// MinAutoResumeOKMinutes 是下限;MaxAutoResumeOKMinutes 是上限(1 天):再长就没有「算成功」的意义了。
	MinAutoResumeOKMinutes = 1
	MaxAutoResumeOKMinutes = 24 * 60
)

自动续跑「成功」判定时长的取值范围(分钟,#172)。

View Source
const (
	MaxTerminalLaunchers    = 20
	MaxLauncherNameRunes    = 40
	MaxLauncherDirRunes     = 512
	MaxLauncherCommandRunes = 1000
)

启动器预设的取值范围(按字符数,不是字节数;中文名字和中文目录同样适用)。

View Source
const (
	DefaultGuardSilenceMinutes = 30
	MinGuardSilenceMinutes     = 5
	MaxGuardSilenceMinutes     = 720
	MaxGuardWorkflowRunes      = 128
	MaxGuardPromptRunes        = 300
)

会话守护(LauncherGuard)的取值范围。静默分钟数的下限防止把「正常思考」当停摆,上限 12 小时。

View Source
const (
	// 固定终端列数(宽度保持):小于 40 列几乎没法用,大于 400 列即使缩到最小字号也放不进手机屏幕。
	MinFixedCols = 40
	MaxFixedCols = 400
	// 单会话记录保留的输出行数上限:小于 5000 行连一屏回看都不够;上限 1000 万行只是防止填错数字,实际受字节配额约束。
	MinRecordMaxLines = 5000
	MaxRecordMaxLines = 10_000_000
)

终端偏好的取值范围;0 一律表示「关闭 / 不限制」。

View Source
const (
	// WebWorkflowFirstMessageMaxRunes 是首条指令的最大字符数。
	WebWorkflowFirstMessageMaxRunes = 20000
	// WebWorkflowProjectDirMaxRunes 是项目目录的最大字符数。
	WebWorkflowProjectDirMaxRunes = 1024
	// WebWorkflowHostNameMaxRunes 是主机名的最大字符数。
	WebWorkflowHostNameMaxRunes = 120
)

「高级选项」各项的长度上限(按字符,不是字节)。

View Source
const (

	// AgentNameMaxRunes 是身份改名的最大长度。
	AgentNameMaxRunes = 80
)
View Source
const (
	// CapabilityTokenPrefix 是能力 URL 凭据令牌的专用前缀:只有这一类凭据使用它,普通凭据不得使用。
	// 固定前缀与固定长度也让服务端能在查库之前就丢弃形状不对的路径,随手乱填的网址不会产生数据库访问。
	CapabilityTokenPrefix = "rmc-"
)
View Source
const ConversationReadEpochKey = "conversation_read_epoch_ms"

ConversationReadEpochKey 是「已读纪元」的设置键:聊天功能上线(第一次用到)的时刻。 纪元之前发的消息一律算已读——否则上线当天每个工作流都会冒出几百条「未读」。

View Source
const DefaultAgentModesContent = `` /* 2911-byte string literal not displayed */
View Source
const DefaultAgentModesSummary = "会话场景模式 playbook(online 值守 / away 安全兜底 / autopilot 外部编排)+ Phase 0-7 开发工作流。"
View Source
const DefaultServerInstructions = `【RelayMesh 智能体协同中枢内生治理指引】
RelayMesh 是本工作区唯一的权威人机交互、多智能体协同与研发生命周期中枢。当连接到 RelayMesh 时,请严格遵循以下行为指引:

1. 简体中文自然表达规范:
   - 涉及中文的一切输出(对话、提问、方案、代码变更总结、文档、提交信息与会话记录)默认保持语义流畅、自然通顺、结构清晰,杜绝电报式省略与生硬符号串堆砌。

2. 工程思维与推理纪律(C-PLAN / C-RT):
   - 目标是系统整体质量与长期可维护性,杜绝以「改动最少/最快」为由采取局部最优或临时打补丁方案;
   - 触发门槛:面对「多步 / 跨模块 / 不可逆 / 新建系统 / 影响面大」的任务,编码前必须进行系统性方案推演:
     • C-PLAN:决策确认 → 问题拆解 → 数据流与状态 → 不变量 → 边界与异常 → 影响面 → 备选方案(≥2) → 验收标准;
     • C-RT:反向自检反驳(哪最幼稚?什么输入会崩溃?漏了哪个边界?是否属于局部最优?),命中立即修正;
   - 改前先读代码与架构规范,改动接口与类型时全量检查所有引用方。

3. RelayMesh 交互与沟通主载体契约:
   - 方案提出、提问请示、歧义澄清、阶段汇报与任务最终总结,必须统一通过 RelayMesh 的 interactive_feedback 工具进行,严禁直接在普通 chat 正文提问或等待确认;
   - 核心入参铁律(严禁颠倒/篡改):
     • workflow_id (必填): 必须原样继承本会话法定工作流标识,严禁随意编造新名称或遗漏;
     • title (单行短标题): 仅限 5~15 字概括,严禁将 Markdown 正文放入 title;
     • summary (详尽正文): 必须放入完整的 Markdown 分析、推演、方案或代码汇报,严禁只填一句话短标题;
   - 收到 === 等待回执 === 时,严格按回执指令调用 AwaitShell 等待并随后调用 continue_feedback_session 轮询,等待期间严禁输出 chat 正文、严禁调用其他工具、严禁擅自总结;
   - 收到 === 用户反馈 === 时,方可作为用户的权威输入继续推进。

` + phaseSection + `

` + irreversibleSection + `

6. 场景模式与内置规范(agent-modes):
   - 系统内置 agent-modes 场景模式规范(online 在线值守 / away 安全兜底 / autopilot 外部编排);可通过 manage_skills(action: "get", name: "agent-modes") 获取完整行为准则。

7. 会话状态与文档自适应策略(Workflow Sheet):
   - 为避免上下文压缩丢失目标与关键决策,根据工作区环境自适应选择存储载体:
     • 场景 A:若项目根目录存在 .cursor/sessions/ 规范,按该规范维护本地会话文档;
     • 场景 B:遵守当前项目文档规范(如项目自有 docs/ 规范体系);
     • 场景 C:若项目无本地会话文档体系,统一调用 RelayMesh 内置 workflow_context(action: "session_doc_save", workflow_id: "...", content: "...") 将会话文档与关键决策持久化至中枢工作表(Workflow Sheet),并可通过 workflow_context(action: "session_doc_get") 检索恢复。

8. 上下文获取与跨项目边界隔离(D-165):
   - 主机名 (HostName) 由连接凭据权威锁定,项目目录 (project_directory) 由大模型主动传递;
   - 凡调用 list_sessions 或 workflow_context(action: 'list_workflows') 获取上下文,必须传递 project_directory,系统严格限定在当前 (HostName, ProjectDirectory) 边界内,杜绝跨项目与跨主机污染;
   - 仅当人工明确指定特定 workflow_id 时,才允许跨目录读取该指定工作流的会话历史。

9. 交付锚点(可选,用于定位信息的陈旧性):
   - 项目目录是 git 仓库时,调用 interactive_feedback 可把 git log -1 --format='%h %s' 的单行输出放进 commit 参数,时间由服务端记录;不是 git 仓库时省略;
   - 回执响应头的 anchor 行是本工作流最近一次交付锚点;上下文被重置后,据此用 git log <哈希>..HEAD 与 git status 核对期间发生了什么;
   - 保存恢复胶囊(checkpoint_save)时可省略 basis.git_commit,服务端会取最近一次交付锚点并把胶囊关联到那次交付。`
View Source
const GuardPromptUnsafe = "`$\\;&|<>(){}[]'\"!*?~#"

GuardPromptUnsafe 是唤醒提示词里不允许出现的字符:它们在 shell 里有特殊含义。

提示词本该输入到智能体的对话框;但万一那时 Cursor CLI 已经退出、会话停在普通的命令行里,输入的内容会被 shell 解释。 所以只允许「在 shell 里只是普通文字」的字符——中文标点、字母、数字、空格、% 都没问题。 提示词的开头由服务端固定为「【系统唤醒 …】」,第一个词因此也不会是任何命令。

View Source
const HeadlessOriginEnableAgent = "enable_agent"

HeadlessOriginEnableAgent 是 HeadlessRun.Origin 的取值:这条预设是会话页「启用 Agent」自动建的。

View Source
const HookSeenPersistEvery = time.Minute

HookSeenPersistEvery 是同一个工作流的 hook 时间落库的最小间隔:落库值最多比真实值旧这么久。 重启后恢复出来的值只会偏旧、不会偏新,对 60 分钟的新鲜度窗口可以忽略,方向也是安全的。

View Source
const InboxConfigKey = "inbox_config"

InboxConfigKey 是收件箱开关在 system_settings 表里的键,值是 JSON(见 InboxConfig)。

View Source
const InboxHookSeenBroadcastEvery = time.Minute

InboxHookSeenBroadcastEvery 是 hook 查询触发 Web 刷新的最小间隔:hook 每隔十几秒就会问一次, 没必要每次都让所有打开的页面重新拉取。

View Source
const InboxSessionIDPrefix = "inbox-"

InboxSessionIDPrefix:收件箱里的图片对外用 inbox-<编号> 当作「会话编号」寻址, 这样 get_session_image 与 /sessions/:id/images/:index 不用新增一套接口就能取到追加里的图片。

View Source
const JWTSecretKey = "jwt_secret"

JWTSecretKey 是自动生成的 JWT 签名密钥在 system_settings 表中的键。

安全约束:该键不属于任何对外接口返回的设置集合(GetSettings 只读取 app_settings,标题类查询按 key 前缀过滤), 也不得被列出、导出或写入日志。新增「枚举全部 system_settings」的代码前必须先排除该键。

View Source
const LostDismissalKeepDays = 90

LostDismissalKeepDays:忽略记录保留多久。守护进程自己也会淘汰很久以前的丢失会话, 过了这么久还没从主机的上报里消失的条目极少,宁可让它重新提醒一次,也不让这张表无限增长。

View Source
const MaxSSHHosts = 50

MaxSSHHosts 是可登记的 SSH 主机数量上限:每台主机都可能占用连接与轮询资源,上限防止被灌满。

View Source
const MaxTerminalArchives = 5000

MaxTerminalArchives 是归档记录的总数上限。超过时丢弃最早归档的几条: 代价只是对应的条目重新出现在侧栏里,不会丢任何会话、记录或审计。

View Source
const NotifyPrefsKey = "notify.prefs"

NotifyPrefsKey 是通知偏好在 system_settings 表里的键,值是 JSON(见 notify.Prefs)。 只新增键、不改表结构;旧版本二进制不认识这个键,会直接忽略它。

View Source
const NtfyConfigKey = "ntfy_config"

NtfyConfigKey 是 ntfy 推送配置在 system_settings 表里的键,值是 JSON(见 ntfy.Config,含访问令牌 / 密码)。

它独立于全局设置(GlobalSettingsKey):全局设置会整体返回给浏览器,而这里的凭据只许写、不许读。

View Source
const (
	OAuthClientMax = 200
)
View Source
const RetractionEventsMax = 20

RetractionEventsMax 是历史查询里最多给几条撤回记录(取最近的)。

View Source
const SQLTraceEnv = "RELAYMESH_SQL_TRACE"

SQLTraceEnv 是开启 SQL 追踪的环境变量名(只在实验与排查里用,默认关闭,生产不设)。

设置为一个文件路径后,Store 执行的每一条 SQL 都以一行 JSON 追加写入该文件:开始时间、耗时(毫秒)、行数、报错与 SQL 原文 (绑定值已代入;超过 sqlTraceMaxLen 的部分截断,免得把整段汇报正文写进去)。配套的离线分析工具是 scripts/dev/explain-audit: 把真实页面加载(跑浏览器套件)时发出的 SQL 按「形状」归并、统计次数与耗时,再逐个形状做 EXPLAIN QUERY PLAN,找全表扫描与临时排序(#177)。

注意:文件里是真实数据的片段,只用于临时库;不要对着含真实内容的库长期打开,用完删除。

View Source
const (
	// SettingTerminalExecPaused 为 "1" 时全局暂停一切模型运行(G5 的全局开关,重启后保持)。
	SettingTerminalExecPaused = "terminal_exec_paused"
)

系统开关(system_settings 键值表)里保存的终端相关键。

View Source
const TerminalGuardStateKey = "terminal_guard_state"

TerminalGuardStateKey 是守护状态在 system_settings 表里的键,值是 JSON(见 GuardStateDoc)。

View Source
const TerminalLaunchersKey = "terminal_launchers"

TerminalLaunchersKey 是启动器预设在 system_settings 表里的键,值是 JSON(见 terminalLauncherDoc)。

View Source
const TerminalPrefsKey = "terminal_prefs"

TerminalPrefsKey 是终端偏好在 system_settings 表里的键,值是 JSON(见 TerminalPrefs)。

View Source
const TypingFreshness = 10 * time.Second

TypingFreshness 超过这个间隔没有新的心跳就算停手了。

View Source
const WebPlaceholderSessionPrefix = "sess-web-"

WebPlaceholderSessionPrefix 是网页新建会话时占位会话行的编号前缀。

View Source
const WebWorkflowTitleMaxRunes = 80

WebWorkflowTitleMaxRunes 是网页新建会话时名字的最大字符数(按字符,不是字节)。

View Source
const WorkflowUpdatesMax = 100

WorkflowUpdatesMax 是一次最多返回的进展条数:会话里只看最近的,更早的去任务页看。

Variables

View Source
var (
	// ErrInvalidLauncher 表示预设的某个字段不合法;错误信息可以直接展示给用户。
	ErrInvalidLauncher = errors.New("终端启动预设不合法")
	// ErrLauncherLimit 表示预设数量已到上限,不能再新增(修改已有的不受影响)。
	ErrLauncherLimit = errors.New("终端启动预设数量已到上限")
	// ErrLauncherNotFound 表示要删除的预设不存在(可能已在别的浏览器里删掉了)。
	ErrLauncherNotFound = errors.New("终端启动预设不存在")
)
View Source
var ErrInvalidTerminalPrefs = errors.New("终端偏好取值不合法")

ErrInvalidTerminalPrefs 表示偏好的取值超出范围;错误信息可以直接展示给用户。

View Source
var ErrSSHHostLimit = errors.New("ssh host limit reached")

ErrSSHHostLimit 表示 SSH 主机数量已达上限。

View Source
var ErrTerminalHostExists = errors.New("terminal host already exists")

ErrTerminalHostExists 表示该机器码已存在记录(同一公钥)。

View Source
var ErrTerminalHostNotFound = errors.New("terminal host not found")

ErrTerminalHostNotFound 表示记录不存在。

View Source
var ErrTerminalKeyMismatch = errors.New("terminal host public key mismatch")

ErrTerminalKeyMismatch 表示同一机器码对应的已存公钥与传入公钥不一致(不应发生,发生即拒绝)。

Functions

func BackfillPhasePrompts

func BackfillPhasePrompts(phases []model.PhaseItem)

BackfillPhasePrompts fills in missing Prompt fields from DefaultPhaseTemplate.

func ClaimStateLabel

func ClaimStateLabel(state string) string

ClaimStateLabel 是接取状态的中文名;空串 = 未指派。

func ClassifyLauncherExec

func ClassifyLauncherExec(command string) (execLine string, err error)

ClassifyLauncherExec 判断启动命令能否用 exec 启动;可以时返回包装后的 exec 片段(不含 cd)。

func CredentialFilesError

func CredentialFilesError(c *model.MCPCredential) error

CredentialFilesError 在凭据打开了文件权限位却没有任何访问范围时返回错误。 文件权限没有「默认全部可访问」的含义:既不指定目录、也没有明确开启「允许整个文件系统」,就等于没有范围, 不允许保存这样的组合。「允许整个文件系统」只能由 allow_whole_fs 显式打开——在 allowed_paths 里写 `/` 仍然被拒绝(见 NormalizeAllowedPaths),免得一个手误就等于不设防。

func CredentialTerminalTokenError

func CredentialTerminalTokenError(c *model.MCPCredential) error

CredentialTerminalTokenError 在凭据带终端权限(或「运行预设」权限)而令牌强度不足时返回错误。 终端权限等价于远程代码执行,「运行预设」让一个智能体去唤醒另一个智能体(#179),令牌都必须不可猜;服务端自动生成的令牌始终合格。

func DraftReferencedKeys

func DraftReferencedKeys(draftsJSON string) map[string]struct{}

DraftReferencedKeys 解析草稿 JSON,返回它引用的全部图片内容键(解析失败按「没有引用」处理)。

func GenerateCapabilityToken

func GenerateCapabilityToken() (string, error)

GenerateCapabilityToken 生成能力 URL 凭据的令牌:专用前缀 + 32 字节随机数的十六进制。

func GenerateHiddenCredentialToken

func GenerateHiddenCredentialToken() (string, error)

GenerateHiddenCredentialToken 生成隐藏 OAuth 凭据的内部占位令牌(高熵、永不对外返回、不可作 MCP Bearer)。

func GenerateToken

func GenerateToken() (string, error)

func GroupErrorCode

func GroupErrorCode(err error) (code string, ok bool)

GroupErrorCode 取出错误里的群聊错误码;不是群聊错误时 ok 为 false。

func HashOAuthToken

func HashOAuthToken(plain string) string

func HostDefaultState

func HostDefaultState(v string) string

HostDefaultState 把库里的默认态归一成 allow / deny(空串等价于 deny)。

func InboxPreview

func InboxPreview(q model.QueuedFeedback) string

InboxPreview 是一条追加的单行预览:折叠空白、截断到 InboxPreviewRunes 个字符;只有图片时注明张数。 智能体在回执里看到的正文就是 ResponseText(快捷标签只用于界面展示),所以预览也以它为准,没有正文时才退回到标签。

func InboxSessionID

func InboxSessionID(queuedID uint) string

InboxSessionID 把追加编号变成对外的图片寻址编号。

func IsCapabilityTokenShape

func IsCapabilityTokenShape(s string) bool

IsCapabilityTokenShape 判断字符串是否具有能力 URL 令牌的形状(前缀 + 64 位小写十六进制)。 它只是廉价的形状检查,不代表令牌有效。

func IsHeadlessPrefixCmd

func IsHeadlessPrefixCmd(word string) bool

IsHeadlessPrefixCmd 判断一个词是不是 shell 内建或会改变后面命令含义的前缀命令(cd、env、sudo、bash……): 非交互运行的第一个词必须是可执行文件本身,不能是它们。

func IsWebPlaceholderSessionID

func IsWebPlaceholderSessionID(sessionID string) bool

IsWebPlaceholderSessionID 判断一个会话编号是不是网页新建会话时落下的占位行。

func MaskToken

func MaskToken(token string) string

func NormalizeAllowedCIDRs

func NormalizeAllowedCIDRs(in []string) (model.StringList, error)

NormalizeAllowedCIDRs 校验来源白名单;每项可以是 CIDR 或单个 IP,单个 IP 保持原样。

func NormalizeAllowedPaths

func NormalizeAllowedPaths(in []string) ([]string, error)

NormalizeAllowedPaths 校验并归一化文件工具的允许目录:去空白、去重、限条数与长度,写法必须是明确的绝对路径 (见 termproto.RootProblem)。文件系统根目录、相对路径、含 .. 的写法一律拒绝——这是一条强制的访问边界, 不接受含糊的写法。

func NormalizeConfirmOptions

func NormalizeConfirmOptions(in []model.ConfirmOption) ([]model.ConfirmOption, error)

NormalizeConfirmOptions 校验并规整选项:2~8 个,id 非空唯一,文案非空,各字段限长。

func NormalizeModulePath

func NormalizeModulePath(p string) (string, error)

NormalizeModulePath 规整模块路径:用 / 分隔、最多 8 层、每层 ≤ 64 个字符,不允许 . / .. 段与路径里的危险字符。

func NormalizeReplyHash

func NormalizeReplyHash(raw string) string

NormalizeReplyHash 把用户写的哈希整理成小写十六进制:容忍大小写、前后空白和多写的 sess- 前缀; 不合法(太短、太长、含非十六进制字符)返回空串。这也保证了拼进 LIKE 的内容里没有通配符。

func NormalizeTerminalHosts

func NormalizeTerminalHosts(in []string) (model.StringList, error)

NormalizeTerminalHosts 去重、裁剪并校验机器码列表;包含 "*" 时折叠为 ["*"]。

func NormalizeWebFirstMessage

func NormalizeWebFirstMessage(raw string) (string, error)

NormalizeWebFirstMessage 规整网页新建会话时写的首条指令:去首尾空白(正文里的换行原样保留);空串表示没有首条指令; 含 NUL 或超过 WebWorkflowFirstMessageMaxRunes 个字符的拒绝。

func NormalizeWebHostName

func NormalizeWebHostName(raw string) (string, error)

NormalizeWebHostName 规整网页新建会话时填的主机名(会话的归属标签):折成单行;空串表示不指定(沿用全局设置 / 环境变量); 超过 WebWorkflowHostNameMaxRunes 个字符的拒绝。

func NormalizeWebPhase

func NormalizeWebPhase(raw string) (string, error)

NormalizeWebPhase 规整网页新建会话时选的起始阶段:空串表示不指定(沿用默认阶段); 只接受 discuss / plan / dev,旧五段式的编号(assess / verify / done)换算成对应的新编号后接受;其它拒绝。

func NormalizeWebProjectDirectory

func NormalizeWebProjectDirectory(raw string) (string, error)

NormalizeWebProjectDirectory 规整网页新建会话时填的项目目录:空串表示不绑定(返回 ""); 否则必须是绝对路径——POSIX 的 /…,Windows 的 X:\… 或 X:/…,以及 \\服务器\共享\…——不含控制字符,不超过 WebWorkflowProjectDirMaxRunes 个字符。

规整只做「不会改变含义」的那部分:POSIX 路径做 path.Clean(多余的 /、. 与 ..、末尾 /);Windows 路径只去掉末尾分隔符 (盘符根 C:\ 保留),不改大小写、不换分隔符。原因:D-161 比较的是字符串,智能体按启动提示词把这个值原样回填,两边才会一致。

func NormalizeWebWorkflowTitle

func NormalizeWebWorkflowTitle(raw string) (string, error)

NormalizeWebWorkflowTitle 规整网页新建会话时填的名字:空白与控制字符(含换行、制表)一律折成一个空格, 不可见的格式字符(零宽空格之类)直接丢掉,去掉首尾空白;规整后为空,或超过 WebWorkflowTitleMaxRunes 个字符的拒绝。

func NormalizeWorkLabels

func NormalizeWorkLabels(in []string) ([]string, error)

NormalizeWorkLabels 去空白、去重(不区分大小写)并校验数量与长度。

func NormalizeWorkRefs

func NormalizeWorkRefs(in []string) ([]string, error)

NormalizeWorkRefs 去空白、去重并校验数量与长度。引用是自由文本:提交(commit:abc1234)、决策(D-201)、文件路径、文档链接都可以。

func ParseBoardKey

func ParseBoardKey(key string) (projectID uint, workflowID string, ok bool)

ParseBoardKey 拆开 board_key:项目板返回 projectID,独立板返回 workflowID;不合法返回 ok=false。

func ParseInboxSessionID

func ParseInboxSessionID(id string) (queuedID uint, ok bool)

ParseInboxSessionID 反过来解析;不是 inbox-<数字> 时 ok 为 false。

func ProjectBoardKey

func ProjectBoardKey(projectID uint) string

ProjectBoardKey 返回项目板的 key。

func SanitizeCredentialUpdates

func SanitizeCredentialUpdates(in map[string]any) (map[string]any, error)

SanitizeCredentialUpdates 校验并归一化 REST 传入的凭据更新,返回可直接交给 GORM 的 map。

func SlugifyProjectName

func SlugifyProjectName(name string) string

SlugifyProjectName 把项目名转成建议的 slug:小写字母数字与连字符;转不出来(比如全是汉字)就返回空串。

func ValidateCredentialTerminal

func ValidateCredentialTerminal(c *model.MCPCredential) error

ValidateCredentialTerminal 校验并就地归一化一条完整凭据的终端相关字段(创建时调用)。

func ValidateHostDefaultForNewModels

func ValidateHostDefaultForNewModels(v string) error

ValidateHostDefaultForNewModels 校验默认态取值:空串或 deny 表示不预先授予,allow 表示预先授予。

func ValidateHostExecMode

func ValidateHostExecMode(v string) error

ValidateHostExecMode 校验主机的执行模式(空串等价于 auto)。

func ValidatePathReference

func ValidatePathReference(ref model.PathReference) error

func ValidatePathReferences

func ValidatePathReferences(refs []model.PathReference) error

func ValidateSegments

func ValidateSegments(segments []model.Segment) error

func ValidateTerminalLimits

func ValidateTerminalLimits(l model.TerminalLimits) (model.TerminalLimits, error)

ValidateTerminalLimits 校验令牌级限额(全部为零表示不设限,合法)。 AllowWholeFS 开启时 AllowedPaths 照常校验并保留(关闭开关后恢复为目录限制,永远不会比管理员显式配置的更宽), 但它们不起作用,运行时一律以 AllowWholeFS 为准。

func ValidateTerminalModeCap

func ValidateTerminalModeCap(v string) error

ValidateTerminalModeCap 校验令牌的执行模式上限。

func WebWorkflowStartPrompt

func WebWorkflowStartPrompt(title, workflowID, projectDir string) string

WebWorkflowStartPrompt 是交给用户、由用户转发给智能体的「启动提示词」。 关键信息只有三条:带上这个 workflow_id、目录填自己当前的工作区(用户在「高级选项」里绑定了项目目录时,改成原样填那个目录, 否则 D-161 会把它挡在门外)、接入后先取用户留下的第一条指令(回执里带回来的,或收件箱里的)。projectDir 为空 = 没绑定。

func WorkItemListLimit

func WorkItemListLimit(requested int) int

WorkItemListLimit 是任务清单一次最多返回多少条:调用方没指定(或指定得不合理、超过 1000)就取默认的 500。 清单按最近更新从新到旧取前这么多条;REST 拿它判断清单是不是被截断了(顶到上限 = 更早更新的可能被略去), 这样页面能如实说明,而不是悄悄少显示。

func WorkStateLabel

func WorkStateLabel(state string) string

WorkStateLabel 返回状态的中文名(与界面一致);未知值原样返回。

func WorkflowBoardKey

func WorkflowBoardKey(workflowID string) string

WorkflowBoardKey 返回工作流独立板的 key。

Types

type AgentEvent

type AgentEvent struct {
	Kind           string
	Status         string
	ConversationID string
}

AgentEvent 是 hook 汇报的一次事件。字段都由调用方自报,入库前统一清洗(见 NormalizeAgentEvent)。

func NormalizeAgentEvent

func NormalizeAgentEvent(ev AgentEvent) (AgentEvent, bool)

NormalizeAgentEvent 清洗 hook 自报的事件:种类只认 tool / stop;状态只认 completed / aborted / error(其余记为 other, 只在 stop 事件里有意义);对话编号只认字母数字、下划线、连字符,最长 64 位,格式不对就当没有。返回 ok=false 表示没有可记的内容。

type AgentIdentityView

type AgentIdentityView struct {
	ID               uint       `json:"id"`
	CredentialID     uint       `json:"credential_id"`
	HostName         string     `json:"host_name"`
	ProjectDirectory string     `json:"project_directory"`
	Name             string     `json:"name"`
	DirectoryName    string     `json:"directory_name"`
	Label            string     `json:"label"`
	LabelDegraded    bool       `json:"label_degraded"`
	ClientKind       string     `json:"client_kind,omitempty"`
	CursorVersion    string     `json:"cursor_version,omitempty"`
	FirstSeenAt      time.Time  `json:"first_seen_at"`
	LastSeenAt       time.Time  `json:"last_seen_at"`
	LastHookAt       *time.Time `json:"last_hook_at,omitempty"`
	LastMCPAt        *time.Time `json:"last_mcp_at,omitempty"`
	LastQueryAt      *time.Time `json:"last_query_at,omitempty"`
}

AgentIdentityView 是对外的身份视图。

type AgentIngestInput

type AgentIngestInput struct {
	WorkflowID       string
	CredentialID     uint
	HostName         string // 连接凭据 / 请求锁定的主机名;空就用工作流上记录的绑定
	ProjectDirectory string // 调用方自报的项目目录;空就用工作流上记录的绑定
	ConversationID   string
	ClientKind       string
	CursorVersion    string
	Event            agentstate.Event
	// Latest 为 true 表示「记到这个工作流最近活动的那个会话上」:Hub 自己产生的事件(托管终端的屏幕扫描器)不知道
	// 对话 ID、凭据,也不该凭空造出一个新身份。找不到可归属的会话就什么都不记(res.IdentityID 为 0)。
	Latest bool
	// Conversation 为 true 表示「记到这个工作流里 ConversationID 这个对话的会话上」(不管它有没有结束):
	// Hub 读到非交互运行的输出时清楚自己在续哪个对话——最近活动的会话可能是另一个,这个对话也可能刚被 hook 记成了 ended。
	// 同样不造新身份:这个对话还没有任何 hook 汇报过,就什么都不记(res.IdentityID 为 0)。
	Conversation bool
}

AgentIngestInput 是一次汇报(hook 事件,或 Hub 自己产生的事件)。

type AgentIngestResult

type AgentIngestResult struct {
	IdentityID uint
	SessionID  uint
	NewSession bool
	Change     agentstate.Change
	Snapshot   agentstate.Snapshot
}

AgentIngestResult 是 IngestAgentEvent 的结果。IdentityID 为 0 表示认不出身份(没有项目目录),什么都没记。

type AgentLink struct {
	ConversationID string    // Cursor 对话编号(用于重新拉起时恢复同一个对话);未知时为空
	LastToolAt     time.Time // 最近一次工具调用结束的时间(零值 = 没汇报过)
	StopAt         time.Time // 最近一轮对话结束的时间(零值 = 没汇报过)
	StopStatus     string    // 那一轮的结束状态;StopAt 为零值时为空
}

AgentLink 是某个工作流的智能体最近的运行情况。

type AgentLiveState

type AgentLiveState string

AgentLiveState 是顶栏存活图标的结论。

const (
	AgentLiveRunning AgentLiveState = "running"
	AgentLiveIdle    AgentLiveState = "idle"
	AgentLiveQuiet   AgentLiveState = "quiet"
	AgentLiveUnknown AgentLiveState = "unknown"
)

type AgentLiveView

type AgentLiveView struct {
	State  AgentLiveState `json:"state"`
	Reason string         `json:"reason,omitempty"`
	At     *time.Time     `json:"at,omitempty"`
}

AgentLiveView 供 GET /workflows/:id/inbox 与前端使用。

func ComputeAgentLive

func ComputeAgentLive(link AgentLink, hookAt time.Time, hookOK bool, sess *model.FeedbackSession, now time.Time) AgentLiveView

ComputeAgentLive 根据 hook 痕迹、智能体汇报与会话状态推断顶栏图标档位(纯函数)。

type AgentScreenChange

type AgentScreenChange struct {
	ApprovalStarted bool // 刚进入审批等待
	ApprovalEnded   bool // 审批等待刚结束(批准、跳过或中断)
	Approval        bool // 当前是否在审批等待
}

AgentScreenChange 描述一次上报带来的变化,供调用方决定要不要产生状态事件与通知。

type AgentScreenInput

type AgentScreenInput struct {
	Verified      bool   // cursor 版本在已验证清单里;false 时只展示「未识别」,不参与任何判断
	Recognized    bool   // 守护进程认出了 TUI(Screen 非空)
	CursorVersion string // 判断 Verified 所用的版本,仅展示
	Word          string
	Tokens        int     // -1 = 没读到
	CtxPct        float64 // -1 = 没读到
	Animating     bool
	Approval      bool
	Cancelled     bool
	QuietSeconds  int // 上报时距最后一次输出的秒数;-1 = 不知道
}

AgentScreenInput 是一次屏幕上报(已按版本闸门判断过 Verified)。

type AgentScreenView

type AgentScreenView struct {
	TUI        string  // "ok"(版本已验证)| "unrecognized"(版本未验证或画面认不出)
	Word       string  // 状态行动词,仅在动画中有值
	Tokens     int     // -1 = 没读到
	TokensSrc  string  // 有 Tokens 时为 "tui"
	CtxPct     float64 // -1 = 没读到
	Approval   bool
	Animating  bool
	ReceivedAt time.Time
	// contains filtered or unexported fields
}

AgentScreenView 是对外展示的屏幕信号。

type AgentSessionFilter

type AgentSessionFilter struct {
	WorkflowID string
	IdentityID uint
	Limit      int // 默认 20,最多 200
}

AgentSessionFilter 是 ListAgentSessions 的过滤条件。

type AgentSessionView

type AgentSessionView struct {
	ID             uint   `json:"id"`
	IdentityID     uint   `json:"identity_id"`
	WorkflowID     string `json:"workflow_id"`
	ConversationID string `json:"conversation_id"`
	ClientKind     string `json:"client_kind,omitempty"`
	CursorVersion  string `json:"cursor_version,omitempty"`

	IdentityLabel string `json:"identity_label"`
	HostName      string `json:"host_name"`
	ProjectDir    string `json:"project_directory"`

	StartedAt     *time.Time `json:"started_at,omitempty"`
	EndedAt       *time.Time `json:"ended_at,omitempty"`
	EndReason     string     `json:"end_reason,omitempty"`
	LastTool      string     `json:"last_tool,omitempty"`
	ToolStartedAt *time.Time `json:"tool_started_at,omitempty"`
	TurnStartedAt *time.Time `json:"turn_started_at,omitempty"`
	TurnEndedAt   *time.Time `json:"turn_ended_at,omitempty"`
	LastEventAt   time.Time  `json:"last_event_at"`
	LastMCPAt     *time.Time `json:"last_mcp_at,omitempty"`
	LastQueryAt   *time.Time `json:"last_query_at,omitempty"`

	State             string    `json:"state"`      // 展示态(含 waiting_you / offline)
	BaseState         string    `json:"base_state"` // 状态机里的状态
	Sub               string    `json:"sub,omitempty"`
	StateSource       string    `json:"state_source,omitempty"` // hook | tui | run:现在这个状态是谁说的(空 = 旧数据,没有记录)
	Since             time.Time `json:"since"`
	QuietSeconds      int       `json:"quiet_seconds"`
	WaitingYou        bool      `json:"waiting_you"`
	Stalled           bool      `json:"stalled"`
	StalledSoft       bool      `json:"stalled_soft"`
	ApprovalSuspected bool      `json:"approval_suspected"`
	ApprovalOverdue   bool      `json:"approval_overdue"`
	Reason            string    `json:"reason,omitempty"`

	// 托管终端的屏幕信号(M3.2)。TUI 为空表示这个会话没有可用的屏幕扫描结果。
	TUI          string     `json:"tui,omitempty"`           // ok | unrecognized
	LiveWord     string     `json:"live_word,omitempty"`     // 状态行动词(动画中才有)
	TokensLive   *int       `json:"tokens_live,omitempty"`   // 状态行里的实时 token 数
	TokensSource string     `json:"tokens_source,omitempty"` // tui
	CtxPct       *float64   `json:"ctx_pct,omitempty"`       // 页脚的上下文占用百分比
	ScreenAt     *time.Time `json:"screen_at,omitempty"`     // 屏幕信号的接收时间
}

AgentSessionView 是对外的会话视图:库里的状态加上 Evaluate 推导出的展示状态。

type AgentTouchInput

type AgentTouchInput struct {
	WorkflowID       string
	CredentialID     uint
	HostName         string
	ProjectDirectory string
	Query            bool // 读类调用(收件箱、会话列表、文档读取……)
	// Hook 为真表示这是编辑器 hook 的轮询(没带运行情况事件的那种):只记「hook 最近一次查询」,不算智能体调用 RelayMesh。
	Hook          bool
	ClientKind    string // hook 顺带汇报的客户端类型(ide / cli),其余场景留空
	CursorVersion string
}

AgentTouchInput 是一次 MCP 调用(带工作流编号)留下的痕迹。

type AppError

type AppError struct {
	Kind            ErrorKind
	Message         string
	CurrentRevision int64
}

func NewConflictError

func NewConflictError(msg string, currentRev int64) *AppError

func NewForbiddenError

func NewForbiddenError(msg string) *AppError

NewForbiddenError 表示任务级权限不允许这次操作;消息写给智能体看:谁能做、该怎么做。

func NewInvalidInputError

func NewInvalidInputError(msg string) *AppError

func NewNotFoundError

func NewNotFoundError(msg string) *AppError

func NewTaskClosedError

func NewTaskClosedError(msg string) *AppError

func (*AppError) Error

func (e *AppError) Error() string

type ArtifactCommentInput

type ArtifactCommentInput struct {
	DocID       uint
	Anchor      string
	Body        string
	AuthorKind  string
	AuthorRef   string
	AuthorLabel string
}

ArtifactCommentInput 是新增评论的入参。

type ArtifactDataSetInput

type ArtifactDataSetInput struct {
	DocID           uint
	Key             string
	ValueJSON       string
	ExpectedVersion *int
	ActorLabel      string
	ActorRef        string
}

ArtifactDataSetInput 是写一个键的入参。ExpectedVersion 非空时做乐观并发:版本不符返回冲突(0 = 期望这个键还不存在)。

type AuditFilter

type AuditFilter struct {
	ProjectID uint
	ActorRef  string
	Action    string // 精确,或以 . 结尾的前缀(如 doc.)
	Result    string
	ScopeRef  string // 前缀
	Since     time.Time
	Until     time.Time
	Limit     int
	BeforeID  uint // 翻页:只取 id 小于它的
}

AuditFilter 审计筛选。

type AuditInput

type AuditInput struct {
	ProjectID  uint
	ActorKind  string
	ActorRef   string
	ActorLabel string
	Action     string
	ScopeKind  string
	ScopeRef   string
	Target     string
	Result     string // 空 = allow
	Detail     any    // 序列化成 JSON;不得含正文
	// Dedupe > 0 时:窗口内已有同主体、同动作、同范围、同结果的记录就不再写。
	Dedupe time.Duration
	// DedupeExact 为 true 时,去重还要求目标与详情也完全相同:只有「同一个目标、同一个原因」的重复才合并,
	// 不同的原因 / 不同的目标各记各的(项目管理 Agent 运行预设被拒绝时,用户要看清每一种原因,而不是只看到第一条)。
	DedupeExact bool
}

AuditInput 是要记的一条审计。

type AuthCredentials

type AuthCredentials struct {
	Username  string    `json:"username"`
	Password  string    `json:"password"`
	UpdatedAt time.Time `json:"updated_at"`
}

type AuthProfileInput

type AuthProfileInput struct {
	Name  *string
	Level *string
	Rules *string
	Sort  *int
}

AuthProfileInput 是新建 / 修改档位的入参;修改时只改非 nil 的字段。

type AutoResumeRecord

type AutoResumeRecord struct {
	// FromRun 是出事的那次运行(它异常退出了);同一次运行最多一条登记。
	FromRun string `json:"from_run"`
	// Attempt 是这次续跑在这一串里排第几次(1 起);出事的运行本身是手动运行时从 1 开始。
	Attempt int `json:"attempt"`
	// Class、Code、Reason 是出事的原因:类别(retriable……)、服务端错误码、一句中文。
	Class  string `json:"class,omitempty"`
	Code   string `json:"code,omitempty"`
	Reason string `json:"reason,omitempty"`
	// PlannedAt 是登记(出事被发现)的时间,Due 是排定的开跑时间。
	PlannedAt time.Time `json:"planned_at"`
	Due       time.Time `json:"due,omitempty"`
	State     string    `json:"state"`
	// Why 是跳过 / 放弃 / 取消的原因(一句中文)。
	Why string `json:"why,omitempty"`
	// RunID 是续跑出来的新运行;StartedAt 是它提交的时间。
	RunID     string    `json:"run_id,omitempty"`
	StartedAt time.Time `json:"started_at,omitempty"`
	// Quick 在续跑出来的运行又失败时由后一次登记补上:它跑得太短(没有进展,短于「续跑成功」的判定时长)。连续几次 Quick 就熔断。
	Quick bool `json:"quick,omitempty"`
	// Settled 表示这次续跑出来的运行连续跑满了「续跑成功」的判定时长(#172):这次续跑算成功,
	// 24 小时内累计的续跑次数(预算与退避阶梯)从它之后重新算,它自己和它之前的登记都不再占名额。
	Settled bool `json:"settled,omitempty"`
}

AutoResumeRecord 是一次「异常退出之后自动续跑」的登记:从排期,到开跑 / 跳过 / 放弃 / 被你取消。 它只记运行编号、次数、时间与一句话原因,不含任何输出内容。

type BoardAssignment

type BoardAssignment struct {
	WorkflowID string `json:"workflow_id"`
	BoardKey   string `json:"board_key"`
	Items      int    `json:"items"`
	Modules    int    `json:"modules"`
	// Reason 说明依据:粘性(已有归板的任务 / 节点)、目录归属,或冲突回退。
	Reason string `json:"reason"`
	// Fallback 为 true 表示它本该落到 WantedKey,因序号或规划节点路径冲突回退到自己的独立板。
	Fallback  bool     `json:"fallback,omitempty"`
	WantedKey string   `json:"wanted_key,omitempty"`
	Conflicts []string `json:"conflicts,omitempty"`
}

BoardAssignment 是迁移里一个工作流的归板决定。

type BoardCounterPlan

type BoardCounterPlan struct {
	BoardKey string `json:"board_key"`
	LastSeq  int    `json:"last_seq"`
	// Existing 是现有 work_board_counters 里的值,没有记录为 0。
	Existing int `json:"existing"`
}

BoardCounterPlan 是迁移后某张板的序号计数;只列需要写(没有记录或要调大)的。

type BoardInfo

type BoardInfo struct {
	// Key 是板的 key。
	Key string
	// Project 在项目板时非空。
	Project *model.Project
	// Host / Dir 是解析所依据的最近一条带目录的汇报会话;没有时为空。
	Host, Dir string
	// Reason 是一句话说明为什么落在这张板(迁移预演与排错用)。
	Reason string
}

BoardInfo 是一个工作流按目录归属解析出的板。

type BoardMergeBoard

type BoardMergeBoard struct {
	Key         string `json:"key"`
	ProjectID   uint   `json:"project_id,omitempty"`
	ProjectSlug string `json:"project_slug,omitempty"`
	ACLMode     string `json:"acl_mode,omitempty"`
	// Workflows 按「谁更早」排序(有任务的最早创建时间,其次编号):排在前面的保留自己的序号。
	Workflows []string `json:"workflows"`
	Tasks     int      `json:"tasks"`
	// Counter 是迁移后 work_board_counters.last_seq:板内最大序号与各工作流旧计数的最大值。
	Counter int `json:"counter"`
	// Renumbered 是要改号的任务数;DupModules 是会被合并掉的重复规划节点数。
	Renumbered int `json:"renumbered"`
	DupModules int `json:"dup_modules"`
}

BoardMergeBoard 是规划出的一张板。

type BoardMergeCollision

type BoardMergeCollision struct {
	BoardKey string              `json:"board_key"`
	Seq      int                 `json:"seq"`
	Items    []BoardMergeItemRef `json:"items"`
}

BoardMergeCollision 是同一张板里两个以上工作流用了同一个序号。

type BoardMergeItemRef

type BoardMergeItemRef struct {
	ItemID     uint   `json:"item_id"`
	WorkflowID string `json:"workflow_id"`
	Title      string `json:"title"`
}

BoardMergeItemRef 指向一条任务。

type BoardMergeModuleDup

type BoardMergeModuleDup struct {
	BoardKey  string   `json:"board_key"`
	Path      string   `json:"path"`
	Workflows []string `json:"workflows"`
	ModuleIDs []uint   `json:"module_ids"`
	// Tasks 是挂在这些节点上的任务数。
	Tasks int `json:"tasks"`
}

BoardMergeModuleDup 是同一张板里路径相同的规划节点(会合并成一个)。

type BoardMergePlan

type BoardMergePlan struct {
	Items      int                   `json:"items"`
	Workflows  []BoardMergeWorkflow  `json:"workflows"`
	Boards     []BoardMergeBoard     `json:"boards"`
	Collisions []BoardMergeCollision `json:"collisions"`
	Renumbers  []BoardMergeRenumber  `json:"renumbers"`
	ModuleDups []BoardMergeModuleDup `json:"module_dups"`
	// Warnings 是不阻塞但值得人看一眼的发现(解析不到目录、跨工作流的父子 / 模块引用、计数落后等)。
	Warnings []string `json:"warnings"`
}

BoardMergePlan 是并入预演的完整结果。

func PlanBoardMerge

func PlanBoardMerge(ctx context.Context, db *gorm.DB) (*BoardMergePlan, error)

PlanBoardMerge 读库算出「若把每个工作流并入它目录归属的板,序号有没有冲突、要改哪些号」,不写任何表。 只用到旧列(不看 board_key),所以对迁移前后的库都可用;它按目录归属动态解析,不考虑任务已经落在哪张板。

type BoardMergeRenumber

type BoardMergeRenumber struct {
	BoardKey   string `json:"board_key"`
	WorkflowID string `json:"workflow_id"`
	ItemID     uint   `json:"item_id"`
	OldSeq     int    `json:"old_seq"`
	NewSeq     int    `json:"new_seq"`
}

BoardMergeRenumber 是一条改号动作:只重编冲突的那几条,别的序号原样保留;旧号写进别名表。

type BoardMergeWorkflow

type BoardMergeWorkflow struct {
	WorkflowID string `json:"workflow_id"`
	Tasks      int    `json:"tasks"`
	MaxSeq     int    `json:"max_seq"`
	// Counter 是旧计数表 work_item_counters 里的值;HasCounter 表示有没有这条记录。
	Counter     int       `json:"counter"`
	HasCounter  bool      `json:"has_counter"`
	Modules     int       `json:"modules"`
	FirstTaskAt time.Time `json:"first_task_at,omitempty"`
	BoardKey    string    `json:"board_key"`
	ProjectSlug string    `json:"project_slug,omitempty"`
	Host        string    `json:"host,omitempty"`
	Dir         string    `json:"dir,omitempty"`
	Reason      string    `json:"reason"`
}

BoardMergeWorkflow 是规划里的一个工作流:它有多少任务、落在哪张板、依据是什么。

type BoardReconcilePlan

type BoardReconcilePlan struct {
	// Placed 是已经归板的任务数(board_key 非空);Unplaced / UnplacedModules 是这次要归板的任务数与规划节点数。
	Placed          int                `json:"placed"`
	Unplaced        int                `json:"unplaced"`
	UnplacedModules int                `json:"unplaced_modules"`
	Assignments     []BoardAssignment  `json:"assignments"`
	Counters        []BoardCounterPlan `json:"counters"`
	Warnings        []string           `json:"warnings"`
}

BoardReconcilePlan 是给历史任务补板的完整计划。

func PlanBoardReconcile

func PlanBoardReconcile(ctx context.Context, db *gorm.DB) (*BoardReconcilePlan, error)

PlanBoardReconcile 只读地算出启动迁移会做什么(供 dry-run 工具使用)。

func (*BoardReconcilePlan) Changed

func (p *BoardReconcilePlan) Changed() bool

Changed 表示这份计划是否会写库。

type ConfirmAnswerInput

type ConfirmAnswerInput struct {
	OptionIDs []string
	Note      string
	Custom    string
	By        string
}

ConfirmAnswerInput 一次作答:选项 id + 可选备注 + 可选的自定义答复(#183)+ 作答来源。

type ConfirmBatchItem

type ConfirmBatchItem struct {
	Ref     string   `json:"ref"`
	Options []string `json:"options,omitempty"`
	Note    string   `json:"note,omitempty"`
}

ConfirmBatchItem 是批量作答里的一项;Options 为空且批量要求「采用推荐」时取该项的推荐选项。

type ConfirmBatchResult

type ConfirmBatchResult struct {
	Items   []*model.ConfirmItem
	Message string
}

ConfirmBatchResult 批量作答的结果:已作答的项与投递给智能体的那条收件箱文案。

type ConfirmCreateInput

type ConfirmCreateInput struct {
	WorkflowID    string
	Kind          string
	Title         string
	Body          string
	Options       []model.ConfirmOption
	Multi         bool
	AllowNote     bool
	DefaultOption string
	Risk          string
	TaskSeq       int
	DocID         uint
	DocKey        string
	Anchor        string
	CreatedBy     string
}

ConfirmCreateInput 创建确认项(REST 不暴露;MCP async_ask 与文档同步使用)。

type ConfirmFilter

type ConfirmFilter struct {
	WorkflowID string
	Statuses   []string
	Kinds      []string
	TaskSeq    int
	DocID      uint
	Limit      int
	Offset     int
	Ascending  bool
}

ConfirmFilter 列表筛选。Ascending=false 时新的在前(序号倒序),true 时旧的在前(待确认队列用)。

type CreateGroupInput

type CreateGroupInput struct {
	Title     string
	ProjectID string
	CreatedBy string
	Members   []string // 工作流编号;调用方负责校验它们处于聊天模式(G-1)
}

CreateGroupInput 是建群的入参。建群只有你能做(API 层校验 actor 是 human,工具层没有入口)。

type CreateSessionInput

type CreateSessionInput struct {
	SessionID          string `json:"session_id,omitempty"`
	WorkflowID         string `json:"workflow_id,omitempty"`
	CredentialID       uint   `json:"credential_id,omitempty"`
	EnvHostName        string `json:"env_host_name,omitempty"`
	CredentialHostName string `json:"credential_host_name,omitempty"`
	ProjectDirectory   string `json:"project_directory"`
	Title              string `json:"title,omitempty"`
	Summary            string `json:"summary"`
	TimeoutSeconds     int    `json:"timeout_seconds,omitempty"`
	// 交付锚点(可选):调用方已校验并规整;为空表示本轮没有锚点。
	GitCommit  string `json:"git_commit,omitempty"`
	GitSubject string `json:"git_subject,omitempty"`
}

type CreateWebWorkflowInput

type CreateWebWorkflowInput struct {
	// Title 必填,经 NormalizeWebWorkflowTitle 规整。
	Title string
	// WorkflowID 可选;为空自动生成 wf-web-<日期>-<6 位随机>。给定时必须符合 webWorkflowIDPattern 且库里还没有这个工作流。
	WorkflowID string
	// EnvHostName 是服务自己配置的主机名,仅作兜底(全局设置里的主机名优先)。
	EnvHostName string
	// ProjectDirectory 可选:把占位会话(以及这个工作流)绑定到某个项目目录,经 NormalizeWebProjectDirectory 规整;
	// 为空 = 不绑定(D-161 不比较,智能体带什么目录都行)。
	ProjectDirectory string
	// HostName 可选:用户指定的主机名(会话的归属标签),经 NormalizeWebHostName 规整;
	// 为空沿用「全局设置 > 服务环境变量 > hosts」。智能体接入后,凭据绑定的主机仍以凭据为准。
	HostName string
}

CreateWebWorkflowInput 是网页新建会话的入参。

type CreateWebWorkflowResult

type CreateWebWorkflowResult struct {
	Session     *model.FeedbackSession
	StartPrompt string
}

CreateWebWorkflowResult 是网页新建会话的结果。

type CredentialHost

type CredentialHost struct {
	Name     string `json:"name"`
	HostName string `json:"host_name"`
	Active   bool   `json:"active"`
}

CredentialHost 是「凭据名 → 主机名」的只读视图,供运维挑选改绑目标主机;不含令牌。

type DocActor

type DocActor struct {
	Kind string // human / agent / import
	// IdentityID 是写入者的 Agent 身份(#114);新建文档时记为负责人,0 = 不记。
	IdentityID uint
}

DocActor 描述写入者。

type DocBrief

type DocBrief struct {
	ID         uint      `json:"id"`
	WorkflowID string    `json:"workflow_id"`
	Path       string    `json:"path"`
	Title      string    `json:"title"`
	Kind       string    `json:"kind"`
	Status     string    `json:"status"`
	Render     string    `json:"render,omitempty"`
	UpdatedAt  time.Time `json:"updated_at"`
}

DocBrief 是模块页里一篇文档的摘要(不含正文)。

type DocLinkRef

type DocLinkRef struct {
	Target     string `json:"target,omitempty"` // 出链:正文里写的目标(已规范化路径)
	ID         uint   `json:"id,omitempty"`
	WorkflowID string `json:"workflow_id,omitempty"`
	Path       string `json:"path"`
	Title      string `json:"title,omitempty"`
	Exists     bool   `json:"exists"`
}

DocLinkRef 是链接关系里的一端:出链指向的文档(可能不存在),或反链来自的文档。

type DocLinks struct {
	Outlinks  []DocLinkRef `json:"outlinks"`
	Backlinks []DocLinkRef `json:"backlinks"`
}

DocLinks 是一篇文档的出链与反链。

type DocWorkflowStat

type DocWorkflowStat struct {
	WorkflowID string    `json:"workflow_id"`
	Total      int       `json:"total"`
	UpdatedAt  time.Time `json:"updated_at"`
}

DocWorkflowStat 供页头角标。

type DraftImageInfo

type DraftImageInfo struct {
	Key       string    `json:"key"`
	Name      string    `json:"name,omitempty"`
	Format    string    `json:"format,omitempty"`
	Hash      string    `json:"hash,omitempty"`
	Width     int       `json:"width,omitempty"`
	Height    int       `json:"height,omitempty"`
	Size      int       `json:"size"`
	UpdatedAt time.Time `json:"updated_at"`
}

DraftImageInfo 是一张草稿图片的元数据(不含正文)。

type ErrorKind

type ErrorKind string
const (
	ErrNotFound         ErrorKind = "not_found"
	ErrConflict         ErrorKind = "conflict"
	ErrInvalidInput     ErrorKind = "invalid_input"
	ErrClosed           ErrorKind = "task_closed"
	ErrUnauthorized     ErrorKind = "unauthorized"
	ErrForbidden        ErrorKind = "forbidden" // 任务级权限(#175 B2):调用方不是这条任务的创建者 / 承接者 / 管理者
	ErrOperationFailed  ErrorKind = "operation_failed"
	ErrIdempotencyClash ErrorKind = "idempotency_clash"
)

type GlobalAppSettings

type GlobalAppSettings struct {
	HostName                    string `json:"hostName"`
	DefaultTimeoutSeconds       int    `json:"defaultTimeoutSeconds"`
	PromptWaitMinutes           int    `json:"promptWaitMinutes"`
	MaxNoFeedbackChecks         int    `json:"maxNoFeedbackChecks"`
	DefaultWaitCountdownMinutes int    `json:"defaultWaitCountdownMinutes"`
	// DefaultWaitCountdownSeconds 秒级默认挂起倒计时;-1 = 没设过,沿用分钟值。
	DefaultWaitCountdownSeconds int `json:"defaultWaitCountdownSeconds"`
	// 异步对话(#123):智能体每发一条新消息,回复窗口加这么多分钟;<=0 按默认 5。
	AsyncWindowAddMinutes int `json:"asyncWindowAddMinutes"`
	// 异步对话:智能体每次用计时器最多连续等这么多分钟再回头读收件箱;<=0 按默认 10。
	AsyncWaitSliceMinutes int               `json:"asyncWaitSliceMinutes"`
	UserMemory            string            `json:"userMemory"`
	ServerInstructions    string            `json:"serverInstructions"`
	PhaseTemplate         []model.PhaseItem `json:"phaseTemplate"`
	Security              SecuritySettings  `json:"security"`
	FlowPrompts           struct {
		Online struct {
			WaitPollPrompt  string `json:"waitPollPrompt"`
			ExhaustedPrompt string `json:"exhaustedPrompt"`
		} `json:"online"`
	} `json:"flowPrompts"`
}

type GrantInput

type GrantInput struct {
	ProjectID      uint
	PrincipalKind  string // identity | group
	PrincipalRef   string // identity:身份编号;group:会话编号
	ScopeKind      string // project | module | doc | workflow | tasks(项目任务板的管理权,只能由用户授予)
	ScopeRef       string
	Role           string // read | comment | edit(manage 不能授予)
	GrantedByKind  string // human | identity
	GrantedByRef   string
	GrantedByLabel string
	ExpiresAt      *time.Time
	Note           string
}

GrantInput 是一条新授权。

type GroupError

type GroupError struct {
	Code    string // not_member | rate_limited | hop_limit | too_large | group_archived
	Message string
}

GroupError 是群聊规则拒绝一次操作时的错误,Code 给 MCP / API 做机器可读的分流。

func (*GroupError) Error

func (e *GroupError) Error() string

type GroupVisibility

type GroupVisibility struct {
	From time.Time
	To   *time.Time
}

GroupVisibility 限定一个 Agent 能看到的消息:入群之后,且(离开前)。人读取时传 nil。

type GuardPresetState

type GuardPresetState struct {
	// NotifiedEpisode 是最近一次推送过的事件标识:同一次事件不重复推送。
	NotifiedEpisode string                `json:"notified_episode,omitempty"`
	NotifiedAt      time.Time             `json:"notified_at,omitempty"`
	Reminders       int                   `json:"reminders,omitempty"` // 同一次事件已经补发过几次提醒
	Wakes           []GuardWakeRecord     `json:"wakes,omitempty"`
	Permit          *GuardWakePermitState `json:"permit,omitempty"`
	// AutoResumes 是「非交互运行异常退出后自动续跑」的登记(按登记先后,新的在后)。
	AutoResumes []AutoResumeRecord `json:"auto_resumes,omitempty"`
}

GuardPresetState 是一个预设的守护状态。

func (*GuardPresetState) AutoResumeFrom

func (p *GuardPresetState) AutoResumeFrom(fromRun string) (AutoResumeRecord, bool)

AutoResumeFrom 返回为 fromRun 这次出事登记的自动续跑;没有时 ok 为 false。

func (*GuardPresetState) AutoResumeStartedSince

func (p *GuardPresetState) AutoResumeStartedSince(since time.Time) int

AutoResumeStartedSince 返回 since 之后已经开跑的自动续跑次数(滚动窗口里的预算用量)。 成功的续跑(Settled,见 SettleAutoResume)会把计数清零:从最近一次成功的续跑之后才开始数,它自己和它之前的都不算。

func (*GuardPresetState) AutoResumeStarting

func (p *GuardPresetState) AutoResumeStarting(runID string) (AutoResumeRecord, bool)

AutoResumeStarting 返回那条「开跑出了 runID 这次运行」的登记;runID 不是自动续跑出来的就 ok 为 false。

func (*GuardPresetState) AutoResumeTrailingQuick

func (p *GuardPresetState) AutoResumeTrailingQuick() int

AutoResumeTrailingQuick 返回沿着「续跑出来的运行又出事」这条链,最近连续有几次续跑「没有进展」(Quick)。 链断了(中间被你手动运行过、或某次续跑被跳过)就停:那之后重新算。

func (*GuardPresetState) ClaimAutoResumeRun

func (p *GuardPresetState) ClaimAutoResumeRun(runID string, attempt int) bool

ClaimAutoResumeRun 把「已开跑、却还没写上运行编号」的那条登记认领给 runID(#187):占名额、提交运行、写聊天行、写运行编号是分开的几步, 运行很快就结束(或这几步被负载拖慢)时,结束的处理会先到,按编号找不到登记。结束的处理拿运行说明末尾「自动续跑 n/m」里的次数 attempt 来认领: 找最近一条已开跑、编号为空、次数相同的登记。提交方随后写入的是同一个编号,所以认领与写入的先后不影响结果。 返回是否有改动:已经有登记带着这个编号、找不到合适的登记(不是续跑出来的、编号已经写上、次数对不上),都返回 false 且什么也不改。

func (*GuardPresetState) LastWake

func (p *GuardPresetState) LastWake() (GuardWakeRecord, bool)

LastWake 返回最近一次唤醒;没有时 ok 为 false。

func (*GuardPresetState) SettleAutoResume

func (p *GuardPresetState) SettleAutoResume(runID string) bool

SettleAutoResume 认定「开跑出了 runID 这次运行」的那次续跑成功(调用方已确认它连续跑满了判定时长): 标上 Settled、去掉 Quick,并让预算用量从它之后重新算。返回是否有改动:runID 不是自动续跑出来的、 那条登记不是「已开跑」状态、或者早就认定过,都返回 false(幂等,调用方据此只写一次聊天行)。

func (*GuardPresetState) TrailingNoProgress

func (p *GuardPresetState) TrailingNoProgress() int

TrailingNoProgress 返回最近连续有几次唤醒「过了观察窗口仍没有动静」(遇到有动静的、或还没结论的就停)。

func (*GuardPresetState) WakesSince

func (p *GuardPresetState) WakesSince(since time.Time) int

WakesSince 返回 since 之后的唤醒次数。

type GuardStateDoc

type GuardStateDoc struct {
	Presets map[string]*GuardPresetState `json:"presets"`
}

GuardStateDoc 是整份守护状态:预设编号 → 状态。

func (*GuardStateDoc) Preset

func (d *GuardStateDoc) Preset(id string) *GuardPresetState

Preset 返回某个预设的状态;没有时返回新建的空状态(并登记进文档,方便调用方直接改)。

type GuardWakePermitState

type GuardWakePermitState struct {
	Permit            int       `json:"permit,omitempty"` // 0 = 已标记;缺省或 1 = 正常守护
	SetAt             time.Time `json:"set_at,omitempty"`
	SetBy             string    `json:"set_by,omitempty"` // agent | human
	Note              string    `json:"note,omitempty"`   // 可选备注,审计不含
	SuppressedEpisode string    `json:"suppressed_episode,omitempty"`
}

GuardWakePermitState 是唤醒许可的持久化(默认 1;标记为 0 表示任务全部完成、结束时不唤醒)。

type GuardWakeRecord

type GuardWakeRecord struct {
	At      time.Time `json:"at"`
	Mode    string    `json:"mode"`              // type(输入到存活的会话)| relaunch(会话已结束,重新拉起)
	Reason  string    `json:"reason"`            // 出错中断 / 长时间无活动 / 会话意外结束 / 手动唤醒……
	Episode string    `json:"episode,omitempty"` // 唤醒时判断的事件标识
	// Progress 由守护的周期判断补上:这次唤醒之后智能体有没有新的动静。连续几次「没有」说明唤醒在白费力气。
	Progress string `json:"progress,omitempty"`
}

GuardWakeRecord 是一次唤醒的登记。

type HeadlessRun

type HeadlessRun struct {
	// Bin 是可执行文件(命令名或路径);空 = DefaultHeadlessBin。
	Bin string `json:"bin,omitempty"`
	// Model 是 --model 的值;空 = 不带(用 CLI 自己的默认模型)。
	Model string `json:"model,omitempty"`
	// Posture 是权限姿态:allowlist(默认,不带 --force,只能做 CLI 白名单放行的事)或 force(带 --force,放开全部命令)。
	Posture string `json:"posture,omitempty"`
	// WorkflowID 是智能体使用的 RelayMesh 工作流编号:用来找到它最近的对话、替换提示词里的 %workflow、
	// 在聊天里记系统行、判断这次运行有没有向 RelayMesh 汇报。
	WorkflowID string `json:"workflow_id,omitempty"`
	// ConversationID 固定要接着的对话;空 = 用 hook 汇报的、这个工作流最近的 CLI 对话编号。
	ConversationID string `json:"conversation_id,omitempty"`
	// Prompt 是提示词正文;空 = 服务端默认文本。其中 %workflow 换成工作流编号。
	Prompt string `json:"prompt,omitempty"`
	// MaxRunMinutes 是一次运行最长跑多久(分钟,#141);0 = 没设,用平台单次运行上限 7 天。
	// 到点由主机强制结束这次运行(运行状态「超时」,界面写「达到运行时长上限」);设了的值收进 [1 分钟, 7 天],负数被拒绝。
	// 续聊是一个会话而不是一条短命令,所以默认不设短限;想给一次运行封顶(防止它无人看管地跑太久)才需要填。
	MaxRunMinutes int `json:"max_run_minutes,omitempty"`
	// AutoResume 打开后,这个预设发起的运行如果「异常退出」且错误被 CLI 自己标成可重试(#151,D-260),Hub 会在退避之后
	// 自动再续聊一次:24 小时最多 3 次,连续 2 次没有进展就停下并通知。默认关闭——它是无人值守的模型调用,有成本。
	// 你取消的、运行时长上限到点的、成功退出的、需要你处理或认不出原因的失败,一律不会自动续跑。
	AutoResume bool `json:"auto_resume,omitempty"`
	// AutoResumeOKMinutes 是自动续跑「成功」的判定时长(分钟,#172,追加 #304):续跑出来的运行连续跑满这么久,
	// 就算这次续跑成功,24 小时内累计的续跑次数与退避从头算,不再被它之前的几次续跑拖累;
	// 比它短就算「没有进展」(连续 2 次没有进展就熔断)。0 = 没设,用默认的 10 分钟;设了的值收进 [1 分钟, 1 天],负数被拒绝。
	AutoResumeOKMinutes int `json:"auto_resume_ok_minutes,omitempty"`
	// NewConversation 打开后,这个预设在「还不知道要接哪个对话」(预设里没有固定对话编号、这个工作流里也没有智能体接入过)时
	// 不再报错,而是新开一个对话(#176 第三期):命令不带 --resume,提示词换成「接入工作流」版本,
	// 对话编号从这次运行输出的 init 事件里学到并记下来——之后的运行就是续聊,所以它只会新开一次。
	// 默认关:不打开它,没有对话编号的预设照旧报错,不会悄悄新开。固定了对话编号(ConversationID)就不能再选新开:二选一。
	NewConversation bool `json:"new_conversation,omitempty"`
	// Origin 标记预设是怎么来的:空 = 手工建的;HeadlessOriginEnableAgent = 会话页「启用 Agent」自动建的(#176)。
	// 只用来在启动器清单里给它打标记、以及让「启用 Agent」再次点击时复用同一条预设,不改变运行行为。
	Origin string `json:"origin,omitempty"`
}

HeadlessRun 是「非交互续聊」预设(Kind == "headless")的运行配置。

点「运行」时,Hub 经主机的执行通道运行(与 ExecMesh、会话守护的非交互唤醒同一条通道、同一套闸门):

<bin> -p --resume <对话编号> --approve-mcps --trust [--model <模型>] [--force] --workspace <目录> --output-format stream-json '<提示词>'

新开对话(NewConversation 且还不知道对话编号)时命令不带 `--resume <对话编号>`,其余相同。

命令只由这些已校验的字段拼出,所有动态部分都经过单引号包裹;预设不能写任意命令,所以改配置不会变成任意命令执行。

func NormalizeHeadlessRun

func NormalizeHeadlessRun(r HeadlessRun) (HeadlessRun, error)

NormalizeHeadlessRun 规整并校验一份非交互运行配置:会话页的「运行」(#128)与预设共用这套字段规则。 错误信息面向用户,已去掉「终端启动预设不合法」的前缀;返回的配置总是规整后的。

func (HeadlessRun) EffectiveAutoResumeOK

func (r HeadlessRun) EffectiveAutoResumeOK() time.Duration

EffectiveAutoResumeOK 返回实际生效的「续跑成功」判定时长:没设就是默认的 10 分钟,超过上限的收进上限。

func (HeadlessRun) EffectiveBin

func (r HeadlessRun) EffectiveBin() string

EffectiveBin 返回实际使用的可执行文件。

func (HeadlessRun) EffectiveMaxRunMinutes

func (r HeadlessRun) EffectiveMaxRunMinutes() int

EffectiveMaxRunMinutes 返回实际生效的最长运行时间(分钟):没设就是平台单次运行上限。

func (HeadlessRun) EffectiveMaxRunSeconds

func (r HeadlessRun) EffectiveMaxRunSeconds() int

EffectiveMaxRunSeconds 是 EffectiveMaxRunMinutes 换算成秒:交给执行通道当这次运行的超时。

func (HeadlessRun) EffectivePosture

func (r HeadlessRun) EffectivePosture() string

EffectivePosture 返回实际生效的权限姿态。

type HeadlessWake

type HeadlessWake struct {
	Enabled bool   `json:"enabled"`
	Posture string `json:"posture,omitempty"` // allowlist | force;空 = allowlist
}

HeadlessWake 是非交互唤醒的配置。

func (HeadlessWake) EffectivePosture

func (h HeadlessWake) EffectivePosture() string

EffectivePosture 返回实际生效的权限姿态。

type HostGrantResult

type HostGrantResult struct {
	// Granted 是这次新写入名单的令牌名称(令牌名不是机密,可用于审计与界面提示)。
	Granted []string `json:"granted"`
	// Full 是名单已满(达到 CredentialMaxTerminalHosts)、无法再写入的令牌数。
	Full int `json:"full"`
}

HostGrantResult 是把一台主机写入模型令牌名单的结果。

type HostModelUpdate

type HostModelUpdate struct {
	AllowModel  *bool
	ExecMode    *string
	ModelPaused *bool
	// DefaultForNewModels 是主机对新建模型授权的默认态(allow / deny);归一后比较,deny 与空串视为同一状态。
	DefaultForNewModels *string
}

HostModelUpdate 描述对主机「模型访问」设置的一次修改;nil 字段表示不修改。

type ImportDocFile

type ImportDocFile struct {
	Path    string
	Content string
	Kind    string
	Status  string
	Tags    []string
	Title   string
}

ImportProjectDocs 批量导入。

type ImportDocResult

type ImportDocResult struct {
	Created   int
	Updated   int
	Unchanged int
	Errors    []string
}

type InboxConfig

type InboxConfig struct {
	Enabled         bool `json:"enabled"`           // 总开关
	ReceiptHint     bool `json:"receipt_hint"`      // 第二层:工具回执里追加 inbox: 提示
	Hooks           bool `json:"hooks"`             // 第一层:Cursor hook 的提醒 / 拦截(hook 查询时由服务端判断)
	PromptClause    bool `json:"prompt_clause"`     // 第三层:MCP 指引里的收件箱条款
	HookInstallHint bool `json:"hook_install_hint"` // 未装 hook 时在回执末尾提示安装(可关)
}

InboxConfig 是追加指令收件箱的手动开关:一个总开关,外加三层发现机制各自的开关。 总开关关闭等于回到「被动模式」:不再追加回执提示行、不再让 hook 提醒、不再在指引里提收件箱; 已经排队的追加一条都不会丢,智能体下次发起交互时仍然会被秒回带走。

func DefaultInboxConfig

func DefaultInboxConfig() InboxConfig

DefaultInboxConfig 默认全部打开。

func (InboxConfig) ClauseOn

func (c InboxConfig) ClauseOn() bool

func (InboxConfig) Effective

func (c InboxConfig) Effective(envOff bool) InboxConfig

Effective 叠加环境变量的总闸(RELAYMESH_INBOX=off):它只能关,不能开。

func (InboxConfig) HintOn

func (c InboxConfig) HintOn() bool

HintOn / HooksOn / ClauseOn 是「总开关 ∧ 分层开关」。

func (InboxConfig) HookInstallHintOn

func (c InboxConfig) HookInstallHintOn() bool

HookInstallHintOn 是否在回执里提示安装 hook。

func (InboxConfig) HooksOn

func (c InboxConfig) HooksOn() bool

type InboxPeek

type InboxPeek struct {
	InboxSummary
	Remind bool `json:"remind"`
}

InboxPeek 是 hook 的查询结果:概况,外加「这次该不该提醒」。

type InboxReadOptions

type InboxReadOptions struct {
	// Recent 同时返回最近已确认的几条(上下文被压缩后想找回之前读过的追加时用)。
	Recent bool
}

InboxReadOptions 控制 InboxRead 返回什么。

type InboxReadResult

type InboxReadResult struct {
	New       []model.QueuedFeedback // 这次第一次送达
	Pending   []model.QueuedFeedback // 此前已读取、仍未确认(再列一遍,防止遗漏)
	Retracted []model.QueuedFeedback // 读取或被提醒后被撤回,这是第一次告诉智能体:请忽略(DeliveredAt 为空的是「只被提醒过、没读过」)
	Recent    []model.QueuedFeedback // 最近已确认的(仅 Recent=true 时)
}

InboxReadResult 是一次读取收件箱的结果。

func (InboxReadResult) Empty

func (r InboxReadResult) Empty() bool

Empty 表示没有任何内容可给。

type InboxSummary

type InboxSummary struct {
	Unread         int        `json:"unread"`                     // 排队中、智能体还没读到的条数
	UnreadMentions int        `json:"unread_mentions,omitempty"`  // 其中是群聊 @ 提醒(kind=chat_mention)的条数
	UnreadAnswers  int        `json:"unread_answers,omitempty"`   // 其中是确认项答复(kind=answer)的条数;提示行据此换措辞
	Delivered      int        `json:"delivered"`                  // 已读取、尚未确认的条数
	RetractNotices int        `json:"retract_notices"`            // 智能体读过或被提醒过、之后被撤回、还没告诉它的条数(#199)
	OldestUnreadAt *time.Time `json:"oldest_unread_at,omitempty"` // 最早一条未读的时间
	LatestUnreadAt *time.Time `json:"latest_unread_at,omitempty"` // 最新一条未读的时间
	LatestPreview  string     `json:"latest_preview,omitempty"`   // 最新一条未读的预览(单行、截断)
}

InboxSummary 是一个工作流收件箱的概况:提示行与 hook 都靠它。

type JWTSecretResolution

type JWTSecretResolution struct {
	// Secret 是最终用于签名的密钥,恒满足 config.IsStrongJWTSecret。
	Secret string
	Source JWTSecretSource
	// EnvRejectedReason 非空表示运维显式设置了 RELAYMESH_JWT_SECRET 但强度不足而被忽略(原因不含密钥内容)。
	// 变量缺省(等于内置默认值)不算显式设置,不会填充该字段。
	EnvRejectedReason string
	// PersistError 仅在 Source 为 ephemeral 时非空:说明无法持久化的原因。
	PersistError error
}

JWTSecretResolution 是 ResolveJWTSecret 的结果。

type JWTSecretSource

type JWTSecretSource string

JWTSecretSource 标记当前生效的 JWT 签名密钥来源,仅用于日志与诊断。

const (
	JWTSecretSourceEnv       JWTSecretSource = "env"       // 环境变量 RELAYMESH_JWT_SECRET(强度合格)
	JWTSecretSourceDB        JWTSecretSource = "database"  // 此前自动生成并持久化在数据库中的密钥
	JWTSecretSourceGenerated JWTSecretSource = "generated" // 本次启动新生成并已持久化
	JWTSecretSourceEphemeral JWTSecretSource = "ephemeral" // 持久化失败,仅本进程内存有效,重启后失效
)

type LauncherGuard

type LauncherGuard struct {
	// Enabled 是监测开关;关闭时保留其余配置,下次打开不用重填。
	Enabled bool `json:"enabled"`
	// WorkflowID 是这个会话里的智能体使用的 RelayMesh 工作流编号:服务端据此判断它是不是在合法地等你回复、
	// 有没有没读的回复或追加、有没有进行中的任务。留空只能监测「意外退出」,无法判断停摆。
	WorkflowID string `json:"workflow_id,omitempty"`
	// SilenceMinutes 是多久没有任何活动才算停摆;0 表示用默认值(DefaultGuardSilenceMinutes)。
	SilenceMinutes int `json:"silence_minutes,omitempty"`
	// ResumeCommand 是会话已经结束时重新拉起用的一整行命令,其中 {chat_id} 会换成智能体最近一次汇报的对话编号。
	// 留空表示只能在会话还活着时唤醒。
	ResumeCommand string `json:"resume_command,omitempty"`
	// WakePrompt 是唤醒时输入的提示词正文;留空用服务端的默认正文。支持 %n(第几次)、%max(上限)、%reason(原因)。
	// 开头的「【系统唤醒 …】」由服务端固定加上;正文里不能有 shell 特殊字符(见 GuardPromptUnsafe)。
	WakePrompt string `json:"wake_prompt,omitempty"`
	// ExitEndsSession 为 true 时启动行使用 exec 包装命令,命令退出即会话结束(默认 false)。
	ExitEndsSession bool `json:"exit_ends_session,omitempty"`
	// Headless 是「非交互唤醒」(#113 M3.4,默认关闭):会话已经结束、你又点了「非交互唤醒」时,
	// Hub 经这台主机的执行通道运行一次 `agent -p --resume <对话编号> …`,不打开终端。
	Headless *HeadlessWake `json:"headless,omitempty"`
}

LauncherGuard 是终端启动器预设的「会话守护」配置(D-214)。

它只描述「怎么判断、怎么唤醒」,不会让任何东西自动运行:唤醒是人在界面里点一下之后, 由浏览器把一句固定的提示词输入到会话里(会话已经结束时,按 ResumeCommand 重新拉起再输入)。

func (LauncherGuard) EffectiveSilence

func (g LauncherGuard) EffectiveSilence() time.Duration

EffectiveSilence 返回实际生效的停摆判定时长。

type MigrationItem

type MigrationItem struct {
	DocID      uint   `json:"doc_id"`
	WorkflowID string `json:"workflow_id"`
	FromPath   string `json:"from_path"`
	ToPath     string `json:"to_path"`
	Title      string `json:"title"`
	Reason     string `json:"reason,omitempty"` // 空 = 路径不变;sheet | conflict(与 MigrationMove 同义)
}

MigrationItem 是一篇待并入项目的文档的去向(路径不变的也在内)。

Moves 只列「要改路径」的,看不出其余文档是谁;Items 把每一篇都列出来——用户确认迁移前要看清「每篇文档去哪」, 知识库页也靠它在迁移完成前继续列出这些还没并入的文档,不让它们从入口上消失(#131)。

type MigrationMove

type MigrationMove struct {
	DocID      uint   `json:"doc_id"`
	WorkflowID string `json:"workflow_id"`
	FromPath   string `json:"from_path"`
	ToPath     string `json:"to_path"`
	Reason     string `json:"reason"` // sheet | conflict
}

MigrationMove 是一篇文档的去向。

type MigrationReport

type MigrationReport struct {
	ProjectID   uint            `json:"project_id"`
	Workflows   []string        `json:"workflows"`
	Docs        int             `json:"docs"`                  // 涉及的、尚未归入项目的文档数
	Assigned    int             `json:"assigned"`              // 其中原路径不变直接归入的
	Moves       []MigrationMove `json:"moves"`                 // 需要改路径的
	Items       []MigrationItem `json:"items"`                 // 全部待迁移的文档(= Docs 篇,含路径不变的);不参与哈希
	Already     int             `json:"already"`               // 已经在项目里的文档数
	Unplaceable []string        `json:"unplaceable,omitempty"` // 改路径后仍不合法(太长等)而跳过的文档说明
	Hash        string          `json:"hash"`
	Applied     bool            `json:"applied"`
}

MigrationReport 是迁移报告(dry-run 与确认后都用这个结构)。

type ModeInfo

type ModeInfo struct {
	WorkflowID string
	Row        model.WorkflowMode // 没有行时只有 WorkflowID 有值
	State      asyncmode.State
	HookSeen   time.Time // 最近一次见到该工作流的 hook;零值表示没见过(落库节流,重启后恢复,见 RestoreHookSeen)
	// Profile 只在开启过异步的工作流上解析(回执里的 auth: 行要用);
	// 没开启过的工作流不付这次查询的代价,也不需要它——界面要展示默认档位时自己取。
	Profile *model.AuthProfile
}

ModeInfo 是某个工作流此刻的异步对话状态:用户的开关、有效模式的判定、选用的档位。

func (ModeInfo) Signature

func (m ModeInfo) Signature() string

Signature 是「智能体该知道的模式状态」的签名(模式、降级原因、实际生效的档位及其内容);从未开启过为空串。

type ModePatch

type ModePatch struct {
	Enabled   *bool
	ProfileID *uint // 0 表示跟随默认档位
}

ModePatch 是修改工作流异步状态的入参:只改非 nil 的字段。

type ModuleInput

type ModuleInput struct {
	Path            string
	Title           string
	Description     string
	OwnerIdentityID uint
}

ModuleInput 新建 / 修改模块。

type ModulePageView

type ModulePageView struct {
	Module     model.ProjectModule   `json:"module"`
	Children   []model.ProjectModule `json:"children"`
	OwnerLabel string                `json:"owner_label,omitempty"`
	Index      *DocBrief             `json:"index,omitempty"`  // modules/<m>/index.md
	Design     *DocBrief             `json:"design,omitempty"` // modules/<m>/design.md
	Decisions  []DocBrief            `json:"decisions"`
	Artifacts  []DocBrief            `json:"artifacts"` // 渲染类型不是 md 的
	Docs       []DocBrief            `json:"docs"`      // 其余
	Recent     []DocBrief            `json:"recent"`
	Tasks      []ModuleTask          `json:"tasks"`
}

ModulePageView 是模块页:总述 + 设计 + 决策 + 相关任务 + 最近修订 + 渲染型文档 + 负责人。

type ModuleTask

type ModuleTask struct {
	WorkflowID string `json:"workflow_id"`
	Seq        int    `json:"seq"`
	Title      string `json:"title"`
	State      string `json:"state"`
}

ModuleTask 是模块页里的相关任务(按名称与任务看板的模块对齐,设计稿 06 §3.2;任务本身不动)。

type PostGroupInput

type PostGroupInput struct {
	ConversationID string
	SenderKind     string   // human | workflow
	SenderRef      string   // GroupHumanRef | 工作流编号
	Body           string   //
	Mentions       []string // 工作流编号 / all / human
	ReplyTo        string   // m:<消息 id>
	IdemKey        string   // Agent 重试保护;人发的不用
	// 下面两个只用来拼投递给对方的提示前缀。
	SenderLabel   string // Agent 的身份标签
	SenderProject string // Agent 所在项目(目录最后一段即可)
}

PostGroupInput 是发一条群消息的入参。

type PostGroupResult

type PostGroupResult struct {
	Message        *model.ChatMessage
	Group          *model.Conversation
	Recipients     []string // 被扔进收件箱的工作流
	Duplicate      bool     // 幂等键命中:没有新写入
	Cooling        bool     // 群在冷却中:消息只落库、没有投递
	CoolingStarted bool     // 这一条触发了冷却(要通知你)
	MentionsHuman  bool     // Agent 点名了你(或 @all):要穿透免打扰通知你
	HopDropped     bool     // 回复链过长:消息没有落库
}

PostGroupResult 是一次发送的结果。

type ProjectDocFilter

type ProjectDocFilter struct {
	WorkflowID      string
	Query           string
	Kinds           []string
	Statuses        []string
	Tag             string
	Prefix          string
	Limit           int
	IncludeArchived bool
	// 项目范围(#114):ProjectID > 0 时按项目取(跨该项目的所有工作流),此时 WorkflowID 被忽略。
	ProjectID       uint
	ModulePath      string // 模块路径前缀(含子模块)
	OwnerIdentityID uint
	Render          string
	UpdatedAfter    time.Time
	// OmitBody:列表只要元数据(目录树、索引、选择器)时置 true,SQL 不再把正文列读出来(#177:正文是这张表最重的一列,
	// 每次开页面列表都带着全文,生产上一个工作流的文档列表解压后 383 KB)。有 Query 过滤时仍要读正文来打分,此时本项不生效,
	// 查完由调用方自己清空正文(见 api.ListProjectDocs)。返回的 Body 为空串,不代表文档是空的。
	OmitBody bool
}

ProjectDocFilter 列表筛选。

type ProjectDocInput

type ProjectDocInput struct {
	WorkflowID string
	Path       string
	Title      string
	Kind       string
	Status     string
	Tags       []string
	Body       string
	Summary    string
	// 项目知识库(#114):空 = 不绑定模块 / 默认渲染。模块必须已在项目里建立。
	ModulePath string
	Render     string
}

ProjectDocInput 新建文档。

type ProjectDocPatch

type ProjectDocPatch struct {
	Title       *string
	Kind        *string
	Status      *string
	Tags        *[]string
	Body        *string
	Path        *string
	ModulePath  *string // 空串 = 解除模块绑定
	Render      *string
	Summary     string
	ExpectedRev int // 0 = 不校验
}

ProjectDocPatch 更新文档。

type ProjectDocSaveResult

type ProjectDocSaveResult struct {
	Doc       *model.ProjectDoc
	Changed   bool
	Unchanged bool
	Warnings  []string
}

ProjectDocSaveResult 保存结果。

type ProjectInput

type ProjectInput struct {
	Slug        string
	Name        string
	Description string
	ACLMode     string // 空 = audit
}

ProjectInput 新建项目。

type ProjectPatch

type ProjectPatch struct {
	Name        *string
	Description *string
	ACLMode     *string
}

ProjectPatch 修改项目。

type ProjectSearchFilter

type ProjectSearchFilter struct {
	ProjectID       uint
	Query           string
	ModulePath      string
	Kinds           []string
	Statuses        []string
	Tag             string
	OwnerIdentityID uint
	Render          string
	UpdatedAfter    time.Time
	Limit           int
}

ProjectSearchFilter 项目范围搜索的条件。

type ProjectSearchHit

type ProjectSearchHit struct {
	docs.SearchHit
	DocID      uint      `json:"doc_id"`
	WorkflowID string    `json:"workflow_id"`
	ModulePath string    `json:"module_path,omitempty"`
	Kind       string    `json:"kind"`
	Status     string    `json:"status"`
	Render     string    `json:"render,omitempty"`
	UpdatedAt  time.Time `json:"updated_at"`
}

ProjectSearchHit 是一条项目范围的命中(在单工作流命中的基础上带上归属信息,让界面能直接打开)。

type ProjectStats

type ProjectStats struct {
	Dirs      int `json:"dirs"`
	Modules   int `json:"modules"`
	Docs      int `json:"docs"`
	Workflows int `json:"workflows"`
}

ProjectStats 是项目的几个计数,给列表与详情用。

type ProjectSuggestion

type ProjectSuggestion struct {
	HostName         string   `json:"host_name"`
	ProjectDirectory string   `json:"project_directory"`
	SuggestedName    string   `json:"suggested_name"`
	SuggestedSlug    string   `json:"suggested_slug,omitempty"`
	Workflows        []string `json:"workflows"`
	Docs             int      `json:"docs"`
}

ProjectSuggestion 是一个「待确认的项目建议」:一个还没有归属项目的(主机,目录),以及落在那里的工作流与文档数。

type QueueFeedbackInput

type QueueFeedbackInput struct {
	WorkflowID       string               `json:"workflow_id"`
	HostName         string               `json:"host_name,omitempty"`
	ProjectDirectory string               `json:"project_directory,omitempty"`
	ResponseText     string               `json:"response_text"`
	UserMessages     []string             `json:"user_messages,omitempty"`
	Images           []model.SessionImage `json:"images,omitempty"`
	Kind             string               `json:"kind,omitempty"` // append(默认)| answer(确认项答复,不并入 interactive_feedback 秒回)
}

QueueFeedbackInput 是 Web 上追加一条消息的入参。

type RebindRequest

type RebindRequest struct {
	WorkflowID string
	ToDir      string
	ToHost     string
}

RebindRequest 描述一次改绑:目标目录必填,目标主机为空表示不改主机。

type RebindResult

type RebindResult struct {
	Before         WorkflowBinding `json:"before"`
	After          WorkflowBinding `json:"after"`            // 预演时等于 Before
	TargetDir      string          `json:"target_dir"`       // 规整后的目标目录
	TargetHost     string          `json:"target_host"`      // 规整后的目标主机(空 = 不改)
	SessionsToMove int64           `json:"sessions_to_move"` // 需要改写(预演)或已改写(执行)的会话行数
	QueuedToMove   int64           `json:"queued_to_move"`
	Applied        bool            `json:"applied"`
}

RebindResult 是一次改绑(或预演)的结果。

func (*RebindResult) Noop

func (r *RebindResult) Noop() bool

Noop 表示该工作流已经绑定在目标上,无需任何改写。

type ReplyRef

type ReplyRef struct {
	Session model.FeedbackSession
	// Turn 是它在工作流里按创建时间数的轮次序号(从 1 开始,与界面上的「第 N 轮」一致);
	// 进度通知不占轮次,为 0。
	Turn int
}

ReplyRef 是一个哈希解析出的会话。

func (ReplyRef) IsNotice

func (r ReplyRef) IsNotice() bool

IsNotice 报告这条是不是异步模式下的进度气泡(而不是一轮汇报)。

type ReplyWindow

type ReplyWindow = asyncmode.WindowState

ReplyWindow 是回复窗口此刻的状态(已按任务情况对齐过)。

type RetractionEvent

type RetractionEvent struct {
	ID          uint      `json:"id"`
	RetractedAt time.Time `json:"retracted_at"`
	Read        bool      `json:"read"` // 撤回前它读到过全文;false 表示只是被 hook / 提示行提醒过
}

RetractionEvent 是「智能体知道的追加后来被用户撤回了」的一条记录:只有编号与时间,不含正文(#199)。

type RevokedFeedbackResult

type RevokedFeedbackResult struct {
	SessionID    string               `json:"session_id,omitempty"`
	WorkflowID   string               `json:"workflow_id,omitempty"`
	QueuedID     uint                 `json:"queued_id,omitempty"`
	ResponseText string               `json:"response_text"`
	UserMessages []string             `json:"user_messages"`
	Images       []model.SessionImage `json:"images"`
	// Delivered:撤回的是一条智能体已经读取过的追加(收件箱),会在它下次读取时被告知忽略。
	Delivered bool `json:"delivered,omitempty"`
	// AgentNotified:撤回时智能体已经知道这条追加存在(读取过全文,或被 hook / 提示行提醒过),它会被告知忽略这一条(#199)。
	// 比 Delivered 宽:只被提醒过、还没读的也算;界面据此提示「已撤回,会告知忽略」。
	AgentNotified bool `json:"agent_notified,omitempty"`
}

type RunFilter

type RunFilter struct {
	Target       string
	ThreadKey    string
	CredentialID uint
	// CredentialName 与 Thread 按调用方名字与线程标签精确匹配(内部身份没有凭据编号,靠名字与标签认领自己的运行)。
	CredentialName string
	Thread         string
	States         []string
	BeforeID       uint
	Limit          int
}

RunFilter 是模型运行列表的过滤条件。

type SSHCheck

type SSHCheck struct {
	At          time.Time
	OK          bool
	Err         string // 已净化、不含凭据
	KeyMismatch bool   // 主机密钥与固定值不一致:置位后保持,直到管理员重新确认指纹
	Hostname    string
	OS          string
	Arch        string
	// TermOnly 非 nil 时(仅成功的检查)刷新「只能当人工终端用」标记:目标环境可能被重装成了别的系统。
	TermOnly *bool
}

SSHCheck 是一次连接尝试的结果。

type SSHConnUpdate

type SSHConnUpdate struct {
	Addr        *string
	User        *string
	Auth        *string
	Secret      *string // 已密封
	HostKeyType *string
	HostKey     *string
	Fingerprint *string
	KeyState    *string
	Error       *string // 最近一次失败的原因;重新固定主机密钥时用它清除旧的错误
	Gateway     *string // 网关主机的机器码;空串表示改为由 Hub 直连
	TermOnly    *bool   // 经网关接入的主机是否只能当人工终端用(探测不出 POSIX 环境)
}

SSHConnUpdate 是对 SSH 主机连接信息的部分更新:nil 表示不改。

type SecuritySettings

type SecuritySettings struct {
	BruteForceProtection bool     `json:"bruteForceProtection"` // 是否开启反爆破保护
	MaxFailedAttempts    int      `json:"maxFailedAttempts"`    // 最大连续失败尝试次数 (默认 5)
	LockoutMinutes       int      `json:"lockoutMinutes"`       // 封禁时长 (分钟,默认 15)
	WhitelistIPs         []string `json:"whitelistIps"`         // 白名单 IP 列表
}

type Store

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

func New

func New(dbPath string) (*Store, error)

func (*Store) AckReports

func (s *Store) AckReports(ctx context.Context, projectID, taskID string, throughSequence int64) (*model.AckSummary, error)

func (*Store) ActivateCredential

func (s *Store) ActivateCredential(ctx context.Context, id uint) error

ActivateCredential 启用凭据(OAuth 授权码首次兑换后)。

func (*Store) ActiveGrantsFor

func (s *Store) ActiveGrantsFor(ctx context.Context, projectID, identityID uint, groupRefs []string) ([]acl.Grant, error)

ActiveGrantsFor 给判定函数用:这个身份(以及它所在的群)在项目里有效的授权。

func (*Store) ActiveGrantsForCaller

func (s *Store) ActiveGrantsForCaller(ctx context.Context, projectID, identityID uint, workflowID string) ([]acl.Grant, error)

ActiveGrantsForCaller 在 ActiveGrantsFor 的基础上补上调用方所在的群(群共享授权)。

func (*Store) AddArtifactComment

func (s *Store) AddArtifactComment(ctx context.Context, in ArtifactCommentInput) (*model.ArtifactComment, error)

AddArtifactComment 新增一条评论。

func (*Store) AddAuditEvent

func (s *Store) AddAuditEvent(ctx context.Context, in AuditInput) (bool, error)

AddAuditEvent 写一条审计;返回是否真的写入(被去重则为 false)。

func (*Store) AddConversationEvent

func (s *Store) AddConversationEvent(ctx context.Context, ev model.ConversationEvent) (*model.ConversationEvent, error)

AddConversationEvent 写一条会话系统事件。Text 是给人看的一句话(不超过 400 字,超出会被截断)。

func (*Store) AddGroupMembers

func (s *Store) AddGroupMembers(ctx context.Context, groupID, actor string, workflowIDs []string) error

AddGroupMembers 把工作流拉进群(只有你能做);已离开的成员重新加入时从现在起看消息。

func (*Store) AddProjectDir

func (s *Store) AddProjectDir(ctx context.Context, projectID uint, host, dir, branchHint string) (*model.ProjectDir, error)

AddProjectDir 把(主机,目录)归入项目。同一个目录已经在别的项目里 → 冲突并说明在哪个项目。

func (*Store) AddReport

func (s *Store) AddReport(ctx context.Context, input model.AddReportInput) (*model.ReportResult, error)

func (*Store) AdvanceConversationRead

func (s *Store) AdvanceConversationRead(ctx context.Context, conversationID, readerKind, readerRef string, ms, seq int64) (model.ConversationRead, error)

AdvanceConversationRead 把已读游标推到 (ms, seq):两个分量各自只增不减(多设备、乱序请求取最大值)。 返回推进之后的游标。ms、seq 传 0 表示该分量不动。

func (*Store) AdvanceGroupRead

func (s *Store) AdvanceGroupRead(ctx context.Context, groupID, readerKind, readerRef string, seq int64) error

AdvanceGroupRead 把某个读者在群里的已读游标推到 seq(只增不减)。

func (*Store) AgentCursorVersion

func (s *Store) AgentCursorVersion(ctx context.Context, workflowID string) string

AgentCursorVersion 返回工作流最近一个 Agent 会话报告的 cursor 版本(屏幕扫描器的版本闸门要用);不知道返回空串。 先看内存(hook 事件刚推进过的会话),再退到库里最近一行有版本的会话。

func (*Store) AgentLastActivity

func (s *Store) AgentLastActivity(workflowID string) (time.Time, bool)

AgentLastActivity 返回某个工作流的智能体最近一次调用 RelayMesh 的时间(服务重启后从头记)。

func (*Store) AgentLinkOf

func (s *Store) AgentLinkOf(ctx context.Context, workflowID string) AgentLink

AgentLinkOf 返回某个工作流的智能体最近的运行情况;内存里没有对话编号(比如刚重启过)时,用落库的那一份补上。

func (*Store) AnswerConfirmBatch

func (s *Store) AnswerConfirmBatch(ctx context.Context, workflowID string, items []ConfirmBatchItem, adoptRecommended bool) (*ConfirmBatchResult, error)

AnswerConfirmBatch 批量作答,整批原子:只要有一项不合格(不存在 / 已处理 / 选项非法 / 没有可采用的推荐 / L2), 整批都不落库,错误里一次列出全部问题。L2 项永远不进批量:不可逆的决定必须逐条确认。 adoptRecommended=true 时,没写选项的项取各自的推荐选项(单选取第一个、多选取全部)。

func (*Store) AnswerConfirmItem

func (s *Store) AnswerConfirmItem(ctx context.Context, workflowID, ref string, in ConfirmAnswerInput) (*model.ConfirmItem, error)

AnswerConfirmItem 单条作答。第二次作答(并发或重复点击)返回 409;作答与投递在同一事务里。

func (*Store) AppendTerminalAudit

func (s *Store) AppendTerminalAudit(ctx context.Context, e *model.TerminalAuditLog) error

AppendTerminalAudit 追加一条审计记录。

func (*Store) ApplyMigration

func (s *Store) ApplyMigration(ctx context.Context, projectID uint, expectHash string) (*MigrationReport, error)

ApplyMigration 确认迁移:重新计算计划,哈希与 dry-run 的不一致就拒绝;一致才在一个事务里落库。

func (*Store) ApplyWorkPlan

func (s *Store) ApplyWorkPlan(ctx context.Context, workflowID string, plan []WorkPlanNode, reorder bool) (*WorkPlanResult, error)

ApplyWorkPlan 把一份规划声明落到工作流所在任务板的规划树上(同一个项目的工作流共用一棵树):

  • 不存在的节点新建(追加在同级末尾),已存在的保持原位,所以重复提交同一份计划是幂等的;
  • 带 rename 的节点改名,带 remove 的节点移除(必须没有任务也没有剩余功能),description 不为空时更新说明;
  • reorder=true 时,计划里列出的同级节点按给定顺序排到前面(没列出的保持原有相对顺序,跟在后面);
  • 整个调用在一个事务里:任何一个节点不合法,整份计划都不生效。

func (*Store) ArchiveFeedbackSession

func (s *Store) ArchiveFeedbackSession(ctx context.Context, idOrWorkflow string) (*model.FeedbackSession, error)

func (*Store) ArchiveProject

func (s *Store) ArchiveProject(ctx context.Context, id uint) error

ArchiveProject 归档项目:目录归属保留,文档照常可读;只是从默认列表里消失。

func (*Store) ArchiveProjectDoc

func (s *Store) ArchiveProjectDoc(ctx context.Context, docID uint, actor DocActor) (*model.ProjectDoc, error)

ArchiveProjectDoc 归档(MCP delete 只归档)。

func (*Store) ArtifactDataDelete

func (s *Store) ArtifactDataDelete(ctx context.Context, docID uint, key string) (bool, error)

ArtifactDataDelete 删除一个键;返回是否真的删了。

func (*Store) ArtifactDataGet

func (s *Store) ArtifactDataGet(ctx context.Context, docID uint, key string) (*model.ArtifactData, error)

ArtifactDataGet 读一个键;不存在返回 NotFound。

func (*Store) ArtifactDataList

func (s *Store) ArtifactDataList(ctx context.Context, docID uint) ([]model.ArtifactData, error)

ArtifactDataList 列出一篇文档的全部键,按键名排序。

func (*Store) ArtifactDataSet

func (s *Store) ArtifactDataSet(ctx context.Context, in ArtifactDataSetInput) (*model.ArtifactData, error)

ArtifactDataSet 写一个键(不存在则新建),校验 JSON 合法、总量与键数上限。

func (*Store) AsyncWindowTimes

func (s *Store) AsyncWindowTimes(ctx context.Context) (add, slice time.Duration)

AsyncWindowTimes 返回全局设置里的「每条新消息加多久」与「单次计时器最长等多久」(没设过用默认值)。

func (*Store) BackfillDecisionConfirmItems

func (s *Store) BackfillDecisionConfirmItems(ctx context.Context)

BackfillDecisionConfirmItems 启动时给「升级前就存在的文档」补上决策卡对应的确认项(第一波只解析展示,没有确认项)。 幂等,对已经同步过的文档不写库;单篇失败只记日志,不拖垮启动。

func (*Store) BackfillHiddenOAuthCredentialTokens

func (s *Store) BackfillHiddenOAuthCredentialTokens(ctx context.Context) error

BackfillHiddenOAuthCredentialTokens 将可预测的 rm-oauth-internal-* 令牌重写为随机值(幂等)。

func (*Store) BeatReplyWindow

func (s *Store) BeatReplyWindow(ctx context.Context, workflowID string, now time.Time) (ReplyWindow, error)

BeatReplyWindow 记一次输入心跳:窗口走动中时,把距上一次心跳的间隔(不超过新鲜期)加进窗口,等于暂停倒计时。 暂停中(有任务)的窗口本来就不走,心跳不改动它。

func (*Store) BoardKeyOf

func (s *Store) BoardKeyOf(ctx context.Context, workflowID string) (string, error)

BoardKeyOf 返回工作流现在使用的板(见 boardKeyOn)。

func (*Store) BoardWorkflowIDs

func (s *Store) BoardWorkflowIDs(ctx context.Context, boardKey string) ([]string, error)

BoardWorkflowIDs 列出一张板上能被指派的工作流(#175 B2b,详情里「指派」下拉用): 项目板 = 项目里的全部工作流(最近一次汇报会话的目录落在项目目录里的)加上已经在这张板上建过任务的工作流 (它们的会话目录后来即使被移出项目,任务仍在板上,按「粘性归板」仍然属于这张板,checkAssignee 也认); 独立板没有可指派的对象,返回空列表。

func (*Store) CancelFeedbackSession

func (s *Store) CancelFeedbackSession(ctx context.Context, idOrWorkflow string) (*model.FeedbackSession, error)

func (*Store) CheckFeedback

func (s *Store) CheckFeedback(ctx context.Context, input model.CheckFeedbackInput) (*model.CheckFeedbackResult, error)

func (*Store) ClaimConversation

func (s *Store) ClaimConversation(ctx context.Context, workflowID, conv string, until, now time.Time) ([]string, error)

ClaimConversation 认领一个对话:Hub 发起的非交互运行清楚自己在跑哪个对话(新开对话从输出里学到,续聊的在命令里), 也清楚这次运行是替哪个工作流跑的——而 hook 汇报带的工作流来自项目目录里的 .cursor/relaymesh.json, 同一个仓库的多个工作树共用一份配置时,它写的常常是另一个工作流。认领到 until 之前,这个对话的一切汇报 (智能体状态会话、旧链路的对话编号与活动时间)都归 workflowID,不管汇报自己带的是哪个工作流。

认领的同时把已经建在别的工作流名下的状态会话(库里与内存里)搬过来,并清掉别的工作流上记着这个对话编号的旧「续聊目标」 (见 dropForeignAgentLinks);返回会话原来所在的工作流(去重,不含 workflowID),调用方据此通知 Web 重新取一遍。 同一个认领再来一次(运行监视每轮都会续期,收尾时缩短到收尾期)只改到期时间,不动库。空的工作流 / 对话编号、格式不对的对话编号一律忽略。

func (*Store) ClearAgentScreen

func (s *Store) ClearAgentScreen(workflowID string) (wasApproval bool)

ClearAgentScreen 在托管终端消失(会话退出、主机离线)时清掉信号。返回之前是否在审批等待。

func (*Store) ClearReplyWindow

func (s *Store) ClearReplyWindow(ctx context.Context, workflowID string) error

ClearReplyWindow 用户回复了:窗口清零(走动中的和攒着的都清)。没有窗口时什么都不做。

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying sql.DB connection.

func (*Store) CloseTask

func (s *Store) CloseTask(ctx context.Context, projectID, taskID string, expectedRevision int64, idempotencyKey string) (*model.MutationResult, error)

func (*Store) CompactWorkItems

func (s *Store) CompactWorkItems(ctx context.Context, now time.Time) (int, error)

CompactWorkItems 压缩关闭已久的任务:时间线与「最新进度」不再保留,没有结论的从进度里截一段当结论。 标题 / 类型 / 标签 / 日期 / 结论 / 引用 / 关联会话 都保留。可重复执行,返回本次压缩的任务数。

func (*Store) ConfirmView

func (s *Store) ConfirmView(ctx context.Context, item *model.ConfirmItem) (model.ConfirmItemView, error)

ConfirmView 是 ConfirmViews 的单条版本。

func (*Store) ConfirmViews

func (s *Store) ConfirmViews(ctx context.Context, items []model.ConfirmItem) ([]model.ConfirmItemView, error)

ConfirmViews 把确认项转成对外视图,并给绑定了文档的项补上文档路径与标题。

func (*Store) ConversationOwner

func (s *Store) ConversationOwner(conv string, now time.Time) string

ConversationOwner 返回此刻认领这个对话的工作流(没有人认领,或认领已经过期就是空串)。

func (*Store) ConversationReadEpoch

func (s *Store) ConversationReadEpoch(ctx context.Context) (int64, error)

ConversationReadEpoch 返回已读纪元(Unix 毫秒);第一次调用时把当前时刻记下来。

func (*Store) CountAgentMessagesBetween

func (s *Store) CountAgentMessagesBetween(ctx context.Context, workflowID string, from, to time.Time) (int, error)

CountAgentMessagesBetween 数一个工作流里 Agent 在 [from, to) 时间窗内发的消息条数(口径同 CountUnreadAgentMessages,含任务进展); to 为零值表示不设上界。用来回答「某一次运行期间智能体有没有说过话」:窗口外(比如运行结束之后另一个会话发的)不算。

func (*Store) CountBoardWorkItemsByState

func (s *Store) CountBoardWorkItemsByState(ctx context.Context, workflowID string) (map[string]int, error)

CountBoardWorkItemsByState 统计工作流所在任务板的各状态任务数,与按这个工作流列出的任务清单口径一致。

func (*Store) CountFeedbackSessionsByWorkflow

func (s *Store) CountFeedbackSessionsByWorkflow(ctx context.Context, workflowIDs []string) (map[string]int, error)

CountFeedbackSessionsByWorkflow 数每个工作流在库里一共有多少行会话(含已归档),键是工作流编号,没有行的工作流不出现在结果里。 侧栏「N 轮」徽标要的是整个工作流的总数,而不是列表里恰好带出的行数;按工作流分组一次查出(走 idx_fs_wf_created 覆盖索引,不翻正文)。

func (*Store) CountOAuthClients

func (s *Store) CountOAuthClients(ctx context.Context) (int64, error)

func (*Store) CountOpenArtifactComments

func (s *Store) CountOpenArtifactComments(ctx context.Context, docID uint) int

CountOpenArtifactComments 是未解决评论数(文档列表角标用)。

func (*Store) CountPendingConfirms

func (s *Store) CountPendingConfirms(ctx context.Context, workflowID string) (int, error)

CountPendingConfirms 统计待处理的确认项数。

func (*Store) CountPendingConfirmsByWorkflow

func (s *Store) CountPendingConfirmsByWorkflow(ctx context.Context, workflowIDs []string) (map[string]int, error)

CountPendingConfirmsByWorkflow 一次查出多个工作流各自待处理的确认项数(侧栏会话卡用,避免逐个工作流查询;#159)。 返回表里没有的工作流表示 0 条待处理;传入空列表直接返回空表。

func (*Store) CountProjectDocs

func (s *Store) CountProjectDocs(ctx context.Context, workflowID string) (int, error)

CountProjectDocs 工作流内文档数。

func (*Store) CountRecentNotices

func (s *Store) CountRecentNotices(ctx context.Context, workflowID string, since time.Time) (int, error)

CountRecentNotices 统计某个工作流自 since 以来发布的进度通知条数,给发布端做频率上限用。

func (*Store) CountSSHHostsViaGateway

func (s *Store) CountSSHHostsViaGateway(ctx context.Context, gateway string) (int64, error)

CountSSHHostsViaGateway 统计经某台网关主机接入的 SSH 主机数量(删除网关之前用来拦截)。

func (*Store) CountUnreadAgentMessages

func (s *Store) CountUnreadAgentMessages(ctx context.Context, workflowID string, afterMs int64, updatesSince time.Time, includeUpdates bool) (int, error)

CountUnreadAgentMessages 数一个工作流里 Agent 在 afterMs(Unix 毫秒)之后发的消息条数(系统行不计): 阻塞式汇报、进度气泡、提问 / 计划卡,以及(includeUpdates 时)任务进展。

func (*Store) CountVisibleCredentials

func (s *Store) CountVisibleCredentials(ctx context.Context) (int64, error)

func (*Store) CountWorkItemsByState

func (s *Store) CountWorkItemsByState(ctx context.Context, workflowID string) (map[string]int, error)

CountWorkItemsByState 统计各状态的任务数(workflowID 为空 = 全部工作流)。 按「创建者工作流」数:这是某个智能体自己的任务量(会话守护、工作流模式用); 要与任务清单对得上(整张板)用 CountBoardWorkItemsByState。

func (*Store) CountWorkModules

func (s *Store) CountWorkModules(ctx context.Context, workflowID string) (int, error)

CountWorkModules 统计工作流所在任务板的模块 / 功能节点数。

func (*Store) CreateAuthProfile

func (s *Store) CreateAuthProfile(ctx context.Context, in AuthProfileInput) (*model.AuthProfile, error)

CreateAuthProfile 新增一档。名称不能重复,总数有上限;新档位不是默认。

func (*Store) CreateConfirmItem

func (s *Store) CreateConfirmItem(ctx context.Context, in ConfirmCreateInput) (item *model.ConfirmItem, created bool, err error)

CreateConfirmItem 创建一条确认项。created=false 表示命中了「同一问题仍在待处理」的去重,返回的是已有那条(智能体重试不会产生重复项)。

func (*Store) CreateCredential

func (s *Store) CreateCredential(ctx context.Context, cred *model.MCPCredential) error

func (*Store) CreateFeedbackSession

func (s *Store) CreateFeedbackSession(ctx context.Context, input CreateSessionInput) (*model.FeedbackSession, error)

func (*Store) CreateGrant

func (s *Store) CreateGrant(ctx context.Context, in GrantInput) (*model.ACLGrant, error)

CreateGrant 新增(或续期)一条授权:同一主体 + 范围已有有效授权时更新角色与有效期,不重复建。

func (*Store) CreateGroup

func (s *Store) CreateGroup(ctx context.Context, in CreateGroupInput) (*model.Conversation, error)

CreateGroup 建一个群:你是 owner,Members 是初始成员,并写入系统行。

func (*Store) CreateHiddenOAuthCredential

func (s *Store) CreateHiddenOAuthCredential(ctx context.Context, grantID uint, name string, cred *model.MCPCredential) error

func (*Store) CreateNoticeSession

func (s *Store) CreateNoticeSession(ctx context.Context, input CreateSessionInput) (*model.FeedbackSession, error)

CreateNoticeSession 发布一条不阻塞的进度 / 回答气泡(异步对话模式下 interactive_feedback 的 wait:false)。

它与 CreateFeedbackSession 的区别,也是它不复用后者的原因:

  • 不取走收件箱里的追加(那是给「等待中的汇报」的秒回,notice 没有在等谁,取走就等于吞掉用户的话);
  • 不覆写已有的 pending 汇报,也不把历史上已完成但未消费的轮次批量标成已消费;
  • 一建就是 completed + 已被智能体消费 + 没有回复时间:界面上只有 AI 气泡,没有回复框。

workflow_id 必须给定且已被调用方核实(异步模式是按工作流开的,不存在「自动派生新工作流」的情形)。

func (*Store) CreateOAuthClient

func (s *Store) CreateOAuthClient(ctx context.Context, c *model.OAuthClient) error

func (*Store) CreateOAuthGrant

func (s *Store) CreateOAuthGrant(ctx context.Context, g *model.OAuthGrant) error

func (*Store) CreateProject

func (s *Store) CreateProject(ctx context.Context, in ProjectInput) (*model.Project, error)

func (*Store) CreateProjectDoc

func (s *Store) CreateProjectDoc(ctx context.Context, in ProjectDocInput, actor DocActor) (*ProjectDocSaveResult, error)

CreateProjectDoc 新建文档。

func (*Store) CreateSSHHost

func (s *Store) CreateSSHHost(ctx context.Context, h *model.TerminalHost) error

CreateSSHHost 创建一台 SSH 主机。调用方已经完成校验与凭据密封;这里只保证 类型正确、数量不超限、机器码不重复(重复返回 ErrTerminalHostExists,调用方可换一个再试)。

func (*Store) CreateTask

func (s *Store) CreateTask(ctx context.Context, input model.CreateTaskInput) (*model.Task, error)

func (*Store) CreateTerminalRun

func (s *Store) CreateTerminalRun(ctx context.Context, r *model.TerminalRun) error

CreateTerminalRun 写入一条新的运行记录。

func (*Store) CreateUserNorm

func (s *Store) CreateUserNorm(ctx context.Context, norm *model.UserNorm) error

func (*Store) CreateWebWorkflow

func (s *Store) CreateWebWorkflow(ctx context.Context, input CreateWebWorkflowInput) (*CreateWebWorkflowResult, error)

CreateWebWorkflow 新建一个工作流:落一行占位会话 + 写入自定义标题,返回占位会话与启动提示词。 工作流编号已存在(给定编号撞了)返回冲突错误;名字或编号不合规返回入参错误。

func (*Store) CreateWorkItem

func (s *Store) CreateWorkItem(ctx context.Context, in WorkItemInput, actor WorkActor) (*WorkItemResult, error)

CreateWorkItem 新建任务。

func (*Store) CreateWorkModule

func (s *Store) CreateWorkModule(ctx context.Context, workflowID string, parentID uint, name, description string) (*model.WorkModule, error)

CreateWorkModule 在规划树上新建一个模块(parentID=0)或功能(parentID=某个顶层模块),排在同级最后。

func (*Store) DB

func (s *Store) DB() *gorm.DB

func (*Store) DeactivateCredential

func (s *Store) DeactivateCredential(ctx context.Context, id uint) error

func (*Store) DecisionConfirmsByKey

func (s *Store) DecisionConfirmsByKey(ctx context.Context, docID uint) (map[string]*model.ConfirmItem, error)

DecisionConfirmsByKey 返回文档内各决策 id 对应的最新确认项(序号最大的那条)。

func (*Store) DefaultAllowHostCodes

func (s *Store) DefaultAllowHostCodes(ctx context.Context) ([]string, error)

DefaultAllowHostCodes 返回「对新建模型令牌预先授予」的主机机器码:已启用、默认态为 allow,按机器码排序。

func (*Store) DefaultAuthProfile

func (s *Store) DefaultAuthProfile(ctx context.Context) (*model.AuthProfile, error)

DefaultAuthProfile 返回默认档位;没有标记默认的(不应出现)就取排序最靠前的一档并顺手修正标记。

func (*Store) DeleteAllDraftImages

func (s *Store) DeleteAllDraftImages(ctx context.Context, workflowID string) (int64, error)

DeleteAllDraftImages 删除一个工作流的全部草稿图片(草稿被整体销毁时)。

func (*Store) DeleteAuthProfile

func (s *Store) DeleteAuthProfile(ctx context.Context, id uint) error

DeleteAuthProfile 删除一档。默认档位不能删;选用了这一档的工作流改回「跟随默认」(profile_id = 0)。

func (*Store) DeleteCredential

func (s *Store) DeleteCredential(ctx context.Context, id uint) error

func (*Store) DeleteDraftImages

func (s *Store) DeleteDraftImages(ctx context.Context, workflowID string, keys []string) (int64, error)

DeleteDraftImages 删除一个工作流里指定的草稿图片,返回实际删除的张数。

func (*Store) DeleteFeedbackSession

func (s *Store) DeleteFeedbackSession(ctx context.Context, sessionID string) (*model.FeedbackSession, error)

DeleteFeedbackSession 物理删除会话记录,维护工作流状态并级联清理(D-159)

func (*Store) DeleteNote

func (s *Store) DeleteNote(ctx context.Context, id uint) error

func (*Store) DeleteOAuthAccessTokensForGrant

func (s *Store) DeleteOAuthAccessTokensForGrant(ctx context.Context, grantID uint) error

func (*Store) DeleteProjectModule

func (s *Store) DeleteProjectModule(ctx context.Context, projectID uint, path string) error

DeleteProjectModule 删除模块(及其子模块);挂在这些模块上的文档不删除,只是解除模块绑定。

func (*Store) DeleteTerminalArchivesOfHost

func (s *Store) DeleteTerminalArchivesOfHost(ctx context.Context, machineCode string) error

DeleteTerminalArchivesOfHost 删除一台主机上人工会话的归档记录(删除主机时调用;key 以「机器码:」开头)。

func (*Store) DeleteTerminalHost

func (s *Store) DeleteTerminalHost(ctx context.Context, machineCode string) (bool, error)

DeleteTerminalHost 删除记录,返回是否删除了记录。

func (*Store) DeleteTerminalLauncher

func (s *Store) DeleteTerminalLauncher(ctx context.Context, id string) ([]TerminalLauncher, TerminalLauncher, error)

DeleteTerminalLauncher 按编号删除一条预设;返回删除后的全部预设,以及被删掉的那一条(用于审计)。

func (*Store) DeleteTerminalLostDismissalsOfHost

func (s *Store) DeleteTerminalLostDismissalsOfHost(ctx context.Context, machineCode string) error

DeleteTerminalLostDismissalsOfHost 删除一台主机的全部忽略记录(删除主机时调用)。

func (*Store) DeleteTerminalRunsOfHost

func (s *Store) DeleteTerminalRunsOfHost(ctx context.Context, machineCode string) error

DeleteTerminalRunsOfHost 删除一台主机的全部运行元数据(删除主机时调用)。

func (*Store) DeleteTerminalSessionsOfHost

func (s *Store) DeleteTerminalSessionsOfHost(ctx context.Context, machineCode string) error

DeleteTerminalSessionsOfHost 删除一台主机的全部会话索引(删除主机时调用)。

func (*Store) DeleteUserNorm

func (s *Store) DeleteUserNorm(ctx context.Context, name string) error

func (*Store) DeleteWorkItem

func (s *Store) DeleteWorkItem(ctx context.Context, id uint) (*model.WorkItem, error)

DeleteWorkItem 删除任务及其时间线与会话关联;它的子任务变成顶层任务。

func (*Store) DeleteWorkModule

func (s *Store) DeleteWorkModule(ctx context.Context, id uint) (*WorkModuleDeleteResult, error)

DeleteWorkModule 删除模块(顶层模块连同它的功能)。任务不会被删: 属于被删节点的任务回到它的上一级;顶层模块被删时变成未归类。

func (*Store) DeleteWorkflowDraft

func (s *Store) DeleteWorkflowDraft(ctx context.Context, workflowID string) error

DeleteWorkflowDraft 删除工作流草稿数据

func (*Store) DismissConfirmItem

func (s *Store) DismissConfirmItem(ctx context.Context, workflowID, ref, reason string) (*model.ConfirmItem, error)

DismissConfirmItem 用户放弃一条待处理的确认项,并告诉智能体「不用再等它」。

func (*Store) DismissTerminalLost

func (s *Store) DismissTerminalLost(ctx context.Context, machineCode string, sids []string, now time.Time) (int64, error)

DismissTerminalLost 忽略一台主机上的若干条「会话已不存在」提示,返回实际新增的条数 (重复忽略同一条不算变化,所以界面重复点击是安全的)。同时顺手清掉过期的忽略记录。

func (*Store) DocDecisionExportRows

func (s *Store) DocDecisionExportRows(ctx context.Context, doc *model.ProjectDoc) []docs.DecisionExportRow

DocDecisionExportRows 返回导出时要追加到文档末尾的「决策结果」表的行;没有决策围栏的文档返回 nil。

func (*Store) DocDecisionViews

func (s *Store) DocDecisionViews(ctx context.Context, doc *model.ProjectDoc, body string, historic bool) []confirm.DecisionView

DocDecisionViews 把文档正文里的决策围栏与确认项对齐,给网页和 MCP 读文档时用。 historic=true(看历史修订)时不挂确认项:历史版本里的决策不能作答,也不该显示「现在」的答复。 读确认项失败只记日志、退化为「没挂确认项」,不让一次读文档因此失败。

func (s *Store) DocLinks(ctx context.Context, doc *model.ProjectDoc) (*DocLinks, error)

DocLinks 解析一篇文档的出链与反链(解析 [path] 与相对 .md 链接,见 docs.ExtractLinks)。 解析范围:同一工作流的文档;文档属于项目时再加上同项目的其他文档(同路径时本工作流优先)。 不落库:文档数量有上限(每工作流 500、每项目 2000),按需扫描正文即可,也就不会有「索引与正文不一致」的问题。

func (*Store) EnsureEnvMCPCredential

func (s *Store) EnsureEnvMCPCredential(ctx context.Context, envToken string) (*model.MCPCredential, error)

EnsureEnvMCPCredential 确保环境变量 RELAYMESH_MCP_TOKEN 在数据库中存在对应的可管理凭据

func (*Store) ExtendReplyWindow

func (s *Store) ExtendReplyWindow(ctx context.Context, workflowID string, add time.Duration, now time.Time) (ReplyWindow, error)

ExtendReplyWindow 把工作流的回复窗口累加 add(封顶见 asyncmode.WindowMax)。 智能体手头有任务时只往「攒着的时间」里加(窗口不走);没有任务时从当前截止时间累加。 只更新已有的工作流行:没有行说明从未开启过异步,没有窗口可言。

func (*Store) FindAnchoredSessionByCommit

func (s *Store) FindAnchoredSessionByCommit(ctx context.Context, workflowID, commit string) (*model.FeedbackSession, error)

FindAnchoredSessionByCommit 在某工作流里按哈希找到带该锚点的最近一次会话。 哈希允许长短不一(互为前缀即视为同一提交),用于把胶囊的基准关联回具体交付。

func (*Store) FindCredentialByToken

func (s *Store) FindCredentialByToken(ctx context.Context, token string) (*model.MCPCredential, error)

func (*Store) FindOAuthAccessToken

func (s *Store) FindOAuthAccessToken(ctx context.Context, plainToken string) (*model.OAuthAccessToken, *model.OAuthGrant, *model.MCPCredential, error)

func (*Store) FindReplyRefs

func (s *Store) FindReplyRefs(ctx context.Context, workflowID, hash string, limit int) ([]ReplyRef, error)

FindReplyRefs 在一个工作流里按哈希(6~12 位前缀)找回复,旧的在前,最多 limit 条。 只在给定的工作流里找:别的工作流里哈希相同的会话不可见,不能靠引用窥探别的工作流。 哈希不合法或工作流为空时返回空,不报错。

func (*Store) FindTerminalRunByIdempotency

func (s *Store) FindTerminalRunByIdempotency(ctx context.Context, credentialID uint, key string) (*model.TerminalRun, error)

FindTerminalRunByIdempotency 按 (凭据, 幂等键) 查找已有运行;用于 terminal_exec 的重试去重。

func (*Store) GetAuthCredentials

func (s *Store) GetAuthCredentials(ctx context.Context) (*AuthCredentials, error)

GetAuthCredentials 获取数据库中持久化的账号密码

func (*Store) GetAuthCredentialsWithDB

func (s *Store) GetAuthCredentialsWithDB(ctx context.Context, db *gorm.DB) (*AuthCredentials, error)

GetAuthCredentialsWithDB 从指定 DB (支持事务) 获取数据库中持久化的账号密码

func (*Store) GetAuthProfile

func (s *Store) GetAuthProfile(ctx context.Context, id uint) (*model.AuthProfile, error)

GetAuthProfile 取一档;不存在返回 NotFound。

func (*Store) GetCheckpointByRevision

func (s *Store) GetCheckpointByRevision(ctx context.Context, workflowID string, revision int) (*model.WorkflowCheckpoint, error)

func (*Store) GetConfirmItemByRef

func (s *Store) GetConfirmItemByRef(ctx context.Context, workflowID, ref string) (*model.ConfirmItem, error)

GetConfirmItemByRef 取一条确认项(限定工作流,不能跨工作流读取)。

func (*Store) GetConversationRead

func (s *Store) GetConversationRead(ctx context.Context, conversationID, readerKind, readerRef string) (model.ConversationRead, error)

GetConversationRead 取一个读者在一个会话里的已读游标;还没有记录时返回零值(不报错)。

func (*Store) GetCredential

func (s *Store) GetCredential(ctx context.Context, id uint) (*model.MCPCredential, error)

func (*Store) GetCredentialIfVisible

func (s *Store) GetCredentialIfVisible(ctx context.Context, id uint) (*model.MCPCredential, error)

GetCredentialIfVisible 按 ID 读取非隐藏凭据;隐藏凭据返回 gorm.ErrRecordNotFound 语义。

func (*Store) GetCurrentFeedbackSession

func (s *Store) GetCurrentFeedbackSession(ctx context.Context, projectDir string) (*model.FeedbackSession, error)

func (*Store) GetDraftImage

func (s *Store) GetDraftImage(ctx context.Context, workflowID, key string) (*model.DraftImage, error)

GetDraftImage 读取一张草稿图片(含正文);不存在返回 nil, nil。

func (*Store) GetFeedbackRoundsByWorkflow

func (s *Store) GetFeedbackRoundsByWorkflow(ctx context.Context, workflowID string, limit int) ([]model.FeedbackSession, error)

GetFeedbackRoundsByWorkflow 与 GetSessionsByWorkflow 相同,但不含 notice 进度气泡: 检查点的「之后又多了几轮」「之后的用户反馈」按真正的汇报—回复轮次数,进度通知再多也不该让检查点显得过期。

func (*Store) GetFeedbackSession

func (s *Store) GetFeedbackSession(ctx context.Context, sessionID string) (*model.FeedbackSession, error)

func (*Store) GetGlobalAppSettings

func (s *Store) GetGlobalAppSettings(ctx context.Context) (*GlobalAppSettings, error)

GetGlobalAppSettings 获取强类型系统全局配置,含完备默认值

func (*Store) GetGlobalAppSettingsWithDB

func (s *Store) GetGlobalAppSettingsWithDB(ctx context.Context, db *gorm.DB) (*GlobalAppSettings, error)

GetGlobalAppSettingsWithDB 从指定 DB (支持事务 tx) 获取强类型系统全局配置

func (*Store) GetGrant

func (s *Store) GetGrant(ctx context.Context, projectID, grantID uint) (*model.ACLGrant, error)

GetGrant 取一条授权(限定项目)。

func (*Store) GetGroup

func (s *Store) GetGroup(ctx context.Context, groupID string) (*model.Conversation, error)

GetGroup 取一个群;不存在返回 not found。

func (*Store) GetGroupMember

func (s *Store) GetGroupMember(ctx context.Context, groupID, memberKind, memberRef string) (*model.ConversationMember, error)

GetGroupMember 取一个成员行(含已离开的)。

func (*Store) GetInboxConfig

func (s *Store) GetInboxConfig(ctx context.Context) InboxConfig

GetInboxConfig 读取收件箱开关;从未设置过时是全部打开。读不到库时按默认处理(宁可多提醒,不要把功能悄悄关掉)。

func (*Store) GetLatestAnchoredSession

func (s *Store) GetLatestAnchoredSession(ctx context.Context, workflowID, excludeSessionID string) (*model.FeedbackSession, error)

GetLatestAnchoredSession 返回某工作流里最近一次带交付锚点的会话(只读取轻量列)。 excludeSessionID 非空时跳过该会话(用于「与上一次比较」)。没有任何锚点时返回 (nil, nil)。

func (*Store) GetLatestCheckpoint

func (s *Store) GetLatestCheckpoint(ctx context.Context, workflowID string) (*model.WorkflowCheckpoint, error)

func (*Store) GetLatestWorkflowFeedbackSession

func (s *Store) GetLatestWorkflowFeedbackSession(ctx context.Context, workflowID string) (*model.FeedbackSession, error)

GetLatestWorkflowFeedbackSession 自动查找某工作流下最近的汇报会话(优先 pending 活跃轮次,其次最新轮次)。 notice 进度气泡不是「一轮对话」——它没有回复框、发布即完成——所以不在这里的候选之内: 守护、continue_feedback_session、Agent 存活判定都靠它找「智能体到底在等谁」,被 notice 顶替就会误判。

func (*Store) GetNote

func (s *Store) GetNote(ctx context.Context, id uint) (*model.WorkflowNote, error)

func (*Store) GetNoteByKey

func (s *Store) GetNoteByKey(ctx context.Context, workflowID, noteKey string) (*model.WorkflowNote, error)

func (*Store) GetNotifyPrefs

func (s *Store) GetNotifyPrefs(ctx context.Context) (notify.Prefs, error)

GetNotifyPrefs 读取通知偏好;从未设置过、或存下来的值已损坏时返回出厂默认。已 Normalize(过期的静音不再出现)。

func (*Store) GetNtfyConfig

func (s *Store) GetNtfyConfig(ctx context.Context) (ntfy.Config, error)

GetNtfyConfig 读取 ntfy 推送配置;从未设置过时返回关闭状态的默认值。已 Normalize。

func (*Store) GetOAuthClient

func (s *Store) GetOAuthClient(ctx context.Context, clientID string) (*model.OAuthClient, error)

func (*Store) GetOAuthGrant

func (s *Store) GetOAuthGrant(ctx context.Context, id uint) (*model.OAuthGrant, error)

func (*Store) GetOAuthGrantByRefreshHash

func (s *Store) GetOAuthGrantByRefreshHash(ctx context.Context, hash string) (*model.OAuthGrant, error)

func (*Store) GetOAuthPolicy

func (s *Store) GetOAuthPolicy(ctx context.Context) (model.OAuthPolicy, error)

func (*Store) GetProject

func (s *Store) GetProject(ctx context.Context, id uint) (*model.Project, error)

func (*Store) GetProjectDocByID

func (s *Store) GetProjectDocByID(ctx context.Context, id uint) (*model.ProjectDoc, error)

GetProjectDocByID 按主键读取。

func (*Store) GetProjectDocByRef

func (s *Store) GetProjectDocByRef(ctx context.Context, workflowID, ref string) (*model.ProjectDoc, error)

GetProjectDocByRef 按 path、seq 或 id 读取。

func (*Store) GetProjectDocInProject

func (s *Store) GetProjectDocInProject(ctx context.Context, projectID uint, ref string) (*model.ProjectDoc, error)

GetProjectDocInProject 在整个项目里按路径或文档编号(全局 id,可带前缀 d)取一篇文档。 项目内路径唯一(只对 project_id>0 的文档由应用层保证),所以按路径取到的是唯一一篇。

func (*Store) GetProjectDocRevision

func (s *Store) GetProjectDocRevision(ctx context.Context, docID uint, rev int) (*model.ProjectDocRevision, error)

GetProjectDocRevision 某一版。

func (*Store) GetProjectModule

func (s *Store) GetProjectModule(ctx context.Context, projectID uint, path string) (*model.ProjectModule, error)

GetProjectModule 取项目里的一个模块;不存在返回 nil, nil。

func (*Store) GetQueuedFeedback

func (s *Store) GetQueuedFeedback(ctx context.Context, id uint) (*model.QueuedFeedback, error)

GetQueuedFeedback 按编号取一条追加(含图片全文)。不存在时返回 (nil, nil)。

func (*Store) GetSessionsByWorkflow

func (s *Store) GetSessionsByWorkflow(ctx context.Context, workflowID string, limit int) ([]model.FeedbackSession, error)

func (*Store) GetSettings

func (s *Store) GetSettings(ctx context.Context) (map[string]any, error)

GetSettings 从数据库获取全局配置,若不存在返回默认 map

func (*Store) GetSettingsWithDB

func (s *Store) GetSettingsWithDB(ctx context.Context, db *gorm.DB) (map[string]any, error)

GetSettingsWithDB 从指定 DB (支持事务 tx) 获取全局配置

func (*Store) GetSystemFlag

func (s *Store) GetSystemFlag(ctx context.Context, key string) (bool, error)

GetSystemFlag 读取一个布尔系统开关(值 "1" 为真);不存在视为假。

func (*Store) GetTask

func (s *Store) GetTask(ctx context.Context, projectID, taskID string) (*model.Task, error)

func (*Store) GetTerminalGuardState

func (s *Store) GetTerminalGuardState(ctx context.Context) (GuardStateDoc, error)

GetTerminalGuardState 读取守护状态;从未保存过或存档损坏时返回空文档(不是 nil)。

func (*Store) GetTerminalHost

func (s *Store) GetTerminalHost(ctx context.Context, machineCode string) (*model.TerminalHost, error)

GetTerminalHost 按机器码读取主机,不存在返回 (nil, nil)。

func (*Store) GetTerminalPrefs

func (s *Store) GetTerminalPrefs(ctx context.Context) (TerminalPrefs, error)

GetTerminalPrefs 读取终端偏好;从未设置过时返回全部关闭的默认值。

func (*Store) GetTerminalRun

func (s *Store) GetTerminalRun(ctx context.Context, runID string) (*model.TerminalRun, error)

GetTerminalRun 按运行 ID 查询;不存在时返回 (nil, nil)。

func (*Store) GetTerminalSession

func (s *Store) GetTerminalSession(ctx context.Context, machineCode, sid string) (*model.TerminalSession, error)

GetTerminalSession 按主机与会话 ID 读取一行;不存在返回 (nil, nil)。

func (*Store) GetUserNorm

func (s *Store) GetUserNorm(ctx context.Context, name string) (*model.UserNorm, error)

func (*Store) GetWorkItem

func (s *Store) GetWorkItem(ctx context.Context, id uint) (*model.WorkItem, error)

GetWorkItem 读取任务详情:含最近的时间线(新的在前)与关联的会话。

func (*Store) GetWorkItemBySeq

func (s *Store) GetWorkItemBySeq(ctx context.Context, workflowID string, seq int) (*model.WorkItem, error)

GetWorkItemBySeq 按序号读取任务(智能体使用):序号在工作流所在的任务板内唯一(#175)。 同一个项目的工作流共用一套 #N;单工作流的板与按工作流取完全一致。 找不到时依次回落:显式合并时改过号的旧 (工作流, 序号) 别名,以及旧版本回滚期间写入、还没归板的行。

func (*Store) GetWorkModule

func (s *Store) GetWorkModule(ctx context.Context, id uint) (*model.WorkModule, error)

GetWorkModule 读取单个模块(含完整路径,不含任务汇总)。

func (*Store) GetWorkflowDraft

func (s *Store) GetWorkflowDraft(ctx context.Context, workflowID string) (*model.WorkflowDraft, error)

GetWorkflowDraft 获取工作流对应的草稿数据,若不存在返回 nil, nil

func (*Store) GetWorkflowPhase

func (s *Store) GetWorkflowPhase(ctx context.Context, workflowID string) (*model.WorkflowPhaseState, error)

func (*Store) GetWorkflowPhaseWithDefaults

func (s *Store) GetWorkflowPhaseWithDefaults(ctx context.Context, workflowID string) (currentPhaseID string, phases []model.PhaseItem, err error)

func (*Store) GrantHostToTerminalCredentials

func (s *Store) GrantHostToTerminalCredentials(ctx context.Context, machineCode string) (HostGrantResult, error)

GrantHostToTerminalCredentials 把 machineCode 写入所有「带终端能力、不是通配、尚未包含它」的模型令牌的主机名单。 整个过程在同一个事务里完成:要么全部写入,要么都不写。

func (*Store) GroupLastMessage

func (s *Store) GroupLastMessage(ctx context.Context, groupID string) (*model.ChatMessage, error)

GroupLastMessage 取群里最新一条文本消息(会话列表的预览);没有返回 nil。

func (*Store) GroupLastSeq

func (s *Store) GroupLastSeq(ctx context.Context, groupID string) (int64, error)

GroupLastSeq 返回群里最新的序号(含系统行)。

func (*Store) GroupMentionStates

func (s *Store) GroupMentionStates(ctx context.Context, groupID string, messageIDs []uint) (map[uint]map[string]string, error)

GroupMentionStates 返回群消息对应的提醒行状态(被点名的成员 → 状态),聊天界面给被 @ 的消息标已送达 / 已读 / 已处理。

func (*Store) GroupMessagesAfterSeq

func (s *Store) GroupMessagesAfterSeq(ctx context.Context, groupID string, afterSeq int64, limit int, vis *GroupVisibility) ([]model.ChatMessage, bool, error)

GroupMessagesAfterSeq 取序号大于 afterSeq 的消息(升序,最多 limit 条)。Agent 的 chat read 用它。

func (*Store) GroupReadSeqs

func (s *Store) GroupReadSeqs(ctx context.Context, groupID string) (map[string]int64, error)

GroupReadSeqs 返回群里每个读者的已读序号:key 是 "<kind>:<ref>"。

func (*Store) GroupRefsOfIdentity

func (s *Store) GroupRefsOfIdentity(ctx context.Context, workflowID string, identityID uint) []string

GroupRefsOfIdentity 是这个身份当前所在的群(群授权的主体):群成员单位是工作流, 所以取「本次调用的工作流」和「这个身份名下所有工作流」里仍在群内的那些。

func (*Store) GroupUnread

func (s *Store) GroupUnread(ctx context.Context, groupID, readerKind, readerRef string, since time.Time) (unread, mentioned int, err error)

GroupUnread 是读者在群里的未读数:别人发的文本消息(系统行不计),以及其中点名了读者(或 @all)的条数。 since 是读者可见的起点(入群时间);人读取时传零值。

func (*Store) GroupsOfWorkflow

func (s *Store) GroupsOfWorkflow(ctx context.Context, workflowID string) ([]model.Conversation, error)

GroupsOfWorkflow 列出一个工作流当前所在的(未归档的)群。

func (*Store) HasAnyCredential

func (s *Store) HasAnyCredential(ctx context.Context) (bool, error)

func (*Store) HookLastSeen

func (s *Store) HookLastSeen(workflowID string) (time.Time, bool)

HookLastSeen 返回某个工作流的编辑器 hook 最近一次来问收件箱的时间(Hub 重启后从库里恢复,见 RestoreHookSeen)。

func (*Store) IdentityLabelOf

func (s *Store) IdentityLabelOf(ctx context.Context, identityID uint) string

IdentityLabelOf 给审计用的身份标签:用户改的名字,没有就用目录名。

func (*Store) IdentityProjectID

func (s *Store) IdentityProjectID(ctx context.Context, identityID uint) uint

IdentityProjectID 是身份所在目录归属的项目;没有归属返回 0。

func (*Store) ImportProjectDocs

func (s *Store) ImportProjectDocs(ctx context.Context, workflowID string, files []ImportDocFile, mode string, dryRun bool, actor DocActor) (*ImportDocResult, error)

func (*Store) InboxAck

func (s *Store) InboxAck(ctx context.Context, workflowID string, ids []uint, now time.Time) ([]uint, error)

InboxAck 确认已读取的追加。ids 为空表示确认这个工作流里全部「已读取未确认」的。 还没被读取的(排队中)不能确认——没读过就谈不上确认。返回实际确认的编号。

func (*Store) InboxPeek

func (s *Store) InboxPeek(ctx context.Context, workflowID string, reminder bool, now time.Time) (InboxPeek, error)

InboxPeek 看一眼收件箱。reminder=false 纯只读;reminder=true 是 hook 在用: 按「立即、5 分钟后、15 分钟后」的节奏判断每条未读该不该再提醒一次,提醒过就记一笔(每条最多 InboxMaxReminders 次), 这样 hook 即使每隔十几秒查一次,也不会反复打扰。

撤回也提醒(#199):智能体读过或被提醒过的追加被用户撤回后,hook 提醒它一次(记在 last_notified_at 上, 每条撤回只提醒一次,不占 notified_count);智能体读过收件箱、被告知撤回之后就不再提醒。

func (*Store) InboxRead

func (s *Store) InboxRead(ctx context.Context, workflowID string, opts InboxReadOptions, now time.Time) (InboxReadResult, error)

InboxRead 是智能体主动读取收件箱:把排队中的追加标为已送达并返回全文。 送达归因:读取前 30 分钟内收到过 hook 提醒 / 回执提示行的,记为那条路径,否则记为主动读取。

func (*Store) InboxSummary

func (s *Store) InboxSummary(ctx context.Context, workflowID string, now time.Time) (InboxSummary, error)

InboxSummary 统计一个工作流收件箱的现状。只读。

func (*Store) IngestAgentEvent

func (s *Store) IngestAgentEvent(ctx context.Context, in AgentIngestInput) (AgentIngestResult, error)

IngestAgentEvent 把一次汇报折进状态核心。没有项目目录(认不出身份)时什么都不记,返回零值结果。 写库失败只丢掉持久化:内存里的状态照常前进,下一次事件会重试写库。

func (*Store) InsertOAuthAccessToken

func (s *Store) InsertOAuthAccessToken(ctx context.Context, hash string, grantID uint, expires time.Time) error

func (*Store) InvalidateOAuthGrantFamily

func (s *Store) InvalidateOAuthGrantFamily(ctx context.Context, id uint) error

func (*Store) IsAsyncEffective

func (s *Store) IsAsyncEffective(ctx context.Context, workflowID string, now time.Time) bool

IsAsyncEffective 回答「这个工作流此刻是不是有效的异步模式」。出错一律按同步处理(同步是安全的默认)。

func (*Store) KeepaliveFeedbackSession

func (s *Store) KeepaliveFeedbackSession(ctx context.Context, sessionID string, extendSec int) (*model.FeedbackSession, error)

func (*Store) LatestWorkflowOfIdentity

func (s *Store) LatestWorkflowOfIdentity(ctx context.Context, identityID uint) string

LatestWorkflowOfIdentity 是身份最近活跃的工作流(给授权提醒找收件箱用);没有返回空串。

func (*Store) LinkWorkItemSession

func (s *Store) LinkWorkItemSession(ctx context.Context, id uint, sessionID string) error

LinkWorkItemSession 把一个已存在的会话关联到任务。

func (*Store) ListActiveTerminalRuns

func (s *Store) ListActiveTerminalRuns(ctx context.Context) ([]model.TerminalRun, error)

ListActiveTerminalRuns 返回所有尚未终结的运行(待批准或运行中),Hub 启动时据此恢复内存索引。

func (*Store) ListActiveUserNorms

func (s *Store) ListActiveUserNorms(ctx context.Context) ([]model.UserNorm, error)

func (*Store) ListAgentIdentities

func (s *Store) ListAgentIdentities(ctx context.Context) ([]AgentIdentityView, error)

ListAgentIdentities 返回全部身份(最近活动的在前),显示名按「改名 ?? 目录名、重名降级」统一计算。

func (*Store) ListAgentSessions

func (s *Store) ListAgentSessions(ctx context.Context, f AgentSessionFilter, now time.Time) ([]AgentSessionView, error)

ListAgentSessions 返回会话的展示状态(最近有动静的在前)。now 由调用方给,便于测试。

func (*Store) ListArtifactComments

func (s *Store) ListArtifactComments(ctx context.Context, docID uint, includeResolved bool, limit int) ([]model.ArtifactComment, error)

ListArtifactComments 按时间正序列出评论;默认只含未解决的。

func (*Store) ListAuditEvents

func (s *Store) ListAuditEvents(ctx context.Context, f AuditFilter) ([]model.AuditEvent, error)

ListAuditEvents 按时间倒序返回(新的在前)。

func (*Store) ListAuthProfiles

func (s *Store) ListAuthProfiles(ctx context.Context) ([]model.AuthProfile, error)

ListAuthProfiles 按排序列出全部档位(默认档位不一定排第一,由界面决定怎么展示)。

func (*Store) ListCheckpoints

func (s *Store) ListCheckpoints(ctx context.Context, workflowID string, limit int) ([]model.WorkflowCheckpoint, error)

func (*Store) ListConfirmItems

func (s *Store) ListConfirmItems(ctx context.Context, f ConfirmFilter) ([]model.ConfirmItem, error)

ListConfirmItems 列出确认项。

func (*Store) ListCredentialHosts

func (s *Store) ListCredentialHosts(ctx context.Context) ([]CredentialHost, error)

ListCredentialHosts 列出各凭据登记的主机名(只含名称与主机,不含令牌)。

func (*Store) ListCredentials

func (s *Store) ListCredentials(ctx context.Context) ([]model.MCPCredential, error)

func (*Store) ListDocWorkflowStats

func (s *Store) ListDocWorkflowStats(ctx context.Context) ([]DocWorkflowStat, error)

ListDocWorkflowStats 各工作流文档数。

func (*Store) ListDraftImages

func (s *Store) ListDraftImages(ctx context.Context, workflowID string) ([]DraftImageInfo, error)

ListDraftImages 列出一个工作流的草稿图片元数据(不读出正文),按写入时间排序。

func (*Store) ListFeedbackRoundSessions

func (s *Store) ListFeedbackRoundSessions(ctx context.Context, projectDir, status string, limit int) ([]model.FeedbackSession, error)

ListFeedbackRoundSessions 与 ListFeedbackSessions 相同,但在 SQL 里排除「进度通知」(kind=notice)。 通知不是「轮」;若取完 limit 条再在内存里过滤,每发一条通知就会把一轮更早的汇报挤出窗口, 回执里 recent_workflows 的「N 轮」会随通知越变越少(#109)。

func (*Store) ListFeedbackSessions

func (s *Store) ListFeedbackSessions(ctx context.Context, projectDir, status string, limit int) ([]model.FeedbackSession, error)

func (*Store) ListFeedbackSessionsBrief

func (s *Store) ListFeedbackSessionsBrief(ctx context.Context, projectDir, status string, limit int) ([]model.FeedbackSession, error)

ListFeedbackSessionsBrief 获取轻量会话列表(通过字段投影排除大体积正文 summary、response_text、user_messages 和 images,专供小带宽场景下的列表加载)

func (*Store) ListFeedbackSessionsBriefCovering

func (s *Store) ListFeedbackSessionsBriefCovering(ctx context.Context, projectDir, status string, limit int) ([]model.FeedbackSession, error)

ListFeedbackSessionsBriefCovering 在轻量列表「最新 limit 行」之外,再把每个工作流里最新的一行补进来(#173)。

为什么要补:最新 limit 行是按「会话行」数的,一个工作流跑一百轮就是一百行;话痨的工作流多了, 窗口里只剩它们,较早的工作流(哪怕没归档、没删除)一行都不在窗口里,侧栏与归档库就凭空少了它们。 侧栏和归档库要的是「每个工作流一条」,所以窗口之外的工作流各补它最新的一行(同样遵守项目目录与状态过滤)。

约定:

  • 结果按创建时间倒序,与 ListFeedbackSessionsBrief 同序,调用方不必改排序;
  • 补的行数最多 briefCoverExtraMax,取最近有动静的那些工作流;
  • 没有工作流编号的老会话行不补(它们没有「工作流」可言,维持只看最新窗口的老行为);
  • 不改 limit 的含义:窗口仍是最新 limit 行,补进来的只是窗口之外的各工作流各一行。

func (*Store) ListGrants

func (s *Store) ListGrants(ctx context.Context, projectID uint, includeInactive bool) ([]model.ACLGrant, error)

ListGrants 列出项目的授权,新的在前;默认只给有效的(没撤销、没过期)。

func (*Store) ListGroupMembers

func (s *Store) ListGroupMembers(ctx context.Context, groupID string, includeLeft bool) ([]model.ConversationMember, error)

ListGroupMembers 列出群成员(先 owner 后 member,按加入先后)。

func (*Store) ListGroups

func (s *Store) ListGroups(ctx context.Context, includeArchived bool) ([]model.Conversation, error)

ListGroups 列出群(最近有动静的在前)。

func (*Store) ListInboxItems

func (s *Store) ListInboxItems(ctx context.Context, workflowID string) ([]model.QueuedFeedback, error)

ListInboxItems 返回 Web 上要展示的追加信息(按时间从早到晚)。它们在会话页里是对话中的永久气泡,所以:

  • 未确认的(排队中 / 已读取未确认)全部在内;
  • 已确认的只保留经提示行 / hook / 主动读取送达的,不再设时间窗口——随「秒回」带走的那些 已经原样出现在对话记录里,不重复展示,而经这三条路径送达的从来不会出现在对话记录里,不留下就查不到了;
  • 过期的(保留期内一直没被读到)留一条记录,说明智能体始终没有看到它;
  • 已撤回的不在其中。

最多 InboxListMax 条,超出时保留最近的。

func (*Store) ListNotes

func (s *Store) ListNotes(ctx context.Context, workflowID string, sessionID string, limit int) ([]model.WorkflowNote, error)

func (*Store) ListOAuthGrants

func (s *Store) ListOAuthGrants(ctx context.Context) ([]model.OAuthGrant, error)

func (*Store) ListPendingQueuedFeedbacks

func (s *Store) ListPendingQueuedFeedbacks(ctx context.Context, workflowID string) ([]model.QueuedFeedback, error)

ListPendingQueuedFeedbacks 列出还没有被智能体确认的追加(含已读取未确认的)。保留给旧调用方。

func (*Store) ListProjectDirs

func (s *Store) ListProjectDirs(ctx context.Context, projectID uint) ([]model.ProjectDir, error)

func (*Store) ListProjectDocRevisions

func (s *Store) ListProjectDocRevisions(ctx context.Context, docID uint) ([]model.ProjectDocRevision, error)

ListProjectDocRevisions 修订历史。

func (*Store) ListProjectDocs

func (s *Store) ListProjectDocs(ctx context.Context, f ProjectDocFilter) ([]model.ProjectDoc, error)

ListProjectDocs 列表。

func (*Store) ListProjectModules

func (s *Store) ListProjectModules(ctx context.Context, projectID uint) ([]model.ProjectModule, error)

func (*Store) ListProjects

func (s *Store) ListProjects(ctx context.Context, includeArchived bool) ([]model.Project, error)

ListProjects 按名称排序;默认不含已归档的。

func (*Store) ListRetractionEvents

func (s *Store) ListRetractionEvents(ctx context.Context, workflowID string) ([]RetractionEvent, error)

ListRetractionEvents 列出这个工作流里「智能体知道的追加被撤回」的记录(保留期内、从早到晚、最近 RetractionEventsMax 条), 给 get_session_history 用:经收件箱读到的追加不在历史轮次里,撤回了也就没处留痕。 完全没让智能体知道的撤回(读到之前就撤回、也没提醒过)不在其中;列表只读,不改变任何状态,不带正文与图片。

func (*Store) ListSSHHostCodesViaGateway

func (s *Store) ListSSHHostCodesViaGateway(ctx context.Context, gateway string) ([]string, error)

ListSSHHostCodesViaGateway 列出经某台网关主机接入的全部 SSH 主机的机器码——**不分状态**(停用的主机也算: 它的凭据仍应保留在网关上,重新启用后要能继续使用)。网关据此回收名单之外的凭据,所以绝不能漏。

func (*Store) ListTasks

func (s *Store) ListTasks(ctx context.Context, projectID, state, cursor string, limit int, updatesOnly bool) (*model.TaskPage, error)

func (*Store) ListTerminalArchives

func (s *Store) ListTerminalArchives(ctx context.Context) ([]string, error)

ListTerminalArchives 返回全部已归档条目的 key(最近归档的在前)。

func (*Store) ListTerminalAudit

func (s *Store) ListTerminalAudit(ctx context.Context, limit int, beforeID uint) ([]model.TerminalAuditLog, error)

ListTerminalAudit 按 ID 倒序返回审计记录;beforeID>0 时只返回更早的记录(游标翻页)。

func (*Store) ListTerminalAuditSince

func (s *Store) ListTerminalAuditSince(ctx context.Context, event, result string, since time.Time, limit int) ([]model.TerminalAuditLog, error)

ListTerminalAuditSince 返回某个事件在 since 之后的审计记录,按时间正序排好;result 非空时只取这个结果。 项目管理 Agent 经 MCP 运行预设(#179)的频率账本读它:次数来自审计记录,所以 Hub 重启不会清零。

条数超过 limit(默认 100,上限 500)时留下的是**最新**的 limit 条、丢的是最旧的:账本只关心最近的次数, 反过来(留最旧的)会让一大批被拒绝的尝试把成功的记录挤出窗口,限额就此失效。 事件名带索引;记录总量受 PruneTerminalAudit 的保留条数限制。

func (*Store) ListTerminalHosts

func (s *Store) ListTerminalHosts(ctx context.Context) ([]model.TerminalHost, error)

ListTerminalHosts 返回全部主机(按创建时间升序)。

func (*Store) ListTerminalLaunchers

func (s *Store) ListTerminalLaunchers(ctx context.Context) ([]TerminalLauncher, error)

ListTerminalLaunchers 读取全部预设(按保存顺序);从未保存过时返回空列表(不是 nil)。

func (*Store) ListTerminalLostDismissals

func (s *Store) ListTerminalLostDismissals(ctx context.Context) (map[string]map[string]struct{}, error)

ListTerminalLostDismissals 返回全部忽略记录:机器码 → 已忽略的会话 ID 集合。

func (*Store) ListTerminalRuns

func (s *Store) ListTerminalRuns(ctx context.Context, f RunFilter) ([]model.TerminalRun, error)

ListTerminalRuns 按 ID 倒序返回运行记录(游标翻页)。

func (*Store) ListTerminalRunsByIDs

func (s *Store) ListTerminalRunsByIDs(ctx context.Context, ids []uint) ([]model.TerminalRun, error)

ListTerminalRunsByIDs 按主键批量读取运行记录(线程汇总取首末两条用)。

func (*Store) ListTerminalSessions

func (s *Store) ListTerminalSessions(ctx context.Context, machineCode string, endedOnly bool, limit int) ([]model.TerminalSession, error)

ListTerminalSessions 返回一台主机的会话索引(最近创建的在前);endedOnly 时只返回已结束的。 记录已被主机清理(RecPurged)的已结束会话不再列出。

func (*Store) ListTerminalThreads

func (s *Store) ListTerminalThreads(ctx context.Context, f ThreadFilter) ([]ThreadStat, error)

ListTerminalThreads 按「最近一次运行」倒序返回线程汇总。只聚合元数据,不读取预览等大字段。

func (*Store) ListUserNorms

func (s *Store) ListUserNorms(ctx context.Context) ([]model.UserNorm, error)

func (*Store) ListVisibleCredentials

func (s *Store) ListVisibleCredentials(ctx context.Context) ([]model.MCPCredential, error)

func (*Store) ListWorkItemWorkflows

func (s *Store) ListWorkItemWorkflows(ctx context.Context) ([]WorkflowStat, error)

ListWorkItemWorkflows 列出有任务的工作流及其概况,最近更新的在前。 同一张任务板上的工作流各占一条,数字都是整张板的(见 WorkflowStat)。

func (*Store) ListWorkItems

func (s *Store) ListWorkItems(ctx context.Context, f WorkItemFilter) ([]model.WorkItem, error)

ListWorkItems 列出任务(不含时间线),最近更新的在前;同时补齐子任务进度、父任务和关联会话数。

func (*Store) ListWorkModules

func (s *Store) ListWorkModules(ctx context.Context, workflowID string) (*WorkModuleList, error)

ListWorkModules 返回工作流所在任务板的规划树(按树的顺序拍平,含任务汇总)与未归类的汇总。

func (*Store) ListWorkflowBindings

func (s *Store) ListWorkflowBindings(ctx context.Context) ([]WorkflowBinding, error)

ListWorkflowBindings 按工作流汇总当前绑定,最近活跃的在前;供运维先看清再改绑。

func (*Store) ListWorkflowFeedbackSessions

func (s *Store) ListWorkflowFeedbackSessions(ctx context.Context, workflowID string) ([]model.FeedbackSession, error)

ListWorkflowFeedbackSessions 获取指定工作流的所有完整会话(按 created_at ASC 升序,包含完整图文正文,按需呈现对话流)

func (*Store) ListWorkflowSessionBodies

func (s *Store) ListWorkflowSessionBodies(ctx context.Context, workflowID string, ids []string) ([]model.FeedbackSession, error)

ListWorkflowSessionBodies 按 id 取一批会话的完整正文(#169 第二期「正文按需」): 只读正文相关的列(summary / response_text / user_messages / images)与定位用的 id / 时间戳,不读其余列。 范围限定在这个工作流里(与 ListWorkflowFeedbackSessions 同一个口径:workflow_id 等于它,或会话 id 就是它), 所以拿别的工作流的 id 来问只会得到空结果,不会越界读到别处的正文。结果按创建时间升序;不存在的 id 直接略过。

func (s *Store) ListWorkflowSessionLinks(ctx context.Context, workflowID string) ([]model.WorkItemSessionLink, error)

ListWorkflowSessionLinks 返回一个工作流所在任务板上所有「会话 ↔ 任务」的关联,以及每个会话对每个任务做了什么。 会话页按轮次展开任务时用:一次查询取回整张板,不必为每一轮各查一次。 「做了什么」只依赖任务时间线里还保留的条目(每个任务最近 WorkUpdatesKeep 条)。

func (*Store) ListWorkflowSummaries

func (s *Store) ListWorkflowSummaries(ctx context.Context, projectDir, hostName string, limit int) ([]map[string]any, error)

func (*Store) ListWorkflowUpdates

func (s *Store) ListWorkflowUpdates(ctx context.Context, workflowID string, since time.Time, limit int) ([]WorkflowUpdate, error)

ListWorkflowUpdates 返回一个工作流里「智能体」写下的任务进展,按提交时间升序,最多 limit 条最新的。 人在网页上点状态 / 改进度是自己做的事,不进对话;since 非零时只要这个时间之后的。

func (*Store) MarkGroupMentionsRead

func (s *Store) MarkGroupMentionsRead(ctx context.Context, groupID, workflowID string, messageIDs []uint) error

MarkGroupMentionsRead 把某个成员收件箱里、对应这些群消息的提醒行标为已读取并确认:Agent 用 chat read 读到了它们。

func (*Store) MarkHookInstallHint

func (s *Store) MarkHookInstallHint(workflowID string, now time.Time)

MarkHookInstallHint 记下刚刚在回执里提示过安装 hook。

func (*Store) MarkInboxReceiptHint

func (s *Store) MarkInboxReceiptHint(ctx context.Context, workflowID string, now time.Time) (bool, error)

MarkInboxReceiptHint 记下「回执提示行刚刚提醒过」,用于在读取时把送达归因到这条路径。 时间戳至多每分钟写一次。 返回 true 表示这次真的写了库(界面据此决定要不要刷新)。

func (*Store) MarkModeTold

func (s *Store) MarkModeTold(ctx context.Context, workflowID, sig string) error

MarkModeTold 记下「已经把当前模式状态告诉了智能体」(签名见 asyncmode.Signature)。

func (*Store) MarkSessionConsumedByAI

func (s *Store) MarkSessionConsumedByAI(ctx context.Context, sessionID string, consumedAt ...time.Time) error

func (*Store) MarkTerminalSessionPurged

func (s *Store) MarkTerminalSessionPurged(ctx context.Context, machineCode, sid string) error

MarkTerminalSessionPurged 标记主机上的记录已不存在(过期或被清理)。

func (*Store) MarkWorkflowHistorySessionsConsumed

func (s *Store) MarkWorkflowHistorySessionsConsumed(ctx context.Context, workflowID string) error

MarkWorkflowHistorySessionsConsumed 自动将某工作流下所有已完成但未被消费的历史轮次批量打标为已消费(D-159)

func (*Store) MigrationDryRun

func (s *Store) MigrationDryRun(ctx context.Context, projectID uint) (*MigrationReport, error)

MigrationDryRun 只读:报告「如果现在确认,每篇文档会去哪里」。

func (*Store) ModuleOwnerFor

func (s *Store) ModuleOwnerFor(ctx context.Context, projectID uint, path string) uint

ModuleOwnerFor 返回模块的负责人:模块自己没有就沿父模块往上找最近的一个。没有返回 0。

func (*Store) ModulePage

func (s *Store) ModulePage(ctx context.Context, projectID uint, modulePath string) (*ModulePageView, error)

ModulePage 聚合一个模块(含子模块下的文档)的页面。

func (*Store) MoveWorkModule

func (s *Store) MoveWorkModule(ctx context.Context, id uint, delta int) (*WorkModuleList, error)

MoveWorkModule 在同级里上移(delta<0)或下移(delta>0)一格;已在边界时什么也不做。返回最新的规划树。

func (*Store) NeedsHookInstallHint

func (s *Store) NeedsHookInstallHint(workflowID string, now time.Time) bool

NeedsHookInstallHint 判断是否在回执末尾提示安装 hook(无 hook 痕迹或超过 24h,且 6h 内未提示过)。

func (*Store) PostGroupMessage

func (s *Store) PostGroupMessage(ctx context.Context, in PostGroupInput) (*PostGroupResult, error)

PostGroupMessage 落库一条群消息并按规则表投递(见文件头)。

func (*Store) PreviewHostGrant

func (s *Store) PreviewHostGrant(ctx context.Context, machineCode string) (HostGrantResult, error)

PreviewHostGrant 返回把 machineCode 授予现有模型令牌时会被改动的令牌名称,不写入任何数据。

func (*Store) ProjectBlueprint

func (s *Store) ProjectBlueprint(ctx context.Context, projectID uint, withTemplates bool) ([]docs.BlueprintItem, error)

ProjectBlueprint 项目知识库的推荐结构与缺口。

func (*Store) ProjectOfDir

func (s *Store) ProjectOfDir(ctx context.Context, host, dir string) (*model.Project, error)

ProjectOfDir 返回(主机,目录)所属的项目;没有归属返回 nil, nil。host 为空时只按目录匹配(取最早登记的一条)。

func (*Store) ProjectOfWorkflow

func (s *Store) ProjectOfWorkflow(ctx context.Context, workflowID string) (*model.Project, error)

ProjectOfWorkflow 返回工作流所属的项目;没有归属(或没有任何汇报会话)返回 nil, nil。

func (*Store) ProjectStatsOf

func (s *Store) ProjectStatsOf(ctx context.Context, projectID uint) (ProjectStats, error)

ProjectStatsOf 统计项目的目录、模块、文档与工作流数量。

func (*Store) ProjectSuggestions

func (s *Store) ProjectSuggestions(ctx context.Context) ([]ProjectSuggestion, error)

ProjectSuggestions 列出还没有归属项目的目录:每个(主机,目录)一条,名字取目录名。 用户可以逐条确认成项目,也可以把几条合并到同一个项目里(比如同一仓库的几个工作树)。

func (*Store) ProjectWorkflowIDs

func (s *Store) ProjectWorkflowIDs(ctx context.Context, projectID uint) ([]string, error)

ProjectWorkflowIDs 列出项目里所有工作流(最近一次汇报会话的目录落在项目目录里的),按编号排序。

func (*Store) PruneTerminalAudit

func (s *Store) PruneTerminalAudit(ctx context.Context, keep int) (int64, error)

PruneTerminalAudit 只保留最近 keep 条审计记录,返回删除条数。

func (*Store) PruneTerminalRuns

func (s *Store) PruneTerminalRuns(ctx context.Context, cutoff time.Time) (int64, error)

PruneTerminalRuns 删除结束时间早于 cutoff 的运行元数据,返回删除条数。

func (*Store) PruneTerminalSessions

func (s *Store) PruneTerminalSessions(ctx context.Context, cutoff time.Time) (int64, error)

PruneTerminalSessions 删除结束时间早于 cutoff 的会话索引,返回删除行数。

func (*Store) PurgeUnusedOAuthClients

func (s *Store) PurgeUnusedOAuthClients(ctx context.Context, maxAge time.Duration) error

PurgeUnusedOAuthClients 删除从未成功授权且超过 maxAge 的 DCR 客户端。

func (*Store) PutDraftImage

func (s *Store) PutDraftImage(ctx context.Context, img model.DraftImage) error

PutDraftImage 保存(或重新确认)一张草稿图片:同一工作流里相同的内容键只存一份,重复上传是幂等的,只刷新写入时间。 超过单张 / 张数 / 总量配额时返回 invalid_input,不写入任何内容。

func (*Store) QueueWorkflowFeedback

func (s *Store) QueueWorkflowFeedback(ctx context.Context, input QueueFeedbackInput) (*model.QueuedFeedback, error)

QueueWorkflowFeedback 把一条追加存进收件箱。每条独立一行,不再合并。

func (*Store) ReadFeedbacks

func (s *Store) ReadFeedbacks(ctx context.Context, projectID, taskID string, afterSequence int64, limit int) ([]model.Feedback, error)

func (*Store) ReadReports

func (s *Store) ReadReports(ctx context.Context, projectID, taskID string, afterSequence int64, limit int) (*model.ReportPage, error)

func (*Store) RebindWorkflow

func (s *Store) RebindWorkflow(ctx context.Context, req RebindRequest, apply bool) (*RebindResult, error)

RebindWorkflow 把一个工作流改绑到新的项目目录(可同时改主机)。

apply=false 只做预演:返回当前画像与将要改写的行数,不写入任何数据。 apply=true 在单个事务里改写,并在提交前校验结果(目录唯一、主机符合预期),任何一项不符就整体回滚。 改写使用 UpdateColumns:保持 updated_at 不变,避免这个工作流「看起来刚刚活跃过」而打乱最近活跃排序。

func (*Store) RecentWorkflows

func (s *Store) RecentWorkflows(ctx context.Context, limit int) ([]WorkflowBrief, error)

RecentWorkflows 列出有过汇报会话的工作流(最近有动静的在前),每个工作流取最近一条会话的项目目录与主机。

func (*Store) ReconcileReplyWindow

func (s *Store) ReconcileReplyWindow(ctx context.Context, workflowID string, now time.Time) (w ReplyWindow, changed bool, err error)

ReconcileReplyWindow 读出窗口并按任务情况对齐:有任务在做就把走动中的窗口暂停(剩余攒进 BankSec), 任务清零后再从攒着的时间接着走。changed 表示这次对齐改动了数据(调用方据此广播)。

func (*Store) RecordAgentActivity

func (s *Store) RecordAgentActivity(workflowID string, at time.Time)

RecordAgentActivity 记下某个工作流的智能体刚刚调用过 RelayMesh。

func (*Store) RecordAgentEvent

func (s *Store) RecordAgentEvent(ctx context.Context, workflowID string, ev AgentEvent, at time.Time)

RecordAgentEvent 记下某个工作流的智能体刚汇报的一次事件。对话编号变了才写库,写库失败只丢掉持久化,不影响内存里的记录。

func (*Store) RecordHookSeen

func (s *Store) RecordHookSeen(workflowID string, at time.Time) bool

RecordHookSeen 记下某个工作流的编辑器 hook 刚刚来问过一次。 返回值表示要不要通知 Web 刷新:之前从没记过,或距上一次记录已超过 InboxHookSeenBroadcastEvery。 时间同时按 HookSeenPersistEvery 节流落库,Hub 重启后由 RestoreHookSeen 装回来(#103,见 hook_seen.go)。

func (*Store) RecordSSHCheck

func (s *Store) RecordSSHCheck(ctx context.Context, code string, c SSHCheck) error

RecordSSHCheck 记录一次连接尝试。成功时清除错误并刷新主机自报信息;密钥不一致时置位 mismatch(只升不降)。

func (*Store) RecordTerminalSessionEnds

func (s *Store) RecordTerminalSessionEnds(ctx context.Context, machineCode string, ends []TerminalSessionEnd, now time.Time) error

RecordTerminalSessionEnds 把若干会话标记为已结束并记下(精确的)原因: 不在索引里的补建;尚未结束的记下结束时间;已结束但原因较弱(gone / exit)的改写为这个更精确的原因, 已有精确原因的不会被覆盖。

func (*Store) RecycleOldestUnusedOAuthClient

func (s *Store) RecycleOldestUnusedOAuthClient(ctx context.Context) bool

RecycleOldestUnusedOAuthClient 回收最老的从未使用客户端,成功返回 true。

func (*Store) RegenerateCredentialToken

func (s *Store) RegenerateCredentialToken(ctx context.Context, id uint) (*model.MCPCredential, string, error)

func (*Store) RemoveGroupMember

func (s *Store) RemoveGroupMember(ctx context.Context, groupID, workflowID string) error

RemoveGroupMember 把成员移出群:保留一行(离开之后的消息它看不到),写系统行。

func (*Store) RemoveProjectDir

func (s *Store) RemoveProjectDir(ctx context.Context, projectID, dirID uint) error

func (*Store) RenameAgentIdentity

func (s *Store) RenameAgentIdentity(ctx context.Context, id uint, name, by string) (*AgentIdentityView, error)

RenameAgentIdentity 给身份改名(空串 = 恢复用目录名)。改名写一条审计事件,不改变身份编号。

func (*Store) RenameFeedbackSession

func (s *Store) RenameFeedbackSession(ctx context.Context, idOrWorkflow, newTitle string) (*model.FeedbackSession, error)

func (*Store) ResetAuthCredentials

func (s *Store) ResetAuthCredentials(ctx context.Context) error

ResetAuthCredentials 删除数据库中的账号密码记录,回退为环境变量值

func (*Store) ResolveArtifactComment

func (s *Store) ResolveArtifactComment(ctx context.Context, docID, commentID uint, resolved bool) (*model.ArtifactComment, error)

ResolveArtifactComment 把评论标成已解决 / 重新打开。

func (*Store) ResolveAuthProfile

func (s *Store) ResolveAuthProfile(ctx context.Context, id uint) (*model.AuthProfile, error)

ResolveAuthProfile 取工作流选用的档位:id 为 0 或档位已不存在时回退到默认档位。

func (*Store) ResolveCallerIdentity

func (s *Store) ResolveCallerIdentity(ctx context.Context, workflowID string, credentialID uint, host, dir string, now time.Time) (id uint, asserted bool)

ResolveCallerIdentity 回答「这次调用是谁」:带了 project_directory 的是明确断言(asserted=true); 没带就按工作流绑定的目录推断(asserted=false,审计里标 assumed)。认不出目录返回 0。

func (*Store) ResolveDocModule

func (s *Store) ResolveDocModule(ctx context.Context, projectID uint, docPath, explicit string) string

ResolveDocModule 返回一篇文档(路径 + 可选的显式模块)实际会绑定到的模块路径;没有则空串。

func (*Store) ResolveDraftImages

func (s *Store) ResolveDraftImages(ctx context.Context, workflowID string, keys []string) (map[string]model.DraftImage, error)

ResolveDraftImages 按内容键取回一批草稿图片(含正文),缺失的键不会出现在结果里。

func (*Store) ResolveJWTSecret

func (s *Store) ResolveJWTSecret(ctx context.Context, envSecret string) (JWTSecretResolution, error)

ResolveJWTSecret 决定本次运行使用的 JWT 签名密钥,优先级:

  1. 强度合格的环境变量(envSecret);
  2. 数据库中已持久化的强密钥;
  3. 首次启动自动生成 384 bit 随机密钥并持久化。

无论如何都不会返回内置默认值或弱密钥:数据库不可写时降级为仅本进程有效的随机密钥(重启后需重新登录), 而不是回退到可被公开源码推导出的固定值。只有系统随机数源本身失败才会返回错误。

func (*Store) ResolveWorkModule

func (s *Store) ResolveWorkModule(ctx context.Context, workflowID, ref string) (*model.WorkModule, error)

ResolveWorkModule 按路径解析模块(见 moduleForest.resolve)。找不到时错误里带着已有的路径清单。

func (*Store) RestoreFeedbackSession

func (s *Store) RestoreFeedbackSession(ctx context.Context, session *model.FeedbackSession) (*model.FeedbackSession, error)

RestoreFeedbackSession 复原被删除的会话(支持撤销删除)

func (*Store) RestoreHookSeen

func (s *Store) RestoreHookSeen(ctx context.Context) error

RestoreHookSeen 在启动时把库里的 hook 时间装回内存,并清掉太久以前的记录。不会覆盖内存里更新的值。 返回错误只用于测试与排查:启动流程把它当成尽力而为(装不回来就退回「从头记」的旧行为,那是保守的)。

func (*Store) RestoreProjectDocRevision

func (s *Store) RestoreProjectDocRevision(ctx context.Context, docID uint, rev int, actor DocActor) (*ProjectDocSaveResult, error)

RestoreProjectDocRevision 还原为新修订。

func (*Store) RevokeGrant

func (s *Store) RevokeGrant(ctx context.Context, projectID, grantID uint) (*model.ACLGrant, error)

RevokeGrant 撤销一条授权(幂等:已撤销的再撤销不报错)。

func (*Store) RevokeOAuthGrant

func (s *Store) RevokeOAuthGrant(ctx context.Context, id uint) error

func (*Store) RevokeQueuedFeedback

func (s *Store) RevokeQueuedFeedback(ctx context.Context, queuedID uint) (*RevokedFeedbackResult, error)

RevokeQueuedFeedback 撤回一条追加。智能体完全不知道的(没读过、也没被提醒过)直接作废,什么都不用告诉它; 已被读取、或被 hook / 提示行提醒过但还没读的,标为撤回并记下撤回时间,在下一次读取收件箱时告诉智能体忽略它 (被提醒过但没读的只告知编号,不再给正文)。已确认的不能撤回。

func (*Store) RevokeSessionFeedback

func (s *Store) RevokeSessionFeedback(ctx context.Context, sessionID string) (*RevokedFeedbackResult, *model.FeedbackSession, error)

func (*Store) SaveAuthCredentials

func (s *Store) SaveAuthCredentials(ctx context.Context, username, password string) error

SaveAuthCredentials 保存或更新账号密码至数据库

func (*Store) SaveCheckpoint

func (s *Store) SaveCheckpoint(ctx context.Context, cp *model.WorkflowCheckpoint) error

func (*Store) SaveNote

func (s *Store) SaveNote(ctx context.Context, note *model.WorkflowNote) error

func (*Store) SaveOAuthPolicy

func (s *Store) SaveOAuthPolicy(ctx context.Context, p model.OAuthPolicy) error

func (*Store) SaveSettings

func (s *Store) SaveSettings(ctx context.Context, settings map[string]any) error

SaveSettings 保存全局配置至数据库

func (*Store) SaveTerminalHost

func (s *Store) SaveTerminalHost(ctx context.Context, h *model.TerminalHost) error

SaveTerminalHost 在事务内创建或更新主机状态,并校验公钥一致:

  • 不存在:按传入内容创建;
  • 已存在:公钥必须逐字节一致,否则返回 ErrTerminalKeyMismatch;更新状态 / 备注 / 自报字段。

enabledAt 非 nil 时写入启用时间。

func (*Store) SaveWorkflowDraft

func (s *Store) SaveWorkflowDraft(ctx context.Context, workflowID string, activeIndex int, draftsJSON string) (*model.WorkflowDraft, error)

SaveWorkflowDraft 保存或更新工作流草稿数据

func (*Store) SearchProject

func (s *Store) SearchProject(ctx context.Context, f ProjectSearchFilter) ([]ProjectSearchHit, error)

SearchProject 在项目的全部文档里搜索(打分排序)。没有关键词时按最近更新排序返回过滤后的文档。

func (*Store) SearchProjectDocs

func (s *Store) SearchProjectDocs(ctx context.Context, workflowID, query string, limit int) ([]docs.SearchHit, error)

SearchProjectDocs 搜索(打分排序)。

func (*Store) SeedBuiltinNorms

func (s *Store) SeedBuiltinNorms(ctx context.Context) error

func (*Store) SeedDefaultAuthProfile

func (s *Store) SeedDefaultAuthProfile(ctx context.Context) error

SeedDefaultAuthProfile 保证至少有一档默认档位;幂等。

func (*Store) SendFeedback

func (s *Store) SendFeedback(ctx context.Context, input model.SendFeedbackInput) (*model.Feedback, error)

func (*Store) SetAgentRunAuthority

func (s *Store) SetAgentRunAuthority(workflowID, conv string, until time.Time)

SetAgentRunAuthority 标记(或撤销)「这个对话正由 Hub 读非交互运行的输出判定状态」,直到 until: 期间 hook 的汇报只留记录、不改状态——运行输出里的事件是确定的,而 hook 在非交互模式下会漏报 stop、退出时还会报一个 sessionEnd。 until 为零值表示撤销。标记到期自动失效:监视协程没来得及收尾(进程崩了、主机失联)也不会永远挡住 hook。

func (*Store) SetAgentScreen

func (s *Store) SetAgentScreen(workflowID string, in AgentScreenInput, now time.Time) AgentScreenChange

SetAgentScreen 登记一个工作流的最新屏幕信号。

func (*Store) SetDefaultAuthProfile

func (s *Store) SetDefaultAuthProfile(ctx context.Context, id uint) (*model.AuthProfile, error)

SetDefaultAuthProfile 把某一档设为默认(原来的默认档位随之变成普通档位,可以删除了)。

func (*Store) SetGroupMemberPolicy

func (s *Store) SetGroupMemberPolicy(ctx context.Context, groupID, memberRef, policy string, mutedUntil *time.Time, clearMute bool) error

SetGroupMemberPolicy 改成员的推送策略 / 免打扰截止时间(memberRef 可以是你自己)。

func (*Store) SetSystemFlag

func (s *Store) SetSystemFlag(ctx context.Context, key string, on bool) error

SetSystemFlag 写入一个布尔系统开关。

func (*Store) SetTerminalArchived

func (s *Store) SetTerminalArchived(ctx context.Context, keys []string, archived bool, now time.Time) (int64, error)

SetTerminalArchived 归档(archived=true)或取消归档一批条目,返回实际发生变化的条数: 重复归档、取消并未归档的条目都不算变化,所以界面上重复点击是安全的。

func (*Store) SetTerminalHostIdle

func (s *Store) SetTerminalHostIdle(ctx context.Context, machineCode string, sec int) (changed bool, err error)

SetTerminalHostIdle 设置主机上会话的默认生命周期(秒,0 = 永久保持),返回是否有变化。

func (*Store) SetTerminalHostModel

func (s *Store) SetTerminalHostModel(ctx context.Context, machineCode string, u HostModelUpdate) (host *model.TerminalHost, changed bool, err error)

SetTerminalHostModel 修改主机的模型访问设置,返回修改后的记录与是否有变化。

func (*Store) SetTerminalHostRecOff

func (s *Store) SetTerminalHostRecOff(ctx context.Context, machineCode string, off bool) (changed bool, err error)

SetTerminalHostRecOff 设置主机的「关闭终端记录」策略,返回是否有变化。

func (*Store) SetTerminalHostRemark

func (s *Store) SetTerminalHostRemark(ctx context.Context, machineCode, remark string) error

SetTerminalHostRemark 修改备注。

func (*Store) SetTerminalHostStatus

func (s *Store) SetTerminalHostStatus(ctx context.Context, machineCode, status string) (changed bool, err error)

SetTerminalHostStatus 修改状态(enabled / disabled / blocked),返回是否真的发生了变化。

func (*Store) SetWaitPolicy

func (s *Store) SetWaitPolicy(ctx context.Context, input model.SetWaitPolicyInput) (*model.MutationResult, error)

func (*Store) SetWorkflowPhase

func (s *Store) SetWorkflowPhase(ctx context.Context, workflowID, phaseID string, isHumanClick bool) error

SetWorkflowPhase 设置工作流当前阶段。旧五段式的阶段 id(assess / verify / done)仍被接受, 落库前统一换成对应的新 id(见 model.CanonicalPhaseID)。

func (*Store) SetWorkflowPhaseConfig

func (s *Store) SetWorkflowPhaseConfig(ctx context.Context, workflowID string, phases []model.PhaseItem) error

func (*Store) SnapshotTo

func (s *Store) SnapshotTo(ctx context.Context, dest string) error

SnapshotTo 把整个数据库另存为一份一致性快照(VACUUM INTO),不阻塞读写;目标文件必须事先不存在。

func (*Store) SoftDeleteProjectDoc

func (s *Store) SoftDeleteProjectDoc(ctx context.Context, docID uint) error

SoftDeleteProjectDoc 硬删(REST delete)。

func (*Store) StreamAnswerDeliveries

func (s *Store) StreamAnswerDeliveries(ctx context.Context, workflowID string, from, to time.Time) ([]model.QueuedFeedback, error)

StreamAnswerDeliveries 取一个时间窗里的确认项答复投递行(kind=answer、origin_ref 不为空), 聊天据此给「你的答复」消息标上已送达 / 已读 / 已处理。窗口取这一页答复的最早与最晚时间,前后各留 2 秒。

func (*Store) StreamAnswers

func (s *Store) StreamAnswers(ctx context.Context, workflowID string, r StreamRange) ([]model.ConfirmItem, error)

StreamAnswers 取你对提问卡 / 计划卡的答复(已作答或已忽略)。

func (*Store) StreamCards

func (s *Store) StreamCards(ctx context.Context, workflowID string, r StreamRange) ([]model.ConfirmItem, error)

StreamCards 取 Agent 的提问卡与计划确认卡(async_ask / 计划);文档决策卡另按文档汇总,见 StreamDecisionItems。

func (*Store) StreamDecisionItems

func (s *Store) StreamDecisionItems(ctx context.Context, workflowID string) ([]model.ConfirmItem, error)

StreamDecisionItems 取一个工作流里全部文档决策项(最多 500 条,按创建时间升序):它们按文档汇总成卡, 汇总要看到同一文档的全部决策,所以不分页,交给 chat 包按边界裁剪。

func (*Store) StreamEndings

func (s *Store) StreamEndings(ctx context.Context, workflowID string, r StreamRange) ([]model.FeedbackSession, error)

StreamEndings 取「等待超时 / 已取消」的汇报(聊天里显示成一行系统文字),时间是最后更新时间。

func (*Store) StreamEvents

func (s *Store) StreamEvents(ctx context.Context, conversationID string, r StreamRange) ([]model.ConversationEvent, error)

StreamEvents 取会话时间线上的系统事件(Agent 收尾、模式切换…)。

func (*Store) StreamGroupMessages

func (s *Store) StreamGroupMessages(ctx context.Context, groupID string, r StreamRange, vis *GroupVisibility, boundSeq int64, inclusive bool) ([]model.ChatMessage, error)

StreamGroupMessages 取群消息。排序键是(时间,序号);vis 不为空时只取可见范围内的。

翻页边界用序号(boundSeq,0 表示没有边界;Older 方向 inclusive 时包含它本身)而不是毫秒:群消息的序号与时间同序(见 PostGroupMessage), 按序号切边界是精确的,不会像按毫秒那样让「同一毫秒的几条」挤占一页的名额。r.Ms 对群无意义。

func (*Store) StreamInbox

func (s *Store) StreamInbox(ctx context.Context, workflowID string, r StreamRange) ([]model.QueuedFeedback, error)

StreamInbox 取你随时追加的话(收件箱),状态由 DeriveState 推导。

func (*Store) StreamMergedInbox

func (s *Store) StreamMergedInbox(ctx context.Context, workflowID string, sessionIDs []string) (map[string][]model.QueuedFeedback, error)

StreamMergedInbox 取被「秒回」并进指定几轮汇报的追加(origin_ref = s:<会话编号>),按被取走的先后排好。 聊天里它们各是一条独立的消息;那一轮的回复只剩合并之外的部分(见 chat.Builder.ReplyAfterMerge)。

func (*Store) StreamNotices

func (s *Store) StreamNotices(ctx context.Context, workflowID string, r StreamRange) ([]model.FeedbackSession, error)

StreamNotices 取 Agent 的进度气泡(interactive_feedback wait:false 发布的 notice)。

func (*Store) StreamReplies

func (s *Store) StreamReplies(ctx context.Context, workflowID string, r StreamRange) ([]model.FeedbackSession, error)

StreamReplies 取你对各轮汇报的回复(含秒回带走的追加)。时间见 replyTimeSQL。

func (*Store) StreamReports

func (s *Store) StreamReports(ctx context.Context, workflowID string, r StreamRange) ([]model.FeedbackSession, error)

StreamReports 取 Agent 的阻塞式汇报(不含进度气泡)。不取你的回复与图片,免得白读大字段。

func (*Store) StreamRetractions

func (s *Store) StreamRetractions(ctx context.Context, workflowID string, r StreamRange) ([]model.QueuedFeedback, error)

StreamRetractions 取你撤回的追加(聊天里显示成「你撤回了一条消息」,不带正文),时间是撤回的时刻。

func (*Store) StreamTaskUpdates

func (s *Store) StreamTaskUpdates(ctx context.Context, workflowID string, since time.Time, r StreamRange) ([]WorkflowUpdate, error)

StreamTaskUpdates 取 Agent 写下的任务进展;since 非零时只要这个时刻之后的(用来对齐「开启异步之后」的口径)。

func (*Store) SubmitFeedback

func (s *Store) SubmitFeedback(ctx context.Context, input SubmitFeedbackInput) (*model.FeedbackSession, error)

func (*Store) SupersedeOldCheckpoints

func (s *Store) SupersedeOldCheckpoints(ctx context.Context, workflowID string, currentRevision int) error

func (*Store) SweepDraftImages

func (s *Store) SweepDraftImages(ctx context.Context, olderThan time.Time) (int64, error)

SweepDraftImages 清理遗弃的草稿图片:最近一次写入早于 olderThan,并且所在工作流已保存的草稿不再引用它 (没有草稿记录也算不再引用)。这是客户端异常退出、草稿被另一台设备整体覆盖时的兜底,正常路径是客户端在草稿销毁时主动删除。

func (*Store) Sync

func (s *Store) Sync(ctx context.Context, input model.SyncInput) (*model.SyncResult, error)

func (*Store) SyncDecisionConfirmItems

func (s *Store) SyncDecisionConfirmItems(ctx context.Context, doc *model.ProjectDoc, body string) (bool, error)

SyncDecisionConfirmItems 在文档保存后,让「文档里的 decision 围栏」与「确认项」保持一致。返回是否改动了数据。

对每个决策 id,只看它最新的一条确认项(序号最大):

  • 没有:新建待处理;
  • 待处理:把展示字段(标题、说明、选项、默认值、风险……)更新成文档里的最新内容,原地保留序号;
  • 已答复:选项没变就保留答复;选项变了(指纹不同)则旧答复作废(expired)并新建一条待处理——答案是针对旧选项给的,不能套到新选项上;
  • 已忽略:选项没变就一直忽略,不会因为再次保存文档而「复活」;选项变了才新建;
  • 已撤回 / 已过期:围栏回来了就重新新建一条。

文档里已经没有的围栏,其待处理项撤回;已答复 / 已忽略的历史保留。文档归档或删除时,待处理项全部撤回。 幂等:内容没变的重复保存不写库、不换序号。

func (*Store) SyncTerminalSessions

func (s *Store) SyncTerminalSessions(ctx context.Context, machineCode string, seen []TerminalSessionSeen, now time.Time) (int, error)

SyncTerminalSessions 用一台主机当前的会话清单更新索引:新会话建行、已有会话刷新标签与录制索引、 已退出的会话记下结束;清单里不再有的运行中会话视为已结束(原因 gone,之后可被精确原因覆盖)。 返回写入(新建或更新)的行数。

func (*Store) TouchAgentIdentity

func (s *Store) TouchAgentIdentity(ctx context.Context, in AgentTouchInput, now time.Time) error

TouchAgentIdentity 记下某个身份刚刚调用过 RelayMesh(以及是不是读类调用)。只更新身份的时间戳,不产生事件; 认不出项目目录就什么都不记。每个 MCP 调用都会走到这里,所以先查内存,写库按 agentIdentityWriteEvery 节流。

func (*Store) TouchCredentialUsage

func (s *Store) TouchCredentialUsage(ctx context.Context, id uint, ip string, at time.Time) error

TouchCredentialUsage 记录令牌最近一次使用的时间与来源,不改动 updated_at。

func (*Store) TouchOAuthClient

func (s *Store) TouchOAuthClient(ctx context.Context, clientID string)

func (*Store) TouchTerminalHost

func (s *Store) TouchTerminalHost(ctx context.Context, machineCode string, seen TerminalHostSeen) error

TouchTerminalHost 刷新主机的最近在线信息(握手成功后调用)。主机不存在时返回 ErrTerminalHostNotFound。

func (*Store) UnarchiveFeedbackSession

func (s *Store) UnarchiveFeedbackSession(ctx context.Context, idOrWorkflow string) (*model.FeedbackSession, error)

func (*Store) UnlinkWorkItemSession

func (s *Store) UnlinkWorkItemSession(ctx context.Context, id uint, sessionID string) error

UnlinkWorkItemSession 解除任务与会话的关联(不影响会话本身)。

func (*Store) UpdateAuthProfile

func (s *Store) UpdateAuthProfile(ctx context.Context, id uint, in AuthProfileInput) (*model.AuthProfile, error)

UpdateAuthProfile 修改一档(含默认档位):只改入参里给了的字段。

func (*Store) UpdateCheckpointStatus

func (s *Store) UpdateCheckpointStatus(ctx context.Context, workflowID string, revision int, status string) error

func (*Store) UpdateCredential

func (s *Store) UpdateCredential(ctx context.Context, id uint, updates map[string]any) (*model.MCPCredential, error)

func (*Store) UpdateGroup

func (s *Store) UpdateGroup(ctx context.Context, groupID string, in UpdateGroupInput) (*model.Conversation, error)

UpdateGroup 改群名 / 绑定项目 / 归档(归档后只读保留,可恢复)。

func (*Store) UpdateInboxConfig

func (s *Store) UpdateInboxConfig(ctx context.Context, mutate func(cur InboxConfig) InboxConfig) (InboxConfig, error)

UpdateInboxConfig 在事务里读—改—写收件箱开关。

func (*Store) UpdateNote

func (s *Store) UpdateNote(ctx context.Context, id uint, content string) error

func (*Store) UpdateNotifyPrefs

func (s *Store) UpdateNotifyPrefs(ctx context.Context, mutate func(cur notify.Prefs) (notify.Prefs, error)) (notify.Prefs, error)

UpdateNotifyPrefs 在一个事务里「读—改—写」:mutate 拿到当前偏好、返回新偏好(或返回错误拒绝这次修改)。 新偏好经 Normalize 与 Validate 之后才写入;校验不过返回包装了 notify.ErrInvalidPrefs 的错误,库里保持原样。

func (*Store) UpdateNtfyConfig

func (s *Store) UpdateNtfyConfig(ctx context.Context, mutate func(cur ntfy.Config) ntfy.Config) (ntfy.Config, error)

UpdateNtfyConfig 在一个事务里「读—改—写」:mutate 拿到当前配置、返回新配置; 新配置经 Normalize 与校验后才写入,校验不过返回 ntfy.ErrInvalidConfig(不写库)。 启用时主题必填;关闭状态下允许保存只填了一半的配置。

func (*Store) UpdateOAuthGrantCredential

func (s *Store) UpdateOAuthGrantCredential(ctx context.Context, grantID, credID uint) error

func (*Store) UpdateOAuthGrantRefresh

func (s *Store) UpdateOAuthGrantRefresh(ctx context.Context, id uint, newHash string, graceUntil *time.Time) error

func (*Store) UpdateOAuthGrantRefreshIdle

func (s *Store) UpdateOAuthGrantRefreshIdle(ctx context.Context, grantID uint, idle *time.Time) error

func (*Store) UpdateOAuthGrantRefreshMeta

func (s *Store) UpdateOAuthGrantRefreshMeta(ctx context.Context, grantID uint, hash string, idle, abs *time.Time) error

func (*Store) UpdateProject

func (s *Store) UpdateProject(ctx context.Context, id uint, patch ProjectPatch) (*model.Project, error)

func (*Store) UpdateProjectDoc

func (s *Store) UpdateProjectDoc(ctx context.Context, docID uint, patch ProjectDocPatch, actor DocActor) (*ProjectDocSaveResult, error)

UpdateProjectDoc 更新文档(expected_rev 冲突返回 ErrConflict)。

func (*Store) UpdateSSHConn

func (s *Store) UpdateSSHConn(ctx context.Context, code string, u SSHConnUpdate) error

UpdateSSHConn 更新 SSH 主机的连接信息;记录不存在或不是 SSH 主机时返回 ErrTerminalHostNotFound。

func (*Store) UpdateSessionMaxChecks

func (s *Store) UpdateSessionMaxChecks(ctx context.Context, idOrWorkflow string, maxChecks int) (*model.FeedbackSession, error)

func (*Store) UpdateSessionPromptWait

func (s *Store) UpdateSessionPromptWait(ctx context.Context, idOrWorkflow string, waitMinutes int) (*model.FeedbackSession, error)

func (*Store) UpdateSessionWaitCountdown

func (s *Store) UpdateSessionWaitCountdown(ctx context.Context, idOrWorkflow string, countdownMinutes int) (*model.FeedbackSession, error)

func (*Store) UpdateSessionWaitCountdownSeconds

func (s *Store) UpdateSessionWaitCountdownSeconds(ctx context.Context, idOrWorkflow string, seconds int) (*model.FeedbackSession, error)

UpdateSessionWaitCountdownSeconds 按秒设置挂起倒计时(秒回 0 / 30 / 60 …)。 同步写入分钟列(向上取整),旧界面和旧二进制读到的仍然是一个合理的值。

func (*Store) UpdateStages

func (s *Store) UpdateStages(ctx context.Context, input model.UpdateStagesInput) (*model.MutationResult, error)

func (*Store) UpdateTask

func (s *Store) UpdateTask(ctx context.Context, input model.UpdateTaskInput) (*model.MutationResult, error)

func (*Store) UpdateTaskHeartbeat

func (s *Store) UpdateTaskHeartbeat(ctx context.Context, projectID, taskID, role, sessionID string) error

func (*Store) UpdateTerminalGuardState

func (s *Store) UpdateTerminalGuardState(ctx context.Context, now time.Time, mutate func(*GuardStateDoc)) (GuardStateDoc, error)

UpdateTerminalGuardState 在一个事务里「读—改—写」守护状态,并清理过期记录;返回写入后的文档。

func (*Store) UpdateTerminalPrefs

func (s *Store) UpdateTerminalPrefs(ctx context.Context, mutate func(*TerminalPrefs)) (TerminalPrefs, error)

UpdateTerminalPrefs 在一个事务里「读—改—写」终端偏好,避免两个设置项同时保存时互相覆盖。 mutate 只改自己关心的字段;改完的结果必须通过 Validate,否则不写入并返回 ErrInvalidTerminalPrefs。

func (*Store) UpdateTerminalRun

func (s *Store) UpdateTerminalRun(ctx context.Context, runID string, fields map[string]any) (bool, error)

UpdateTerminalRun 无条件更新一条运行记录的指定字段,返回是否命中了记录。

func (*Store) UpdateTerminalRunIf

func (s *Store) UpdateTerminalRunIf(ctx context.Context, runID string, fromStates []string, fields map[string]any) (bool, error)

UpdateTerminalRunIf 只有当记录当前处于 fromStates 之一时才更新,返回是否生效。 终态不会被反向覆盖:服务端据此保证「一次运行只会有一个终态」。

func (*Store) UpdateUserNorm

func (s *Store) UpdateUserNorm(ctx context.Context, name string, updates map[string]any) (*model.UserNorm, error)

func (*Store) UpdateWorkItem

func (s *Store) UpdateWorkItem(ctx context.Context, id uint, patch WorkItemPatch, actor WorkActor) (*WorkItemResult, error)

UpdateWorkItem 更新任务。没有任何变化时不写库,Changed 为 false。

func (*Store) UpdateWorkModule

func (s *Store) UpdateWorkModule(ctx context.Context, id uint, patch WorkModulePatch) (*model.WorkModule, error)

UpdateWorkModule 修改模块的名称或说明(不动位置与归属)。

func (*Store) UpdateWorkflowMode

func (s *Store) UpdateWorkflowMode(ctx context.Context, workflowID string, patch ModePatch, now time.Time) (ModeInfo, error)

UpdateWorkflowMode 开关异步对话 / 选档位。

开启需要「环境允许」:这个工作流至少被服务端见过一次 hook(即使现在已经过期——过期只会让它降级, 用户可以先开着,等 hook 回来自动生效)。从没见过 hook 说明编辑器里根本没装,此时开启没有意义, 返回冲突并让界面引导安装。关闭永远允许。

func (*Store) UpsertProjectModule

func (s *Store) UpsertProjectModule(ctx context.Context, projectID uint, in ModuleInput) (*model.ProjectModule, error)

UpsertProjectModule 按路径创建或修改模块。父级模块不存在会一并补建(标题取路径末段),保证树是连通的。

func (*Store) UpsertTerminalLauncher

func (s *Store) UpsertTerminalLauncher(ctx context.Context, l TerminalLauncher) ([]TerminalLauncher, bool, error)

UpsertTerminalLauncher 新增一条预设,或按编号覆盖已有的那一条;返回保存后的全部预设,以及这次是不是新增。 名字不能与别的预设重名;新增时数量不能超过上限(覆盖已有的不受限)。

func (*Store) WithTx

func (s *Store) WithTx(ctx context.Context, fn func(tx *gorm.DB) error) error

func (*Store) WithdrawConfirmItem

func (s *Store) WithdrawConfirmItem(ctx context.Context, workflowID, ref string, agentOnly bool) (*model.ConfirmItem, error)

WithdrawConfirmItem 撤回一条待处理的确认项(智能体撤回自己提的问题)。 agentOnly=true 时只能撤回智能体创建的:文档决策卡由文档内容决定,智能体不能绕过文档去撤销。

func (*Store) WithdrawDocPendingConfirms

func (s *Store) WithdrawDocPendingConfirms(ctx context.Context, docID uint) error

WithdrawDocPendingConfirms 文档归档 / 删除时,撤回它所有待处理的决策项。

func (*Store) WorkDigestFor

func (s *Store) WorkDigestFor(ctx context.Context, workflowID string) (*WorkDigest, error)

WorkDigestFor 汇总工作流所在任务板的概况:各状态数量、规划节点数与最近更新的未结束任务。 同一个项目的工作流共用一张板,所以概况是整张板的;单工作流的板与按工作流统计完全一致。

func (*Store) WorkModuleScope

func (s *Store) WorkModuleScope(ctx context.Context, moduleID uint) ([]uint, error)

WorkModuleScope 返回一个模块及其下属功能的 ID(任务列表按模块筛选时包含功能里的任务)。

func (*Store) WorkflowBinding

func (s *Store) WorkflowBinding(ctx context.Context, workflowID string) (host, dir string)

WorkflowBinding 返回工作流上记录的主机与项目目录(最近一个带目录的反馈会话的);没有记录就是两个空串。 网页新建的占位行没有目录,不算数;智能体自己的汇报才带主机与目录。

func (*Store) WorkflowBindingOf

func (s *Store) WorkflowBindingOf(ctx context.Context, workflowID string) (*WorkflowBinding, error)

WorkflowBindingOf 返回一个工作流当前的绑定画像;工作流不存在时返回 NotFound。

func (*Store) WorkflowBoundDirectory

func (s *Store) WorkflowBoundDirectory(ctx context.Context, workflowID string) (string, error)

WorkflowBoundDirectory 返回这个工作流此刻被绑定的项目目录,口径与汇报路径上的 D-161 所有权校验完全一致: 取这个工作流里 id 最小的那一行,目录去首尾空白后用 filepath.Clean 规整;没有会话行、那一行没有目录、 或规整后是 "." 时返回空串(= 没有绑定,智能体第一次汇报带什么目录都行)。 「启用 Agent」据此提前告诉用户:在主机上选的运行目录与绑定的目录不一致时,智能体的第一次汇报会被拒绝。

func (*Store) WorkflowIdentityID

func (s *Store) WorkflowIdentityID(ctx context.Context, workflowID string) uint

WorkflowIdentityID 是工作流绑定的身份:先看对话会话(agent_sessions),再按最近一次汇报会话的目录找身份。认不出返回 0。

func (*Store) WorkflowModeInfo

func (s *Store) WorkflowModeInfo(ctx context.Context, workflowID string, now time.Time) (ModeInfo, error)

WorkflowModeInfo 读取并判定某个工作流的异步状态。热路径(每条回执都会问一次): 没开启过异步的工作流只多一次主键查询。

func (*Store) WorkflowTitleOf

func (s *Store) WorkflowTitleOf(ctx context.Context, workflowID string) string

WorkflowTitleOf 是工作流在界面上显示的名字:用户锁定的自定义标题优先,没有就取最近一条带标题的会话的标题;都没有返回空串。 只读、两次主键 / 索引查询;给 MCP 的 preset_run 这类要「用人话指一个工作流」的地方用(#179)。

type StreamDir

type StreamDir int

StreamDir 是取流的方向。

const (
	// StreamOlder 从边界往更早的方向取(没有边界就是最新的一页)。
	StreamOlder StreamDir = iota
	// StreamNewer 从边界往更新的方向取。
	StreamNewer
)

type StreamRange

type StreamRange struct {
	Dir StreamDir
	// Ms 是边界的 Unix 毫秒;0 表示没有边界。Older 包含这一毫秒(由调用方按完整排序键再裁掉边界之外的),Newer 同理。
	Ms int64
	// Limit 是每个来源最多取多少条。调用方传「页大小 + 1」:多出来的一条用来判断还有没有更多。
	Limit int
	// Query 是子串搜索词;空表示不搜。
	Query string
}

StreamRange 约束一次取流。

type SubmitFeedbackInput

type SubmitFeedbackInput struct {
	SessionID    string               `json:"session_id"`
	ResponseText string               `json:"response_text"`
	UserMessages []string             `json:"user_messages,omitempty"`
	Images       []model.SessionImage `json:"images,omitempty"`
}

type TerminalHostSeen

type TerminalHostSeen struct {
	Hostname     string
	OS           string
	Arch         string
	AgentVersion string
	AgentRev     string
	Privilege    string
	IP           string
	At           time.Time
}

TerminalHostSeen 是每次握手成功后要刷新的「自报且已净化」字段。

type TerminalLauncher

type TerminalLauncher struct {
	// ID 由界面生成,保存后不变;增删改都按它定位,所以两个浏览器同时改不同的预设不会互相覆盖。
	ID string `json:"id"`
	// Name 同时是新建会话的名字:启动器靠「主机 + 名字」认出这个预设已经在运行的会话(见前端 lib/terminal/launcher.ts),
	// 所以预设之间不能重名。
	Name string `json:"name"`
	// Host 是目标主机的机器码。
	Host string `json:"host"`
	// Dir 是会话启动时所在的目录;留空表示主机的默认目录。
	Dir string `json:"dir,omitempty"`
	// Command 是会话就绪后自动输入并回车的命令;留空表示只打开一个终端。它是一整行,不含换行与控制字符。
	Command string `json:"command,omitempty"`
	// Guard 是可选的「会话守护」:监测这个预设启动的智能体会话有没有意外退出或停摆,并给出一键唤醒。
	// nil 表示没配置过(旧存档都是这种)。旧版本读到带 guard 的存档会忽略它——回滚后守护配置会丢,预设本身不受影响。
	Guard *LauncherGuard `json:"guard,omitempty"`
	// Kind 是预设类型:空串(默认,旧存档都是这种)= 开终端;LauncherKindHeadless = 非交互续聊(见 HeadlessRun)。
	// 旧版本读到非交互续聊预设,会把它当成一个没有命令的终端预设——回滚后这种预设的运行配置会丢,其余预设不受影响。
	Kind string `json:"kind,omitempty"`
	// Run 是非交互续聊的运行配置,只在 Kind == LauncherKindHeadless 时有。
	Run *HeadlessRun `json:"run,omitempty"`
}

TerminalLauncher 是一条启动预设。

func (TerminalLauncher) IsHeadless

func (l TerminalLauncher) IsHeadless() bool

IsHeadless 表示这是一条「非交互续聊」预设。

func (TerminalLauncher) Normalize

func (l TerminalLauncher) Normalize() TerminalLauncher

Normalize 规整各字段:名字是单行文本,各种空白(含换行、制表)折叠成一个普通空格;其余字段只去掉首尾空白。 命令里的空白(含中间的空格)一律保持原样。

func (TerminalLauncher) Validate

func (l TerminalLauncher) Validate() error

Validate 检查一条(已规整的)预设;错误信息面向用户,并带上出问题的字段。

type TerminalPrefs

type TerminalPrefs struct {
	// FixedCols 大于 0 时开启「宽度保持」:每个会话的终端都固定为这个列数,浏览器窗口再窄也不改变,
	// 窗口放不下就缩小字号去适配;0 表示关闭,终端宽度跟随浏览器窗口(默认)。
	FixedCols int `json:"fixed_cols"`
	// RecordMaxLines 大于 0 时开启「终端限高」:每个会话在主机上的记录至少保留最近这么多行输出,
	// 更早的内容按分段滚动丢弃;0 表示不按行数限制(默认,仍受字节配额约束)。
	RecordMaxLines int `json:"record_max_lines"`
	// AgentAutoUpgrade 是 Hub 的「Agent 自动升级」总闸(默认关):关着时,Hub 对主机 Agent 的版本检查一律回答「不提供」,
	// 即使某台主机的所有者已经在本机开启了自动升级。打开它并不会让任何主机自动升级——每台主机仍需要它的所有者在本机同意。
	AgentAutoUpgrade bool `json:"agent_auto_upgrade"`
}

TerminalPrefs 是终端的服务端偏好:保存在 Hub 里,所有浏览器共享,换设备查看时保持一致。

func (TerminalPrefs) Validate

func (p TerminalPrefs) Validate() error

Validate 检查取值范围;错误信息面向用户。

type TerminalSessionEnd

type TerminalSessionEnd struct {
	SID       string
	Name      string
	StartedAt int64
	EndedAt   time.Time // 零值表示「现在」
	Reason    string
}

TerminalSessionEnd 描述一个会话已经结束及原因。会话不在索引里时按这里的信息补建一行 (例如主机重启后守护进程报告的「已丢失会话」:它们的记录仍在主机磁盘上,值得保留入口)。

type TerminalSessionSeen

type TerminalSessionSeen struct {
	SID       string
	Name      string
	Shell     string
	StartedAt int64
	Exited    bool
	ExitCode  *int
	Rec       string
	RecBytes  int64
	RecFirst  int64
	RecLast   int64
	RecGap    bool
}

TerminalSessionSeen 是 Agent 报告的一个会话的快照(字段均已净化)。 只含标签与录制索引,不含任何终端内容。

type ThreadFilter

type ThreadFilter struct {
	Target       string
	CredentialID uint
	Limit        int
}

ThreadFilter 是线程汇总的过滤条件。

type ThreadStat

type ThreadStat struct {
	ThreadKey string `json:"thread_key"`
	Total     int64  `json:"total"`
	Active    int64  `json:"active"`
	Awaiting  int64  `json:"awaiting"`
	FirstID   uint   `json:"first_id"`
	LastID    uint   `json:"last_id"`
}

ThreadStat 是一个线程(线程键)的汇总:运行总数、进行中与待批准的数量,以及首末两条运行的主键。

type UpdateGroupInput

type UpdateGroupInput struct {
	Title     *string
	ProjectID *string
	Archived  *bool
}

UpdateGroupInput 是改群设置的入参,nil 表示不改。

type WorkActor

type WorkActor struct {
	Kind      string // model.WorkActorHuman 或 model.WorkActorAgent
	SessionID string // 可选
	// 以下三项只对智能体有意义(#175 B2,见 work_assign.go):人在 Web 上写入恒不做任务级判定。
	WorkflowID string     // 智能体自己的工作流(MCP 的 workflow_id);用来判定「是不是自己的任务」,也记在时间线上
	Manager    bool       // 持有该项目任务板的管理授权(由 MCP 层按授权表判定后填入)
	Policy     WorkPolicy // 任务级权限策略;零值 = 不检查
}

WorkActor 描述一次写入是谁做的、发生在哪个会话里。

type WorkDigest

type WorkDigest struct {
	Counts  map[string]int
	Total   int
	Modules int
	// Unassigned 是还没有归入任何模块的未结束任务数(只数叶子任务,与模块汇总的口径一致)。
	Unassigned int
	// Latest 是最近更新的未结束任务(没有时为 nil)。
	Latest *model.WorkItem
}

WorkDigest 是工作流任务清单的一句话概况,供回执头与概览使用。

type WorkItemFilter

type WorkItemFilter struct {
	WorkflowID string
	States     []string
	Kinds      []string
	Stages     []string // 阶段;包含空串或 "none" 表示「未标注」
	SessionID  string   // 非空:只要与这个会话关联的任务,并附上这个会话对每条任务做了什么(SessionCtx)
	Query      string
	ParentID   *uint
	TopLevel   bool // 只要顶层任务(没有父任务的)
	ModuleID   uint // >0:只要这个模块(含它下面各功能)里的任务
	Unassigned bool // 只要未归类的任务(优先于 ModuleID)
	ClosedDays int  // >0:已关闭的任务只保留最近 N 天内关闭的
	Limit      int  // 0 = 默认 500
	// Assignee:工作流编号 = 只要指派给它的任务;"none" = 只要没有指派的任务;空 = 不过滤(#175 B2)。
	Assignee string
	// AssignedBy:只要这个工作流派出的任务(空 = 不过滤)。
	AssignedBy string
}

WorkItemFilter 是列表的筛选条件。

type WorkItemInput

type WorkItemInput struct {
	WorkflowID string
	Title      string
	Kind       string // 空 = feature
	Stage      string // 空 = 未标注
	State      string // 空 = todo
	Labels     []string
	Refs       []string
	// Description 是任务内容的说明(这件事是什么、做到什么算完成);标题和进度都说不清时靠它。
	Description string
	Progress    string
	Note        string
	ParentID    uint // 0 = 没有父任务
	ModuleID    uint // 0 = 未归类
	Percent     *int // nil = 由状态 / 子任务推导;0–100 = 显式完成度
	// Assignee 非空 = 创建时同时指派给这个工作流(管理 Agent / 人;必须是同一张项目板上的工作流)。
	Assignee string
}

WorkItemInput 是新建任务的参数。

type WorkItemPatch

type WorkItemPatch struct {
	Title  *string
	Kind   *string
	Stage  *string // 指向空串 = 清除(回到未标注)
	State  *string
	Labels *[]string
	Refs   *[]string
	// Description 指向空串 = 清除;只改描述不动 updated_at、不写时间线(见 model.WorkItem.Description)。
	Description *string
	Progress    *string
	Conclusion  *string
	ParentID    *uint // 指向 0 表示解除父任务
	ModuleID    *uint // 指向 0 表示取消归类
	Percent     *int  // -1 表示清除显式完成度(回到由状态推导)
	Note        string
	// Assignee 指向工作流编号 = 指派 / 改派;指向空串 = 撤销指派;nil = 不变(#175 B2)。
	Assignee *string
	// Claim 是显式的协作动作:accept / decline / deliver / accept_delivery / reject_delivery;空 = 无。
	// 与 Assignee 不能同时给。承接者直接改状态也能隐式表达接取 / 交付,见 work_assign.go。
	Claim string
}

WorkItemPatch 是更新任务的参数:指针为 nil 的字段保持不变。

type WorkItemResult

type WorkItemResult struct {
	Item *model.WorkItem
	// Changed 为 false 表示这次调用没有产生任何变化(没有写库)。
	Changed bool
	// SessionLinked 表示本次传入的会话已与任务关联(会话不存在时为 false)。
	SessionLinked bool
	// Violations 只在策略为 audit 时有值:这次写入照常执行了,但若启用强制会被拒绝,每条是一句原因,
	// 调用层据此写审计(would_deny)。
	Violations []string
}

WorkItemResult 是一次写入的结果。

type WorkModuleDeleteResult

type WorkModuleDeleteResult struct {
	Module          model.WorkModule `json:"module"`
	MovedTasks      int              `json:"moved_tasks"`
	RemovedFeatures int              `json:"removed_features"`
}

WorkModuleDeleteResult 是删除模块的结果。

type WorkModuleList

type WorkModuleList struct {
	Modules    []model.WorkModule    `json:"modules"`
	Unassigned model.WorkModuleStats `json:"unassigned"`
}

WorkModuleList 是一个工作流的规划树(按树的顺序拍平)与「未归类」的任务汇总。

type WorkModulePatch

type WorkModulePatch struct {
	Name        *string
	Description *string
}

WorkModulePatch 是修改模块的参数:指针为 nil 的字段保持不变。

type WorkPlanNode

type WorkPlanNode struct {
	Name        string
	Description *string // nil = 不改说明
	Rename      string  // 非空 = 把 Name 改成它
	Remove      bool    // 移除这个节点(必须没有任务也没有剩余的功能)
	Features    []WorkPlanNode
}

WorkPlanNode 是一次「规划」调用里的一个节点(模块或功能)。

type WorkPlanResult

type WorkPlanResult struct {
	Created   []string `json:"created,omitempty"`
	Renamed   []string `json:"renamed,omitempty"`
	Updated   []string `json:"updated,omitempty"`
	Removed   []string `json:"removed,omitempty"`
	Unchanged int      `json:"unchanged,omitempty"`
	// Reordered 表示 reorder=true 时同级顺序确实发生了变化。
	Reordered bool `json:"reordered,omitempty"`
}

WorkPlanResult 是规划调用的结果摘要(节点都用完整路径表示)。

func (*WorkPlanResult) Changed

func (r *WorkPlanResult) Changed() bool

Changed 表示这次规划是否真的改动了规划树(新建 / 改名 / 改说明 / 移除 / 顺序变化)。

type WorkPolicy

type WorkPolicy int

WorkPolicy 是任务级权限的策略档位,零值 = 不检查。

const (
	WorkPolicyOff     WorkPolicy = iota // 不检查:人在 Web 上、项目没开访问控制、独立板
	WorkPolicyAudit                     // 违规照常执行,原因记进 WorkItemResult.Violations 交给调用层记审计
	WorkPolicyEnforce                   // 违规直接拒绝
)

type WorkflowBinding

type WorkflowBinding struct {
	WorkflowID string   `json:"workflow_id"`
	Dirs       []string `json:"dirs"`     // 名下出现过的不同 project_directory,正常只有一个
	Hosts      []string `json:"hosts"`    // 名下出现过的不同 host_name(空值不计)
	Sessions   int64    `json:"sessions"` // feedback_sessions 行数
	Pending    int64    `json:"pending"`  // 其中仍在等待用户回复的
	Queued     int64    `json:"queued"`   // queued_feedbacks 行数
}

WorkflowBinding 是一个工作流当前绑定的「项目目录 + 主机」画像。

type WorkflowBrief

type WorkflowBrief struct {
	WorkflowID string
	ProjectDir string
	HostName   string
}

WorkflowBrief 是一个有过交互的工作流的概况(建群时的候选来源之一)。

type WorkflowStat

type WorkflowStat struct {
	WorkflowID string   `json:"workflow_id"`
	BoardKey   string   `json:"board_key,omitempty"`
	Members    []string `json:"workflows,omitempty"`
	// BoardName 是项目板所属项目的名称,只在多个工作流共用这张板时才带(界面给共享板起名用);
	// 独立板与只有一个工作流的板省略,界面照旧用会话标题 / 工作流编号。
	BoardName string `json:"board_name,omitempty"`
	Total     int    `json:"total"`
	Active    int    `json:"active"`
	// Doing / Review 是会话页头「任务」入口上的计数:进行中的数量,以及验证中的数量(都是智能体手上的活,不需要用户处理)。
	Doing     int       `json:"doing"`
	Review    int       `json:"review"`
	UpdatedAt time.Time `json:"updated_at"`
}

WorkflowStat 是某个工作流下任务的概况,供界面做工作流筛选。

同一个项目的工作流共用一张任务板(#175):每个有任务的工作流各占一条,数字是整张板的; BoardKey / Members 说明它在哪张板、板上有哪些工作流(只有一个时省略),界面可据此去重。

type WorkflowUpdate

type WorkflowUpdate struct {
	ID uint `json:"id"`
	// Seq / Title / State 是任务本身的序号、标题与当前状态(State 不是这次更新当时的状态,当时的在 ToState)。
	Seq   int    `json:"seq"`
	Title string `json:"title"`
	State string `json:"state"`
	// FromState / ToState 只有这次更新改了状态时才有;创建任务那一条只有 ToState。
	FromState string    `json:"from_state,omitempty"`
	ToState   string    `json:"to_state,omitempty"`
	Text      string    `json:"text,omitempty"`
	ActorKind string    `json:"actor_kind"`
	CreatedAt time.Time `json:"created_at"`
}

WorkflowUpdate 是会话时间线上的一条任务进展:一条更新记录,外加它所属任务的序号 / 标题 / 当前状态。 会话页的进展卡「每次更新一张」,靠它按提交时间排进对话(#105)。

Jump to

Keyboard shortcuts

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