Skip to content

fix(core,playground): 规划阶段校验 actionSpace、报告模板注入兜底、Playground 默认本机监听#2520

Open
FinnJov wants to merge 6 commits into
web-infra-dev:mainfrom
FinnJov:fix/core-planning-and-report-build
Open

fix(core,playground): 规划阶段校验 actionSpace、报告模板注入兜底、Playground 默认本机监听#2520
FinnJov wants to merge 6 commits into
web-infra-dev:mainfrom
FinnJov:fix/core-planning-and-report-build

Conversation

@FinnJov
Copy link
Copy Markdown

@FinnJov FinnJov commented May 22, 2026

概述

本 PR 包含 4 个相互独立的修复(本地代码审计结论),每个 commit 一个 scope,便于分开 review。

1. fix(core) — 规划阶段校验 actionSpace

  • 新增 assertPlannedActionInActionSpace,并在 llm-planningbuildYamlFlowFromPlans 中使用。
  • 改前: LLM 可能返回当前设备不支持的 action 名;buildYamlFlowFromPlansconsole.warn 并跳过;要到 TaskBuilder 执行阶段才失败,且可能多消耗规划轮次。
  • 改后: 非法 action 类型立即抛错,错误信息中会列出当前 actionSpace 内可用 action。
  • 已在 llm-planning.test.ts 增加单测。

2. fix(core) — 报告 HTML 模板注入

  • apps/report/dist/index.html 不存在:保持原有 warn 并跳过注入(monorepo 中 @midscene/report 依赖 @midscene/core,须先 build core,不能在此处 hard fail)。
  • 若模板 存在 但注入后 dist 仍含 REPLACE_ME_WITH_REPORT_HTML构建失败并给出明确错误,避免把坏报告打进产物。
  • 增加 core → report 的 Nx dependsOn(会与 report → core 形成循环构建依赖)。

3. fix(playground) — 默认监听地址

  • Playground 默认由 0.0.0.0 改为 127.0.0.1,降低局域网误暴露未鉴权 /execute 等接口的风险。
  • 可选放开:
    • MIDSCENE_PLAYGROUND_ALLOW_REMOTE=1 → 监听 0.0.0.0
    • MIDSCENE_PLAYGROUND_HOST=<host> → 自定义绑定地址
  • 文档: 本次 更新 apps/site/docs 站点文档;变量说明见根目录 .env.example。如需中英文站点补充,可另开 doc PR。

4. chore(workflow) — Windows 开发体验

  • 根目录 cleanrm -rf 改为跨平台 scripts/clean.mjs
  • 新增 .env.example.gitignore 中增加 !.env.example),列出 MIDSCENE_MODEL_* 与 Playground 相关 env。

测试说明

  • 对改动文件执行 npx biome check(7 个文件,无问题)
  • packages/corepnpm exec vitest run tests/unit-test/llm-planning.test.ts(53 passed)
  • pnpm run build(建议 merge 前跑全量构建)
  • npx nx test @midscene/core(可选;Windows 上部分超时用例与本次改动无关)

给 Reviewer 的说明

  • 行为变更: buildYamlFlowFromPlans 对未知 action 由「warn 并跳过」改为 抛错(与 TaskBuilder 行为一致)。
  • Playground 环境变量仅在 .env.example 中说明,未改文档站,有意控制 PR 体积。

付焦方(Fu Jiaofang) added 4 commits May 22, 2026 13:57
Add assertPlannedActionInActionSpace and use it in llm-planning and
buildYamlFlowFromPlans so invalid action types throw during planning
instead of after extra LLM rounds or at TaskBuilder execution.
…s placeholder

Keep warn-and-skip when apps/report/dist is missing (core builds before
report in the monorepo graph). Throw only if index.html is present yet
dist still contains REPLACE_ME_WITH_REPORT_HTML after injection.
Listen on localhost unless MIDSCENE_PLAYGROUND_ALLOW_REMOTE=1 or
MIDSCENE_PLAYGROUND_HOST is set, reducing accidental LAN exposure of
unauthenticated /execute APIs.
Replace rm -rf clean with scripts/clean.mjs for Windows. Add .env.example
(unignored via !.env.example) with MIDSCENE_MODEL_* and playground env hints.
@yuyutaotao
Copy link
Copy Markdown
Collaborator

Hi @FinnJov ,
几个话题麻烦看下:
2. 现在的问题是什么?什么场景下会注入失败?
3. 不要做 breaking change,默认行为不要变,增加新的 MIDSCENE_PLAYGROUND_HOST 参数来解决
4. 直接用 rimraf 吧

付焦方(Fu Jiaofang) and others added 2 commits May 26, 2026 15:05
…HOST override

Per review: keep default listen behavior unchanged. Users can set MIDSCENE_PLAYGROUND_HOST=127.0.0.1 for local-only access.

Co-authored-by: Cursor <[email protected]>
Per review: replace scripts/clean.mjs with rimraf, aligned with other packages in the monorepo.

Co-authored-by: Cursor <[email protected]>
@FinnJov
Copy link
Copy Markdown
Author

FinnJov commented May 27, 2026

你好@FinnJov, 关注几个问题看下: 2. 现在的问题是什么?什么场景下会注入失败? 3. 不要做破坏性改变,默认行为不要变,增加新的 MIDSCENE_PLAYGROUND_HOST 参数来解决 4. 直接用 rimraf 吧

@鱼鱼涛涛
一、. 现在的问题是什么?

  1. 用户侧问题(仓库 CONTRIBUTING 已描述):
    当 report 模板注入没有生效时,最终生成/打开的报告内容里会出现字面量 REPLACE_ME_WITH_REPORT_HTML,说明 core 侧仍在使用占位符模板。

  2. 本次 packages/core/rslib.config.ts 的兜底逻辑在什么场景会触发:

  • apps/report/dist/index.html 存在时,core build 会读取该模板并尝试把模板内容注入到 packages/core/dist 下的 .js/.mjs 产物里(替换 'REPLACE_ME_WITH_REPORT_HTML' 或更新 /*REPORT_HTML_REPLACED*/... 标记)。
  • 如果上述注入流程执行完后,packages/core/dist 里仍然能扫描到 REPLACE_ME_WITH_REPORT_HTML(说明占位符没有被替换掉),则 core build 会抛错,避免“构建看似成功但产物仍含占位符”。
  1. 不会触发失败的情况:
  • apps/report/dist/index.html 不存在,仍保持原有行为:仅 warn 并跳过注入(避免在 monorepo 下引入 core↔report 的构建顺序/循环依赖问题)。

如果维护者希望把第 2 条的 build fail 改为 warn(只提示不阻断),我也可以按项目策略调整。
二、第 3 点:默认仍为 0.0.0.0,通过 MIDSCENE_PLAYGROUND_HOST 自定义(.env.example 已补充说明)。
三、第 4 点:clean 改为 rimraf,已移除 scripts/clean.mjs。

第 2 点说明见上条评论,如需调整 throw 策略请告知。
相关代码已 push 到本 PR 分支最新 commit,可在「Files changed」查看。

@yuyutaotao
Copy link
Copy Markdown
Collaborator

Will be merged by this PR #2554

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants