feat(agent): 新增通用 {{.Now}} 提示词变量(每轮实时渲染)

- 各 agent 渲染路径(chat/worker/mainagent/goals/planner)统一提供 Now(nowStr());
  自定义会话 agent 每次触发都会重新 renderSystem,故 {{.Now}} 每轮实时刷新
- server 端 globalPromptVars + withGlobalVars:在保存校验/变量列表/预览/详情放行
  {{.Now}},否则引用它的自定义提示词会被 validateTemplate 拒绝
- 无 DB 迁移(handler 层注入通用变量,不动 agent_prompt_vars 表)
- 用途:配合固定的开始时间戳相减,判断"已运行多久/是否进入最后N小时"
- 新增 agent/prompt_now_test.go:{{.Now}} 渲染实时时间、未知变量安全回退
This commit is contained in:
Autumn-27 committed 2026-08-11 10:45:02 -04:00
1 parent 7afff7e5f5
commit 7064216188
8 files changed
+86 -14

No files matched your search

+9 -2
View File
@@ -3,6 +3,7 @@ package agent
import (
"bytes"
"text/template"
"time"
)
// PromptOverride, if set, returns the stored system-prompt template for an agent
@@ -15,10 +16,16 @@ var PromptOverride func(agentKey string) (string, bool)
// user template referencing a catalog variable renders; referencing anything else
// fails template execution and falls back to the built-in default.
type PlannerVars struct{ Goal, Scope, AssetSummary, Now string }
type WorkerVars struct{ ProxyAddr, WorkerName string }
type MainVars struct{ Goal, AssetSummary, FindingsSummary string }
type WorkerVars struct{ ProxyAddr, WorkerName, Now string }
type MainVars struct{ Goal, AssetSummary, FindingsSummary, Now string }
type GoalsVars struct{ EngagementDescription, Now string }
// nowStr is the server-local wall-clock string exposed as the universal {{.Now}}
// prompt variable. renderSystem runs on every agent turn/round, so this is fresh
// each run — a prompt can subtract it from a fixed start stamp to reason about
// elapsed time (e.g. a timed benchmark's "last N hours" window).
func nowStr() string { return time.Now().Format("2006-01-02 15:04:05 MST") }
// renderSystem returns the rendered system-prompt BODY (段 [A]) for agentKey.
// Precedence: the DB-stored template (if any) over the built-in default template
// (def). BOTH are Go templates now — the built-in default is seeded into the DB