diff --git a/profile.go b/profile.go index df22360..6dfa9e1 100644 --- a/profile.go +++ b/profile.go @@ -11,6 +11,9 @@ type AgentProfile struct { Builtin bool `json:"builtin,omitempty"` Source string `json:"source,omitempty"` // builtin | plugin | user SystemPrompt string `json:"systemPrompt"` + // PromptModules 引用提示词库模块 ID(有序;空 = 组装默认基座全集)。 + // SystemPrompt 兼容保留:非空时作为附加段追加在模块组装结果之后。 + PromptModules []string `json:"promptModules,omitempty"` Model ModelRoute `json:"model"` Tools ToolPolicy `json:"tools"` Context ContextPolicy `json:"context"` diff --git a/prompts.go b/prompts.go new file mode 100644 index 0000000..66fd5b1 --- /dev/null +++ b/prompts.go @@ -0,0 +1,71 @@ +package core + +// 提示词模块契约(prompt-library):提示词从代码移入数据,按层组装、按触发注入。 +// +// 分层(Layer): +// - base 常驻基座块(身份/行为/谨慎/工具/风格),始终组装 +// - env 动态环境段(占位符填充:日期/模型/附件清单) +// - task 任务技能(触发命中才注入;同层只注入优先级最高者) +// - agent 子代理/小队角色提示词(派生 run 时取用) +// - tool 工具描述文案(ToolDecl.description 的数据来源) +// - aux 辅助模板(压缩摘要/标题生成等;入库先行,接线随功能走) +// - style 输出风格(叠加在基座之上的表达方式变体) +type PromptModule struct { + ID string `json:"id"` // "base.identity" / "task.doc-minutes" + Layer string `json:"layer"` // base|env|task|agent|tool|aux|style + Version int `json:"version"` // 内置升级判定 + Title string `json:"title"` + Description string `json:"description"` // 给人看(设置界面/命令菜单) + Priority int `json:"priority,omitempty"` // task 层多命中时的取舍;缺省 50,大者优先 + Triggers []PromptTrigger `json:"triggers,omitempty"` // 空 = 基座,始终组装 + RequiresAttachments bool `json:"requiresAttachments,omitempty"` // 命中还需本轮有附件 + Body string `json:"body"` // 模板正文,{{placeholder}} 占位 + OutputContract string `json:"outputContract,omitempty"` // 期望产出形态(注入模型 + 供验收) + Source string `json:"source,omitempty"` // builtin | plugin | user + Owner string `json:"owner,omitempty"` + BasedOnVersion int `json:"basedOnVersion,omitempty"` // 用户副本基于的内置版本 + Drifted bool `json:"drifted,omitempty"` // 用户副本落后于当前内置版本(提示用,不阻断) + Disabled bool `json:"disabled,omitempty"` // 用户停用 +} + +// PromptTrigger 触发条件;模块命中 = 任一 trigger 命中(再过 RequiresAttachments)。 +type PromptTrigger struct { + Kind string `json:"kind"` // intent | command | attachment | manual + Keywords []string `json:"keywords,omitempty"` + Command string `json:"command,omitempty"` // "/minutes" +} + +// 触发 Kind 常量。 +const ( + TriggerIntent = "intent" + TriggerCommand = "command" + TriggerAttachment = "attachment" + TriggerManual = "manual" +) + +// 层常量。 +const ( + LayerBase = "base" + LayerEnv = "env" + LayerTask = "task" + LayerAgent = "agent" + LayerTool = "tool" + LayerAux = "aux" + LayerStyle = "style" +) + +// PromptBlock 组装产物:一个已解析占位符的 system 段。 +type PromptBlock struct { + ModuleID string `json:"moduleId"` + Version int `json:"version"` + Layer string `json:"layer"` + Body string `json:"body"` +} + +// PromptHitRecord 触发判定记录(可观测:哪个技能因何种原因注入/让位)。 +type PromptHitRecord struct { + ModuleID string `json:"moduleId"` + Layer string `json:"layer"` + Reason string `json:"reason"` // "intent:纪要" / "command:/minutes" / "always" / "superseded-by:" + Injected bool `json:"injected"` +} diff --git a/ts/types.ts b/ts/types.ts index 1d7616b..f713e6b 100644 --- a/ts/types.ts +++ b/ts/types.ts @@ -191,11 +191,32 @@ export interface UIField { options?: string[]; required?: boolean; placeholder?: string; help?: string; default?: string; } +// ---- 提示词库(prompt-library)---- + +export interface PromptTrigger { + kind: 'intent' | 'command' | 'attachment' | 'manual'; + keywords?: string[]; command?: string; +} + +export interface PromptModule { + id: string; layer: 'base' | 'env' | 'task' | 'agent' | 'tool' | 'aux' | 'style'; + version: number; title: string; description?: string; priority?: number; + triggers?: PromptTrigger[]; requiresAttachments?: boolean; + body: string; outputContract?: string; + source?: 'builtin' | 'plugin' | 'user'; owner?: string; + basedOnVersion?: number; drifted?: boolean; disabled?: boolean; +} + +export interface PromptBlock { moduleId: string; version: number; layer: string; body: string; } +export interface PromptHitRecord { moduleId: string; layer: string; reason: string; injected: boolean; } + // ---- 画像 / 设置 ---- export interface AgentProfile { id: string; owner?: string; name: string; description?: string; builtin?: boolean; source?: string; systemPrompt: string; + /** 提示词库模块引用(有序;空 = 默认 base+env 全集)。 */ + promptModules?: string[]; model: { chat?: string; lightweight?: string; embedding?: string; rerank?: string }; tools: { allow: string[]; deny?: string[]; confirm?: string[] }; context: {