Files
Agent-System-Core/plugin.go
weichenandCursor f93f473a0e Add script steps and critic fields to workflow definitions
Why: The workflow executor needs a shared contract for subagent profiles, plugin scripts, and per-step plus whole-run retry caps.
Evidence: go test ./... passed, including the new workflow_def golden.
Impact: New fields are omitempty, so existing workflow JSON still decodes. Kind script is additive.
Refs: feature/agent-harness-p4
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-01 15:55:52 +00:00

116 lines
5.3 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package core
import "encoding/json"
// 插件 manifest(4.6):插件 = manifest + 声明资产 + 可选代码。
// 校验失败整批拒绝(fail-closed);卸载注销注册项,在途引用按定义缺失稳定报错。
const PluginAPIVersion = "1.0"
type PluginManifest struct {
ID string `json:"id"`
Name string `json:"name"`
Version string `json:"version"`
APIVersion string `json:"apiVersion"`
Requires PluginRequires `json:"requires,omitempty"`
Provides PluginProvides `json:"provides"`
Scope PluginScope `json:"scope,omitzero"`
Backend PluginBackend `json:"backend,omitzero"`
}
type PluginRequires struct {
Network []string `json:"network,omitempty"` // 出站域名白名单;v2 空名单拒绝出站,v1 空名单保持放行
}
type PluginProvides struct {
Tools []string `json:"tools,omitempty"` // tools/ 目录下的资产名
Workflows []string `json:"workflows,omitempty"`
Intents []string `json:"intents,omitempty"`
Prompts []string `json:"prompts,omitempty"`
Panels []string `json:"panels,omitempty"`
Cards []string `json:"cards,omitempty"`
Settings []string `json:"settings,omitempty"`
Commands []string `json:"commands,omitempty"` // commands/ 资产名(spec 权威在 Agent-Command 库)
Workspaces []string `json:"workspaces,omitempty"` // workspaces/ 资产名(工作区弹层)
Skills []string `json:"skills,omitempty"`
MCPServers []string `json:"mcpServers,omitempty"`
Knowledge []string `json:"knowledge,omitempty"`
Parsers []string `json:"parsers,omitempty"`
Agents []string `json:"agents,omitempty"`
Channels []string `json:"channels,omitempty"`
Pages []string `json:"pages,omitempty"`
}
// PluginPanel:右栏面板声明(UI schema 静态骨架 + 可选数据提供者)。
type PluginPanel struct {
ID string `json:"id"`
Title string `json:"title"`
Icon string `json:"icon,omitempty"`
Body []UINode `json:"body"`
// Tool 绑定:面板挂载时调用该工具刷新 Body 中的动态区(v1 简化为整体刷新)。
RefreshTool string `json:"refreshTool,omitempty"`
}
// WorkflowDef:工作流即数据(4.6)。Step 可产 HITL 卡片、调工具、产出工件。
// 模板占位符:{{input}}、{{slots.<key>}}、{{steps.<id>.output}}。
type WorkflowDef struct {
ID string `json:"id"`
Title string `json:"title"`
Description string `json:"description,omitempty"`
IntentID string `json:"intentId,omitempty"` // 绑定意图(命中即启动)
MaxRetries int `json:"maxRetries,omitempty"` // 整条工作流的 critic 重试上限
Steps []WorkflowStep `json:"steps"`
}
// StepCritic:单步验收。无法解析的判定按不通过处理。
type StepCritic struct {
Criteria string `json:"criteria"`
MaxRetries int `json:"maxRetries,omitempty"` // 本步重试上限;0 表示缺省 1 次
}
type WorkflowStep struct {
ID string `json:"id"`
Title string `json:"title"`
Kind string `json:"kind"` // prompt | tool | hitl | artifact | card | script
Prompt string `json:"prompt,omitempty"` // prompt: 发给模型的指令模板
Agent string `json:"agent,omitempty"` // prompt: 子代理 profile,缺省 general
Tool string `json:"tool,omitempty"` // tool: 工具名
Args json.RawMessage `json:"args,omitempty"` // tool: 参数模板
Hitl *HITLCardTemplate `json:"hitl,omitempty"` // hitl: 卡片模板
Artifact string `json:"artifact,omitempty"` // artifact: 产出工件名模板
Card *ActivityCardTemplate `json:"card,omitempty"` // card: 产收件箱任务卡
Script string `json:"script,omitempty"` // script: 插件目录内的相对路径
Critic *StepCritic `json:"critic,omitempty"`
}
// ActivityCardTemplate:工作流步骤产卡模板(kind=card)——步骤执行时生成
// ActivityCard(右栏收件箱),Body/Actions 走 UI 有限词汇;Actions 建议绑定命令。
type ActivityCardTemplate struct {
Kind CardKind `json:"kind"`
Title string `json:"title"`
Tone string `json:"tone,omitempty"`
Body []UINode `json:"body,omitempty"`
Actions []UIAction `json:"actions,omitempty"`
}
// PluginWorkspace:工作区弹层声明(深读与治理视图;Esc/遮罩关闭回对话现场,
// 不承载任何唯一步骤——每个操作必须另有命令路径,提案 D31)。
type PluginWorkspace struct {
ID string `json:"id"`
Title string `json:"title"`
Icon string `json:"icon,omitempty"`
Shortcut string `json:"shortcut,omitempty"` // "1"–"9"(⌘N / Ctrl+N 召出)
BadgeTool string `json:"badgeTool,omitempty"` // 角标提供者工具:返回 {count,tone}
Body []UINode `json:"body"`
// RefreshTool:挂载时调用刷新 Body 动态区(与 Panel 同机制,v1 整体刷新)。
RefreshTool string `json:"refreshTool,omitempty"`
}
type HITLCardTemplate struct {
Question string `json:"question"`
Kind HITLKind `json:"kind"`
Choices []HITLChoice `json:"choices,omitempty"`
AllowFreeInput bool `json:"allowFreeInput"`
FreeInputHint string `json:"freeInputHint,omitempty"`
}