Merged
Conversation
Contributor
There was a problem hiding this comment.
Hey - 我发现了 2 个问题,并给了一些整体层面的反馈:
- 新的共享函数
resource.FindResource相比之前的MapTracker/ItemTransfer实现明显不那么灵活(例如:不再去掉前缀resource/,不再向资源路径的父目录回溯搜索),这可能会破坏现有的部署目录结构;建议增加等价的回退匹配模式,以保持行为向后兼容。 - 移除对
MAAEND_ITEMTRANSFER_DATA_DIR的支持会改变item_order.json被覆写/定位的方式;如果某些环境仍然需要基于环境变量的覆写能力,建议在共享的resource包中重新引入这类逻辑,而不是完全删除。
面向 AI Agent 的提示词
Please address the comments from this code review:
## Overall Comments
- The new shared `resource.FindResource` logic is noticeably less flexible than the previous `MapTracker`/`ItemTransfer` implementations (e.g. no stripping of leading `resource/`, no parent-of-resource-path search), which may break existing deployment layouts; consider adding equivalent fallback patterns so behavior remains backward compatible.
- The removal of `MAAEND_ITEMTRANSFER_DATA_DIR` support changes how `item_order.json` can be overridden/located; if this env-based override is still needed in some environments, consider reintroducing it inside the shared `resource` package rather than dropping it entirely.
## Individual Comments
### Comment 1
<location path="agent/go-service/pkg/resource/resource_sink.go" line_range="29-37" />
<code_context>
-type resourcePathSink struct{}
-
-// OnResourceLoading captures the resource path when a resource is loaded.
-func (c *resourcePathSink) OnResourceLoading(resource *maa.Resource, status maa.EventStatus, detail maa.ResourceLoadingDetail) {
- if status != maa.EventStatusSucceeded || detail.Path == "" {
- return
</code_context>
<issue_to_address>
**issue (bug_risk):** The stored resourcePath is a file path but later treated as a base directory, which can produce invalid joined paths.
`OnResourceLoading` stores `detail.Path` (or its absolute form) directly in `resourcePath`, and `getResourceBase` returns it. `FindResource` then calls `filepath.Join(base, rel)`. When `detail.Path` is a file path (the usual case), `base` is not a directory, so the join yields invalid paths like `/path/to/some.png/data/ItemTransfer/item_order.json`. The old `FindResource` logic handled this by using `filepath.Dir(base)`; the new helper does not. Either store `filepath.Dir(absPath)` as the base, or have `getResourceBase` wrap the stored path with `filepath.Dir` before joining.
</issue_to_address>
### Comment 2
<location path="agent/go-service/itemtransfer/types.go" line_range="57" />
<code_context>
- return
- }
- b, err := os.ReadFile(filepath.Join(dir, "item_order.json"))
+ b, err := resource.ReadResource("data/ItemTransfer/item_order.json")
if err != nil {
cachedDataErr = err
</code_context>
<issue_to_address>
**question (bug_risk):** Removing the custom directory search (incl. env override) may break deployments that rely on MAAEND_ITEMTRANSFER_DATA_DIR or deeper search paths.
The previous `loadItemOrderData` respected `MAAEND_ITEMTRANSFER_DATA_DIR`, walked multiple parent directories, and fell back to paths like `assets/data/ItemTransfer`. Switching to `resource.ReadResource("data/ItemTransfer/item_order.json")` drops the env override and narrows the search to a few fixed locations. If existing deployments depend on that configurability, this is a breaking change. Consider wiring the env-based base directory (or equivalent) into `getStandardResourceBase` or this call so those setups continue to work.
</issue_to_address>帮我变得更有用!请对每条评论点 👍 或 👎,我会根据这些反馈改进以后的评审质量。
Original comment in English
Hey - I've found 2 issues, and left some high level feedback:
- The new shared
resource.FindResourcelogic is noticeably less flexible than the previousMapTracker/ItemTransferimplementations (e.g. no stripping of leadingresource/, no parent-of-resource-path search), which may break existing deployment layouts; consider adding equivalent fallback patterns so behavior remains backward compatible. - The removal of
MAAEND_ITEMTRANSFER_DATA_DIRsupport changes howitem_order.jsoncan be overridden/located; if this env-based override is still needed in some environments, consider reintroducing it inside the sharedresourcepackage rather than dropping it entirely.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new shared `resource.FindResource` logic is noticeably less flexible than the previous `MapTracker`/`ItemTransfer` implementations (e.g. no stripping of leading `resource/`, no parent-of-resource-path search), which may break existing deployment layouts; consider adding equivalent fallback patterns so behavior remains backward compatible.
- The removal of `MAAEND_ITEMTRANSFER_DATA_DIR` support changes how `item_order.json` can be overridden/located; if this env-based override is still needed in some environments, consider reintroducing it inside the shared `resource` package rather than dropping it entirely.
## Individual Comments
### Comment 1
<location path="agent/go-service/pkg/resource/resource_sink.go" line_range="29-37" />
<code_context>
-type resourcePathSink struct{}
-
-// OnResourceLoading captures the resource path when a resource is loaded.
-func (c *resourcePathSink) OnResourceLoading(resource *maa.Resource, status maa.EventStatus, detail maa.ResourceLoadingDetail) {
- if status != maa.EventStatusSucceeded || detail.Path == "" {
- return
</code_context>
<issue_to_address>
**issue (bug_risk):** The stored resourcePath is a file path but later treated as a base directory, which can produce invalid joined paths.
`OnResourceLoading` stores `detail.Path` (or its absolute form) directly in `resourcePath`, and `getResourceBase` returns it. `FindResource` then calls `filepath.Join(base, rel)`. When `detail.Path` is a file path (the usual case), `base` is not a directory, so the join yields invalid paths like `/path/to/some.png/data/ItemTransfer/item_order.json`. The old `FindResource` logic handled this by using `filepath.Dir(base)`; the new helper does not. Either store `filepath.Dir(absPath)` as the base, or have `getResourceBase` wrap the stored path with `filepath.Dir` before joining.
</issue_to_address>
### Comment 2
<location path="agent/go-service/itemtransfer/types.go" line_range="57" />
<code_context>
- return
- }
- b, err := os.ReadFile(filepath.Join(dir, "item_order.json"))
+ b, err := resource.ReadResource("data/ItemTransfer/item_order.json")
if err != nil {
cachedDataErr = err
</code_context>
<issue_to_address>
**question (bug_risk):** Removing the custom directory search (incl. env override) may break deployments that rely on MAAEND_ITEMTRANSFER_DATA_DIR or deeper search paths.
The previous `loadItemOrderData` respected `MAAEND_ITEMTRANSFER_DATA_DIR`, walked multiple parent directories, and fell back to paths like `assets/data/ItemTransfer`. Switching to `resource.ReadResource("data/ItemTransfer/item_order.json")` drops the env override and narrows the search to a few fixed locations. If existing deployments depend on that configurability, this is a breaking change. Consider wiring the env-based base directory (or equivalent) into `getStandardResourceBase` or this call so those setups continue to work.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Contributor
There was a problem hiding this comment.
Pull request overview
此 PR 将 go-service 中 MapTracker 与 ItemTransfer 先前各自实现的资源路径探测/读取逻辑,抽取为共享的 pkg/resource,并在主注册流程中统一注册 Maa Resource sink,以便在不同工作目录/安装布局下更稳定地定位资源文件。
Changes:
- 新增
agent/go-service/pkg/resource:通过 Maa resource sink 缓存资源基路径,并提供FindResource/ReadResource统一查找与读取接口 - 重构 map-tracker:模板、地图目录与外部数据读取改用共享 resource 工具
- 重构 itemtransfer:
item_order.json改用共享读取器加载,并移除 README 中对应的环境变量说明
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| agent/go-service/register.go | 在全局注册阶段统一启用 resource sink |
| agent/go-service/pkg/resource/resource_sink.go | 新增 Maa ResourceEventSink:捕获并缓存资源路径 |
| agent/go-service/pkg/resource/resource_reader.go | 新增统一资源查找/读取逻辑(FindResource/ReadResource) |
| agent/go-service/map-tracker/register.go | 移除 map-tracker 内部单独的 resource sink 注册 |
| agent/go-service/map-tracker/move.go | 预览地图读取改为使用共享 FindResource |
| agent/go-service/map-tracker/internal/resource.go | MapTracker 资源加载改用共享 FindResource/ReadResource |
| agent/go-service/map-tracker/big_map_pick.go | 外部数据读取改为使用共享 ReadResource |
| agent/go-service/itemtransfer/types.go | item_order.json 加载改为使用共享 ReadResource |
| agent/go-service/itemtransfer/register.go | 移除 itemtransfer 内部单独的 resource sink 注册 |
| agent/go-service/itemtransfer/README.md | 移除已不再生效的数据目录环境变量说明 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
此 PR 将 MapTracker 和 ItemTransfer 所使用的资源加载逻辑合并到 resource 包。
Summary by Sourcery
将通用的 Go 资源加载和路径解析逻辑提取到一个共享的
pkg/resource模块中,并更新现有使用方以使用该模块。增强内容:
pkg/resource工具,用于以统一的搜索策略并结合 Maa 资源下沉集成来解析和读取资源文件。map-tracker,使其在模板、地图目录、预览图片和外部数据加载方面依赖共享的资源辅助工具。itemtransfer,通过共享的资源读取器加载item_order.json,而不是使用自定义的目录发现逻辑。Original summary in English
Summary by Sourcery
Extract shared Go resource loading and path resolution logic into a common pkg/resource module and update existing consumers to use it.
Enhancements: