@@ -12,7 +12,7 @@ import (
1212//go:embed explain_text.md
1313var explainText string
1414
15- // explainType 是 stdagent explain --json 输出的单条记录
15+ // explainType is a single record of ` stdagent explain --json` output
1616type explainType struct {
1717 Type string `json:"type"`
1818 Semantics string `json:"semantics"`
@@ -21,61 +21,61 @@ type explainType struct {
2121 ExampleFM string `json:"example_frontmatter"`
2222}
2323
24- // explainTypes 是 5 种 type 的结构化语义,供 --json 输出。
25- // 与 explain_text.md 内容对应,保持同步。
24+ // explainTypes holds the structured semantics of the 5 types for --json output.
25+ // It mirrors explain_text.md; keep them in sync.
2626var explainTypes = []explainType {
2727 {
2828 Type : "rules" ,
29- Semantics : "持续生效的编码、架构和操作约束;由 target 自动加载或按路径匹配。 " ,
30- WhenToUse : "违反会造成真实风险、且值得占用常驻上下文的稳定约束。 " ,
31- WhenNot : "长背景用 references,按需工作流用 skills,用户模板用 commands。 " ,
32- ExampleFM : "---\n type: rules\n name: exception-handling\n description: Go 错误传播与边界转换 \n priority: high\n applyTo:\n - \" **/*.go\" \n ---" ,
29+ Semantics : "Always-on coding, architecture, and operational constraints; auto-loaded by targets or matched by path. " ,
30+ WhenToUse : "Stable constraints whose violation causes real risk and that deserve resident context. " ,
31+ WhenNot : "Long background goes in references, on-demand workflows in skills, user templates in commands. " ,
32+ ExampleFM : "---\n type: rules\n name: exception-handling\n description: Go error propagation and boundary conversion \n priority: high\n applyTo:\n - \" **/*.go\" \n ---" ,
3333 },
3434 {
3535 Type : "skills" ,
36- Semantics : "AI 根据 description 按需调用的能力包,可携带辅助资源。 " ,
37- WhenToUse : "可复用、有明确结果和成功标准的工作流。 " ,
38- WhenNot : "持续约束用 rules,用户显式模板用 commands。 " ,
39- ExampleFM : "---\n type: skills\n name: code-review\n description: 审查当前改动并报告正确性、安全和回归问题 \n ---" ,
36+ Semantics : "Capability packages the AI invokes on demand based on description; may carry supporting resources. " ,
37+ WhenToUse : "Reusable workflows with a clear outcome and success criteria. " ,
38+ WhenNot : "Ongoing constraints go in rules, explicit user templates in commands. " ,
39+ ExampleFM : "---\n type: skills\n name: code-review\n description: Review current changes and report correctness, security, and regression issues \n ---" ,
4040 },
4141 {
4242 Type : "commands" ,
43- Semantics : "用户输入 /command-name 显式触发的操作模板。 " ,
44- WhenToUse : "用户需要主动调用的固定操作。 " ,
45- WhenNot : "AI 自动判断的流程用 skills,持续约束用 rules。 " ,
46- ExampleFM : "---\n type: commands\n name: review\n description: 审查当前分支改动并生成 review 报告 \n ---" ,
43+ Semantics : "Operation templates the user triggers explicitly via /command-name. " ,
44+ WhenToUse : "Fixed operations the user wants to invoke directly. " ,
45+ WhenNot : "AI-judged flows go in skills, ongoing constraints in rules. " ,
46+ ExampleFM : "---\n type: commands\n name: review\n description: Review current branch changes and produce a review report \n ---" ,
4747 },
4848 {
4949 Type : "references" ,
50- Semantics : "仅在需要时查阅的架构、协议、 API 和长篇背景。 " ,
51- WhenToUse : "不应占用默认上下文但需要保留的领域知识。 " ,
52- WhenNot : "持续约束用 rules,可执行工作流用 skills。 " ,
53- ExampleFM : "---\n type: references\n name: transformer-design\n description: transformer 协议层架构说明 \n applyTo:\n - \" internal/transformer/**\" \n ---" ,
50+ Semantics : "Architecture, protocol, API, and long-form background consulted only when needed. " ,
51+ WhenToUse : "Domain knowledge worth keeping but not worth occupying default context. " ,
52+ WhenNot : "Ongoing constraints go in rules, executable workflows in skills. " ,
53+ ExampleFM : "---\n type: references\n name: transformer-design\n description: Transformer protocol-layer architecture notes \n applyTo:\n - \" internal/transformer/**\" \n ---" ,
5454 },
5555 {
5656 Type : "subagents" ,
57- Semantics : "在隔离上下文中执行的代理定义。 " ,
58- WhenToUse : "可独立执行、需要专门上下文或可安全并行的任务。 " ,
59- WhenNot : "当前 session 内的流程用 skills,简单模板用 commands。 " ,
60- ExampleFM : "---\n type: subagents\n name: code-reviewer\n description: 在隔离上下文中审查代码并返回问题清单 \n ---" ,
57+ Semantics : "Agent definitions executed in an isolated context. " ,
58+ WhenToUse : "Tasks that run independently, need a dedicated context, or parallelize safely. " ,
59+ WhenNot : "In- session flows go in skills, simple templates in commands. " ,
60+ ExampleFM : "---\n type: subagents\n name: code-reviewer\n description: Review code in an isolated context and return an issue list \n ---" ,
6161 },
6262}
6363
6464func newExplainCmd () * cobra.Command {
6565 var asJSON bool
6666 cmd := & cobra.Command {
6767 Use : "explain [type]" ,
68- Short : "解释 std-agent 5 种类型( rules/skills/commands/references/subagents)的语义 " ,
69- Long : `输出 std-agent 5 种 type 的语义速查:每种类型的触发语义 / 何时使用 / 何时不用 / 示例 frontmatter。
68+ Short : "Explain the semantics of the 5 std-agent types ( rules/skills/commands/references/subagents) " ,
69+ Long : `Print a semantics cheat sheet for the 5 std-agent types: trigger semantics / when to use / when not to / example frontmatter for each type.
7070
71- 不带参数时输出全部 5 种。带 type 参数时只输出该 type 一段。
71+ Without arguments, print all 5 types. With a type argument, print only that type's section.
7272
73- 示例:
73+ Examples:
7474
75- stdagent explain # 全部 5 种
76- stdagent explain rules # 只看 rules
77- stdagent explain --json # JSON 输出( AI 集成)
78- stdagent explain rules --json # rules 单项 JSON
75+ stdagent explain # all 5 types
76+ stdagent explain rules # rules only
77+ stdagent explain --json # JSON output ( AI integration)
78+ stdagent explain rules --json # single rules item as JSON
7979` ,
8080 Args : cobra .MaximumNArgs (1 ),
8181 RunE : func (cmd * cobra.Command , args []string ) error {
@@ -89,11 +89,12 @@ func newExplainCmd() *cobra.Command {
8989 return writeExplainMarkdown (cmd , filter )
9090 },
9191 }
92- cmd .Flags ().BoolVar (& asJSON , "json" , false , "JSON 输出(给 AI / 自动化集成) " )
92+ cmd .Flags ().BoolVar (& asJSON , "json" , false , "JSON output (for AI / automation integration) " )
9393 return cmd
9494}
9595
96- // writeExplainMarkdown 输出 markdown 速查。filter 为空输出全部,否则只输出对应 type 段。
96+ // writeExplainMarkdown prints the markdown cheat sheet. An empty filter prints
97+ // everything, otherwise only the matching type's section.
9798func writeExplainMarkdown (cmd * cobra.Command , filter string ) error {
9899 if filter == "" {
99100 cmd .Print (explainText )
@@ -110,7 +111,7 @@ func writeExplainMarkdown(cmd *cobra.Command, filter string) error {
110111 return nil
111112}
112113
113- // writeExplainJSON 输出 []explainType(全部)或 [explainType](单项过滤)。
114+ // writeExplainJSON prints []explainType (all) or [explainType] (single-type filter).
114115func writeExplainJSON (cmd * cobra.Command , filter string ) error {
115116 enc := json .NewEncoder (cmd .OutOrStdout ())
116117 enc .SetIndent ("" , " " )
@@ -137,21 +138,23 @@ func isKnownType(t string) bool {
137138 return false
138139}
139140
140- // extractSection 从 explain_text.md 抽出 ## <type> 标题对应的段落(含标题,到下一个 ## 之前)。
141+ // extractSection extracts the `## <type>` section from explain_text.md
142+ // (including the header, up to the next `##` header).
141143//
142- // explain_text.md 用 `## rules` / `## skills` 等二级标题分段,最后有一个 `## 速查表` 总表段。
143- // 单项查询时只返回该 type 的段,不包含速查表(避免重复信息)。
144+ // explain_text.md is divided by `## rules` / `## skills` ... level-2 headers
145+ // plus a trailing `## Quick reference` summary section. Single-type queries
146+ // return only that type's section, without the summary (to avoid duplication).
144147func extractSection (text , typeName string ) string {
145148 header := "## " + typeName
146149 idx := strings .Index (text , header + "\n " )
147150 if idx < 0 {
148151 return ""
149152 }
150153 rest := text [idx :]
151- // 找下一个 `## ` 二级标题(注意要在行首)
154+ // Find the next `## ` level-2 header (must be at line start)
152155 next := strings .Index (rest [len (header ):], "\n ## " )
153156 if next < 0 {
154157 return rest
155158 }
156- return rest [:len (header )+ next + 1 ] // +1 包含 next 之前的换行
159+ return rest [:len (header )+ next + 1 ] // +1 keeps the newline before next
157160}
0 commit comments