- 新表 task_constraints(allow/deny),CREATE TABLE IF NOT EXISTS 无需迁移 - 新工具 set_constraints:目标拆解器 round-0 先抽约束再拆目标、主 agent 运行时可补; 拆解器提示词要求约束自包含(把「当前目标」等指代替换成具体域名/端口) - constraintBlock 按最高优先级注入 planner+worker 系统提示;去偏:多样性/拓面显式服从约束 - 注入范围可配置(constraints_inject_planner/worker,默认都开,每轮读、即时生效) - 总览「约束管理」卡片 + CRUD 接口(增删改不通知 planner,下轮规划自然读到) - goals 提示词把抽约束步并入可编辑正文;旧库经 flag 守卫的一次性 reseed 追加新默认版本
50 lines
1.6 KiB
Go
50 lines
1.6 KiB
Go
package agent
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/Autumn-27/artex/db"
|
|
)
|
|
|
|
// constraintBlock renders this task's operation constraints (task_constraints) as a
|
|
// high-priority block appended to the planner/worker system prompt. allow/deny are
|
|
// grouped; empty string when there are no constraints (or ts is nil). The framing
|
|
// deliberately puts these ABOVE the exploration/expansion heuristics so a declared
|
|
// boundary wins the tug-of-war against "chase another entry surface".
|
|
func constraintBlock(ts *db.ExplorationStore) string {
|
|
if ts == nil {
|
|
return ""
|
|
}
|
|
rows, err := ts.ListConstraints()
|
|
if err != nil || len(rows) == 0 {
|
|
return ""
|
|
}
|
|
var allow, deny []string
|
|
for _, c := range rows {
|
|
text := strings.TrimSpace(c.Text)
|
|
if text == "" {
|
|
continue
|
|
}
|
|
if c.Kind == "allow" {
|
|
allow = append(allow, "- "+text)
|
|
} else {
|
|
deny = append(deny, "- "+text)
|
|
}
|
|
}
|
|
if len(allow) == 0 && len(deny) == 0 {
|
|
return ""
|
|
}
|
|
var b strings.Builder
|
|
b.WriteString("\n\n【操作约束(最高优先级,凌驾于下方一切探索/拓面启发式;每生成一条意图、每执行一个动作前都必须先自检是否违反,违反即不得进行)】:")
|
|
if len(allow) > 0 {
|
|
b.WriteString("\n允许的操作:\n")
|
|
b.WriteString(strings.Join(allow, "\n"))
|
|
}
|
|
if len(deny) > 0 {
|
|
b.WriteString("\n禁止的操作:\n")
|
|
b.WriteString(strings.Join(deny, "\n"))
|
|
}
|
|
b.WriteString("\n(发现约束之外的新目标/新端口/新主机,不等于获得授权:除非它落在上述允许范围内,否则记为 out-of-scope 事实并跳过,不得为其派生意图或执行动作。)")
|
|
return b.String()
|
|
}
|