Conversation
Reviewer's Guide新增一个内置且默认自动启用的 带钩子与事务性回滚的
|
| Change | Details | Files |
|---|---|---|
引入一个新的内置 trpg 扩展,负责通用 .st、.sn 和 .team 指令,并默认自动激活。 |
|
dice/ext_trpg.godice/ext.godice/ext_log.godice/ext_core.godice/ext_trpg_internal_test.go |
实现一个新的 TRPG 角色卡(trpg.st)指令处理流水线,支持快照、钩子和事务型属性修改,并与 coc7.st/dnd5e.st 解耦。 |
|
dice/ext_trpg_st.go |
为 TRPG 角色卡操作增加钩子 API,通过 seal.trpg.st 暴露给 JS,包括值与操作类型以及安全的钩子执行。 |
|
dice/dice.godice/dice_jsvm.godice/ext_trpg_st_hooks.godice/ext_trpg_internal_test.go |
将 .sn(团卡)指令重构到 trpg 扩展中,同时保持原有行为和错误处理。 |
|
dice/ext_log.godice/ext_trpg_sn.godice/ext_trpg_st.go |
| 为新的角色卡与钩子行为添加 TRPG 专用文本模板和文档。 |
|
dice/ext_trpg_text.godice/config.godocs/trpg.md |
调整指令提供者选择逻辑,使规则模板可以通过 relatedExt 选择 trpg.st,同时保持现有 COC7/DND5E 行为。 |
|
dice/ext_trpg_st_hooks.godice/ext_trpg_internal_test.go |
Tips and commands
Interacting with Sourcery
- 触发新评审: 在 Pull Request 中评论
@sourcery-ai review。 - 继续讨论: 直接回复 Sourcery 的评审评论。
- 从评审评论生成 GitHub Issue: 通过回复评审评论的方式,让 Sourcery 从该评论创建一个 Issue。你也可以在评审评论中回复
@sourcery-ai issue来从该评论创建 Issue。 - 生成 Pull Request 标题: 在 Pull Request 标题中任意位置写上
@sourcery-ai,即可在任意时间生成标题。你也可以在 Pull Request 中评论@sourcery-ai title来(重新)生成标题。 - 生成 Pull Request 摘要: 在 Pull Request 描述中任意位置写上
@sourcery-ai summary,即可在你想要的位置生成 PR 摘要。你也可以在 Pull Request 中评论@sourcery-ai summary来在任意时间(重新)生成摘要。 - 生成评审者指南: 在 Pull Request 中评论
@sourcery-ai guide,即可在任意时间(重新)生成评审者指南。 - 解决所有 Sourcery 评论: 在 Pull Request 中评论
@sourcery-ai resolve,即可标记所有 Sourcery 评论为已解决。如果你已经处理完所有评论并且不想再看到它们,这会很有用。 - 撤销所有 Sourcery 评审: 在 Pull Request 中评论
@sourcery-ai dismiss,即可撤销所有现有的 Sourcery 评审。尤其在你希望从头开始新一轮评审时非常有用——别忘了再评论@sourcery-ai review来触发新评审!
Customizing Your Experience
访问你的 dashboard 以:
- 启用或禁用评审功能,例如 Sourcery 生成的 Pull Request 摘要、评审者指南等。
- 更改评审语言。
- 添加、删除或编辑自定义评审指令。
- 调整其他评审设置。
Getting Help
Original review guide in English
Reviewer's Guide
Adds a new built-in, auto-active trpg extension that centralizes generic TRPG commands (.st, .sn, .team) with a hookable, transactional attribute system, moves existing .sn and .team implementations into this extension, wires JS APIs and text templates, and updates command routing and tests to ensure compatibility and hook behavior.
Sequence diagram for trpg.st command lifecycle with hooks and transactional rollback
sequenceDiagram
actor User
participant Dice
participant CmdTrpgSt as getCmdTrpgSt.Solve
participant TrpgStHookRunner as trpgStHookRunner
participant ExtensionHooks as TrpgStHooks
User->>Dice: .st hp+1
Dice->>CmdTrpgSt: dispatch Solve(ctx, msg, cmdArgs)
CmdTrpgSt->>TrpgStHookRunner: newTrpgStHookRunner(mctx, tmpl.Name)
CmdTrpgSt->>TrpgStHookRunner: beforeCommand(event)
TrpgStHookRunner-->>CmdTrpgSt: error or rejectReason
alt rejected in beforeCommand
CmdTrpgSt->>Dice: trpgStReplyRejected(mctx, msg, err)
CmdTrpgSt-->>User: CmdExecuteResult{Matched:true, Solved:true}
else proceed
CmdTrpgSt->>CmdTrpgSt: cmdStReadOrMod(mctx, tmpl, input)
CmdTrpgSt->>TrpgStHookRunner: afterParse(event)
loop each TrpgStOperation
CmdTrpgSt->>TrpgStHookRunner: beforeApply(event, operation)
TrpgStHookRunner->>ExtensionHooks: BeforeApply(event, operation)
ExtensionHooks-->>TrpgStHookRunner: maybe Skip/RejectReason
CmdTrpgSt->>CmdTrpgSt: evaluate Operand / ProposedValue
CmdTrpgSt->>TrpgStHookRunner: afterEvaluate(event, operation)
TrpgStHookRunner->>ExtensionHooks: AfterEvaluate(event, operation)
end
CmdTrpgSt->>TrpgStHookRunner: beforeCommit(event)
TrpgStHookRunner-->>CmdTrpgSt: error or rejectReason
alt rejected in beforeCommit
CmdTrpgSt->>CmdTrpgSt: snapshot.restore(attrs, mctx.Player)
CmdTrpgSt->>Dice: trpgStReplyRejected(mctx, msg, err)
else commit
CmdTrpgSt->>CmdTrpgSt: apply changes to AttributesItem
CmdTrpgSt->>TrpgStHookRunner: afterCommit(event)
TrpgStHookRunner->>ExtensionHooks: AfterCommit(event)
CmdTrpgSt->>Dice: ReplyToSender(mctx, msg, text+event.ReplySuffix)
end
end
File-Level Changes
| Change | Details | Files |
|---|---|---|
Introduce a new built-in trpg extension that owns generic .st, .sn, and .team commands and is auto-activated by default. |
|
dice/ext_trpg.godice/ext.godice/ext_log.godice/ext_core.godice/ext_trpg_internal_test.go |
Implement a new TRPG sheet (trpg.st) command pipeline with snapshots, hooks, and transactional attribute modification, decoupled from coc7.st/dnd5e.st. |
|
dice/ext_trpg_st.go |
Add a hook API for TRPG sheet operations, exposed to JS via seal.trpg.st, including value and operation types and safe hook execution. |
|
dice/dice.godice/dice_jsvm.godice/ext_trpg_st_hooks.godice/ext_trpg_internal_test.go |
Refactor .sn (group card) command into the trpg extension while preserving behavior and error handling. |
|
dice/ext_log.godice/ext_trpg_sn.godice/ext_trpg_st.go |
| Add TRPG-specific text templates and documentation for the new sheet and hook behavior. |
|
dice/ext_trpg_text.godice/config.godocs/trpg.md |
Adjust command provider selection so rule templates can opt into trpg.st via relatedExt while keeping existing COC7/DND5E behavior. |
|
dice/ext_trpg_st_hooks.godice/ext_trpg_internal_test.go |
Tips and commands
Interacting with Sourcery
- Trigger a new review: Comment
@sourcery-ai reviewon the pull request. - Continue discussions: Reply directly to Sourcery's review comments.
- Generate a GitHub issue from a review comment: Ask Sourcery to create an
issue from a review comment by replying to it. You can also reply to a
review comment with@sourcery-ai issueto create an issue from it. - Generate a pull request title: Write
@sourcery-aianywhere in the pull
request title to generate a title at any time. You can also comment
@sourcery-ai titleon the pull request to (re-)generate the title at any time. - Generate a pull request summary: Write
@sourcery-ai summaryanywhere in
the pull request body to generate a PR summary at any time exactly where you
want it. You can also comment@sourcery-ai summaryon the pull request to
(re-)generate the summary at any time. - Generate reviewer's guide: Comment
@sourcery-ai guideon the pull
request to (re-)generate the reviewer's guide at any time. - Resolve all Sourcery comments: Comment
@sourcery-ai resolveon the
pull request to resolve all Sourcery comments. Useful if you've already
addressed all the comments and don't want to see them anymore. - Dismiss all Sourcery reviews: Comment
@sourcery-ai dismisson the pull
request to dismiss all existing Sourcery reviews. Especially useful if you
want to start fresh with a new review - don't forget to comment
@sourcery-ai reviewto trigger a new review!
Customizing Your Experience
Access your dashboard to:
- Enable or disable review features such as the Sourcery-generated pull request
summary, the reviewer's guide, and others. - Change the review language.
- Add, remove or edit custom review instructions.
- Adjust other review settings.
Getting Help
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
There was a problem hiding this comment.
Hey - 我发现了 1 个问题,并留下了一些总体反馈:
getCmdTrpgSt的 Solve 函数体积较大且逻辑复杂,把解析、钩子编排、快照/回滚以及回复格式化都混在一起处理;建议将不同子命令(show、export、del、clr、fmt、默认路径)拆分到更小的辅助函数中,以提升可读性和可维护性。- 在
del、clr、fmt和默认分支中,围绕运行钩子、检查trpgStRejectReason、恢复快照,有大量重复的样板代码;可以考虑把这些模式抽取成共享的辅助函数,以减少重复,并让整体的事务行为更易于理解和推理。
给 AI Agent 的提示
Please address the comments from this code review:
## Overall Comments
- `getCmdTrpgSt` 的 Solve 函数体积较大且逻辑复杂,把解析、钩子编排、快照/回滚以及回复格式化都混在一起处理;建议将不同子命令(`show`、`export`、`del`、`clr`、`fmt`、默认路径)拆分到更小的辅助函数中,以提升可读性和可维护性。
- 在 `del`、`clr`、`fmt` 和默认分支中,围绕运行钩子、检查 `trpgStRejectReason`、恢复快照,有大量重复的样板代码;可以考虑把这些模式抽取成共享的辅助函数,以减少重复,并让整体的事务行为更易于理解和推理。
## Individual Comments
### Comment 1
<location path="dice/ext_trpg_st_hooks.go" line_range="199" />
<code_context>
+ return ret
+}
+
+func invokeTrpgStHook(d *Dice, ext *ExtInfo, hook func()) (panicErr error) {
+ if ext == nil || hook == nil {
+ return nil
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Hook panic handling loses stack context and mixes error channels with normal errors.
Wrapping the hook in `recover` and returning `fmt.Errorf(...)` turns all panics into a generic error string and drops the stack trace, which makes failures hard to diagnose, especially for JS-side hooks. Consider logging the panic with `zap` (including a stack via `debug.Stack()` or similar) and clearly distinguishing panic-induced failures from normal hook errors (e.g., separate type or marker) so callers can react appropriately (continue, rollback, or surface richer diagnostics).
</issue_to_address>帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续评审。
Original comment in English
Hey - I've found 1 issue, and left some high level feedback:
- The
getCmdTrpgStSolve function is quite large and complex, mixing parsing, hook orchestration, snapshot/rollback, and reply formatting; consider extracting the different subcommands (show,export,del,clr,fmt, default path) into smaller helpers to improve readability and maintainability. - There is a lot of repeated boilerplate around running hooks, checking
trpgStRejectReason, and restoring snapshots in thedel,clr,fmt, and default branches; factoring these patterns into shared helper functions would reduce duplication and make the transactional behavior easier to reason about.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `getCmdTrpgSt` Solve function is quite large and complex, mixing parsing, hook orchestration, snapshot/rollback, and reply formatting; consider extracting the different subcommands (`show`, `export`, `del`, `clr`, `fmt`, default path) into smaller helpers to improve readability and maintainability.
- There is a lot of repeated boilerplate around running hooks, checking `trpgStRejectReason`, and restoring snapshots in the `del`, `clr`, `fmt`, and default branches; factoring these patterns into shared helper functions would reduce duplication and make the transactional behavior easier to reason about.
## Individual Comments
### Comment 1
<location path="dice/ext_trpg_st_hooks.go" line_range="199" />
<code_context>
+ return ret
+}
+
+func invokeTrpgStHook(d *Dice, ext *ExtInfo, hook func()) (panicErr error) {
+ if ext == nil || hook == nil {
+ return nil
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Hook panic handling loses stack context and mixes error channels with normal errors.
Wrapping the hook in `recover` and returning `fmt.Errorf(...)` turns all panics into a generic error string and drops the stack trace, which makes failures hard to diagnose, especially for JS-side hooks. Consider logging the panic with `zap` (including a stack via `debug.Stack()` or similar) and clearly distinguishing panic-induced failures from normal hook errors (e.g., separate type or marker) so callers can react appropriately (continue, rollback, or surface richer diagnostics).
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
补充说明: |
There was a problem hiding this comment.
Hey - 我已经审查了你的更改,一切看起来都很棒!
帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据这些反馈改进你的代码审查。
Original comment in English
Hey - I've reviewed your changes and they look great!
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
概述
新增默认启用的
trpg内置扩展,统一承载.st、.sn与.team。.sn和.team的既有实现及数据结构完整迁移到该扩展。架构设计
trpg.st使用独立的解析、事务与渲染流程,不依赖coc7.st、dnd5e.st或CmdStOverrideInfo。.st保持一致;回复使用独立的TRPG:*文本模板。relatedExt优先级,现有 COC7 与 DND5E 模板仍使用各自的.st。插件接入
新规则模板可声明
relatedExt: [trpg, my-rule],规则插件通过seal.trpg.st.registerHooks注册回调,并可按规则系统限定作用范围,实现属性上下限、操作跳过、整批拒绝及输出定制。验证
go test ./dice -count=1go test -raceSummary by Sourcery
引入一个新的内置、规则中立的 TRPG 扩展,该扩展负责通用角色卡和团卡相关指令,并为插件提供可挂钩的属性工作流。
New Features:
trpg,默认启用,提供通用的.st、.sn和.team指令。trpg.st),在解析、评估、提交、展示和导出等阶段提供挂钩点。seal.trpg.stJavaScript API,用于注册挂钩、构造属性值和操作,以及清理挂钩。Enhancements:
relatedExt选用trpg.st,同时现有的 COC7 和 DND5E 模板继续使用各自的.st。.st语义一致,并使用相互隔离的回复模板。ExtInfo),为每个扩展存储 TRPG 角色卡挂钩,以保证 JS 重载行为可预测。Documentation:
docs/trpg.md文档,记录 TRPG 扩展、指令路由、挂钩阶段、事务性语义以及 JavaScript 集成 API。Tests:
trpg扩展拥有中立的.st、.sn和.team指令,并且旧有注册已从log和core中移除。trpg.st行为与通用 COC7.st一致,并验证挂钩可以约束数值并在拒绝时执行原子回滚。Original summary in English
Summary by Sourcery
Introduce a new built-in, rule-neutral TRPG extension that owns generic character sheet and group card commands and adds a hookable attribute workflow for plugins.
New Features:
trpgbuilt-in extension that provides generic.st,.sn, and.teamcommands and is active by default.trpg.st) with hook points for parsing, evaluation, commit, display, and export.seal.trpg.stJavaScript APIs for registering hooks, constructing attribute values and operations, and clearing hooks.Enhancements:
trpg.stviarelatedExtwhile existing COC7 and DND5E templates continue using their own.st..stsemantics when no hooks are registered, with isolated reply templates.ExtInfo) to store TRPG sheet hooks per extension for predictable JS reload behavior.Documentation:
docs/trpg.mddocumenting the TRPG extension, command routing, hook stages, transactional semantics, and JavaScript integration APIs.Tests:
trpgextension owns neutral.st,.sn, and.teamcommands and that older registrations are removed fromlogandcore.trpg.stwithout hooks matches generic COC7.stbehavior and that hooks can clamp values and enforce atomic rollback on rejection.