ci / vet-and-test (pull_request) Successful in 42s
Why: Generative UI U3 - the agent needs a real submission path and the next turn needs to see prior pages: a built-in in-process plugin registers generative-ui.present (exposeAsTool) carrying the catalog (prompt=validation single source) with a schema-repair strategy measured against real MiniMax-M3 deviations; the command bus gains an owner-scoped tool gate so a disabled plugin stops injecting its tool (execution guard remains in surfacesvc); ctxasm projects saved surfaces back into context so the model can revise existing structure; doc-refs are authorized against the owner's real artifacts. Evidence: unit suites green (genui guards/epoch/doc-ref, gate fail-closed, projection content); full go test ./... green; cmdbus/ctxasm also green under AGENT_PG_TEST_DSN; real-model closed loop (env-gated TestRealModelSurfaceLoop) passes: task->spec->save->projection->revise with revision 1->2 and structure change, CNY 0.08 total. Impact: New internal/genui package; additive cmdbus/ctxasm/runmgr/ runtime hooks; no storage or contract changes (U2 layer untouched). Refs: Documents proposal r2 U3; Core PR #25/#26; Backend #143; Dev task feature/generative-ui-u3
79 lines
3.7 KiB
Go
79 lines
3.7 KiB
Go
// Package runtime 定义智能体执行端口与实现:mock(脚本回放)与 LLM
|
||
// (复用 agent-native 的 OpenAI 兼容流式客户端)。执行编排归 runmgr。
|
||
package runtime
|
||
|
||
import (
|
||
"context"
|
||
|
||
nruntime "agent-native/runtime"
|
||
agentllm "agent-native/runtime/llm"
|
||
|
||
core "agent-system-core"
|
||
)
|
||
|
||
// RunCtx 是 Runner 的受控环境(由 runmgr 实现):事件发布、HITL、子代理、
|
||
// 工件、检索、工具执行、历史。Runner 不得绕过 RunCtx 直接写库。
|
||
type RunCtx interface {
|
||
Context() context.Context
|
||
Run() core.Run
|
||
Profile() core.AgentProfile
|
||
Settings() core.EffectiveSettings
|
||
Emit(typ core.StreamEventType, payload any) error
|
||
SetAssistantParts(parts []core.Part) error
|
||
AskHITL(card core.HITLCard) (core.HITLResponse, error)
|
||
SpawnSubagent(name, task string, hint string) (core.AgentResultPayload, error)
|
||
UpdatePlan(p core.PlanSnapshot) error
|
||
UpdateTodos(l core.TodoList) error
|
||
WriteArtifact(name, kind, mime string, content []byte) (core.Artifact, error)
|
||
Retrieve(q core.RetrievalQuery) ([]core.RetrievalHit, error)
|
||
ExecuteTool(call core.ToolCallRequest) core.ToolCallResult
|
||
History() []core.Message
|
||
Attachments() []core.ParsedDocument
|
||
// Tools 返回注册表全部工具(画像过滤由 runner 做)。
|
||
Tools() []core.ToolDesc
|
||
// Subtask 返回子代理任务描述(仅 subagent run 有值)。
|
||
Subtask() string
|
||
// CreateCard / SetCardStatus:产收件箱任务卡(收件箱关闭时为 no-op)。
|
||
CreateCard(card core.ActivityCard) (core.ActivityCard, error)
|
||
SetCardStatus(id string, status core.CardStatus, tone, note string) error
|
||
// SubmitCard:产物卡提交(submit_card 工具)——建卡并登记,finishRun 落库助手
|
||
// 消息后回填 AnchorMessageID(卡→消息互定位)。
|
||
SubmitCard(card core.ActivityCard) (core.ActivityCard, error)
|
||
// BeginStreamCard / AppendStreamCard / CommitStreamCard:流式产物卡三段式
|
||
// (card_begin/card_append/card_commit 工具;D44/D45)。Begin 建 active 产物卡
|
||
// 并设为活跃流式卡(多次 begin 以最后一卡为活跃);Append 向活跃卡追加正文
|
||
// (card.updated 按 250ms 窗口节流);Commit 置 done 并登记锚点回填。
|
||
BeginStreamCard(card core.ActivityCard) (core.ActivityCard, error)
|
||
AppendStreamCard(text string) error
|
||
CommitStreamCard() (core.ActivityCard, error)
|
||
// Card:按 ID 取卡(ctxasm 回填 card 部件正文用;无则 nil)。
|
||
Card(id string) *core.ActivityCard
|
||
// Artifact:按 ID 取工件与内容(ctxasm 回填 artifact_ref 正文用;无则 false)。
|
||
Artifact(id string) (core.Artifact, []byte, bool)
|
||
// Surfaces 返回当前会话最近保存的生成页面(U3/R6:ctxasm 语义投影回灌)。
|
||
Surfaces() []core.SurfaceSnapshot
|
||
// SetContextObservation 记录本次运行的上下文组装观测(随 run.completed 下发)。
|
||
SetContextObservation(o core.ContextObservation)
|
||
}
|
||
|
||
// Runner 执行一个 run 至终态:返回 nil = completed;ctx 取消应返回 ctx.Err()。
|
||
type Runner interface {
|
||
Name() string
|
||
Execute(rc RunCtx) error
|
||
}
|
||
|
||
// PermissionAskOf 把宿主的内核级权限询问(runmgr 的 HITL 确认卡)接成
|
||
// nruntime.Config.PermissionAsk 端口;宿主未实现时返回 nil,内核保持
|
||
// 「ask 按拒绝处理」的旧行为(N1 WP2 装配;直连/子代理/小队共用)。
|
||
// 入参为 any:直连/子代理传 RunCtx,小队装配传 squadadapter.Ctx——
|
||
// 判定只依赖可选的 PermissionAsk 方法,不要求实现整个 RunCtx。
|
||
func PermissionAskOf(rc any) func(context.Context, agentllm.ToolCall) nruntime.AskVerdict {
|
||
asker, ok := rc.(interface {
|
||
PermissionAsk(ctx context.Context, call agentllm.ToolCall) nruntime.AskVerdict
|
||
})
|
||
if !ok {
|
||
return nil
|
||
}
|
||
return asker.PermissionAsk
|
||
}
|