Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2043f8c966 | |||
| 65012e89b6 | |||
| 64b9ccfb9d | |||
| fcc3c39dad | |||
| f7a0adc616 | |||
| 57cd81d551 | |||
| 78088e422a | |||
| 65551cd827 |
@@ -5,7 +5,6 @@
|
|||||||
## 目录约定
|
## 目录约定
|
||||||
|
|
||||||
- `.codex/skills/` 是项目专属 skill 根目录。每个 skill 以目录中的 `SKILL.md` 为入口,配套的参考资料和脚本放在同一目录下。
|
- `.codex/skills/` 是项目专属 skill 根目录。每个 skill 以目录中的 `SKILL.md` 为入口,配套的参考资料和脚本放在同一目录下。
|
||||||
- `spec-driven-development` 负责跨模块、公开契约、SpacetimeDB、AGC/Runtime 和复杂 UI 任务的规范先行与逐里程碑验收;具体规则以 `docs/` 下的 SDD 工作流和模板为准。
|
|
||||||
- `.codex/plugins/` 保存随仓库分发的项目插件资源及其参考资料。当前的 `game-studio` 插件提供浏览器游戏设计、原型、2D/3D 技术栈、素材管线和 playtest 工作流;是否启用遵循当前 Codex 的插件加载机制,不依赖旧工具的环境变量或个人配置脚本。
|
- `.codex/plugins/` 保存随仓库分发的项目插件资源及其参考资料。当前的 `game-studio` 插件提供浏览器游戏设计、原型、2D/3D 技术栈、素材管线和 playtest 工作流;是否启用遵循当前 Codex 的插件加载机制,不依赖旧工具的环境变量或个人配置脚本。
|
||||||
- `.codex/hooks/`、`.codex/environments/` 等目录保存项目工具链所需的 hooks 和环境模板;它们不替代项目代码中的运行时配置。
|
- `.codex/hooks/`、`.codex/environments/` 等目录保存项目工具链所需的 hooks 和环境模板;它们不替代项目代码中的运行时配置。
|
||||||
- 长期有效的产品、架构、接口、排障和协作知识统一放在 `docs/` 与 `docs/project-memory/`,不复制到本目录。
|
- 长期有效的产品、架构、接口、排障和协作知识统一放在 `docs/` 与 `docs/project-memory/`,不复制到本目录。
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
---
|
|
||||||
name: spec-driven-development
|
|
||||||
description: 在 Genarrative 中处理跨模块功能、公开 API/DTO、SpacetimeDB schema、AGC/Runtime 或复杂 UI 状态链路时,按主规范、里程碑规范、单里程碑实现计划和验收证据推进;小型局部修复不触发。
|
|
||||||
license: MIT
|
|
||||||
metadata:
|
|
||||||
codex:
|
|
||||||
tags: [SDD, 规范驱动开发, 主规范, 里程碑, 验收]
|
|
||||||
---
|
|
||||||
|
|
||||||
# SDD 规范驱动开发
|
|
||||||
|
|
||||||
本 skill 把 Genarrative 的复杂任务路由到规范先行、单里程碑交付的工作流。权威规则和模板分别见:
|
|
||||||
|
|
||||||
- `docs/【协作规范】规范驱动开发工作流-2026-09-12.md`
|
|
||||||
- `docs/project-memory/shared-memory/【模板】规范驱动开发主规范与里程碑模板-2026-09-12.md`
|
|
||||||
|
|
||||||
## 触发条件
|
|
||||||
|
|
||||||
使用本 skill 的任务包括:
|
|
||||||
|
|
||||||
- 跨前端、`api-server`、`platform-*`、`spacetime-client`、`spacetime-module` 或 `module-*` 的功能。
|
|
||||||
- `/api/external/v1`、共享 DTO、OpenAPI、SpacetimeDB schema、迁移或跨版本重放合同变化。
|
|
||||||
- AGC / DirectProject、Agent Runtime、工具白名单、审批、持久化恢复或资源工作流变化。
|
|
||||||
- 复杂 UI 状态链路、入口/页面生命周期变化,或需要多个独立验收面的功能。
|
|
||||||
|
|
||||||
文案、单文件局部修复、无行为变化重构和一次性诊断继续使用轻量流程;执行中一旦触及公开行为或跨模块合同,切换到本 skill。
|
|
||||||
|
|
||||||
## 执行要求
|
|
||||||
|
|
||||||
1. 检查工作树,读取当前专题、源码、测试、契约和历史决策;写清交付结果、验收判据和不做项。
|
|
||||||
2. 找到或更新唯一主规范。主规范描述行为合同、边界、非目标、兼容/迁移和证据,不绑定实现细节。
|
|
||||||
3. 在 `docs/project-memory/plans/` 创建一个或多个 `【里程碑】中文标题-YYYY-MM-DD.md`,填写 `Version`、`Status`、`Date`、`Parent Spec`、范围、依赖和验收标准;评审通过前不写业务代码。
|
|
||||||
4. 每次只选择一个已评审里程碑,创建对应的 `【实施计划】中文标题-YYYY-MM-DD.md`,明确修改边界、顺序、验证命令、风险和回滚点。
|
|
||||||
5. 发现行为需要变化时,严格按 `主规范 → 尚未实现的里程碑规范 → 当前实现计划 → 代码与测试` 更新。
|
|
||||||
6. 完成一个里程碑后,提供主规范/里程碑逐条对照、自动化验证、必要运行时 smoke、边界验证和未验证项;未验收不得推进下一个里程碑。
|
|
||||||
7. 全部验收通过后,将持久结论合并回主规范,删除已完成的临时计划,并检查文档、契约、测试和提交边界一致。
|
|
||||||
|
|
||||||
## 约束
|
|
||||||
|
|
||||||
- 里程碑和实现计划是开发期协调文件,完成或取消后删除;阶段编号和临时名称不得进入产品代码、用户文档、测试名称或提交标题。
|
|
||||||
- 活动计划可以提交以便团队同步,但不得把一次性实现步骤写进长期规范。
|
|
||||||
- 继续遵守现有 API、SpacetimeDB、AGC、编码和中文文档约束;本 skill 不替代专题门禁。
|
|
||||||
- 文档任务至少运行 `npm run check:doc-index`、`npm run check:encoding` 和 `git diff --check`;代码任务再运行范围匹配的测试、类型检查、schema/OpenAPI 或运行时 smoke。
|
|
||||||
+54
-336
@@ -27,28 +27,9 @@ env:
|
|||||||
RUSTC_WRAPPER: ''
|
RUSTC_WRAPPER: ''
|
||||||
CARGO_BUILD_RUSTC_WRAPPER: ''
|
CARGO_BUILD_RUSTC_WRAPPER: ''
|
||||||
|
|
||||||
# job 声明顺序就是 runner 领取顺序,因此把最长尾的客户端 Rust 门禁排在前面,
|
|
||||||
# 让它在最少的等待下占用并发槽位;其余 job 按时长递减排列。
|
|
||||||
#
|
|
||||||
# 客户端(微信壳 / Expo 移动壳 / Tauri 桌面壳 / AI 游戏创作壳)门禁原先全部串在
|
|
||||||
# `Native shell tests` 一个 job 里,实测 18 分 37 秒。现在按门禁组拆成一个分组一个 job:
|
|
||||||
# `Native shell tests`(契约 + H5 / 微信 / 移动 / 桌面壳门禁 + 发布构建 smoke)、
|
|
||||||
# `AI game creator shell web tests`(typecheck + 壳内测试)、`AI game creator shell
|
|
||||||
# Rust shard 1/4` 到 `4/4`(AGC 壳 bin 单测按名单分 4 片)、`AI game creator shell
|
|
||||||
# Rust smoke`(agent-run smoke)与 `AI game creator shell Rust crates`(AGC 壳依赖的
|
|
||||||
# 共享 / 平台 crate 测试)。各自的命令与拆分前逐一对应,本地
|
|
||||||
# `npm run check:native-shells` 仍是同一条串行序列。
|
|
||||||
#
|
|
||||||
# AGC 壳的 bin 单测(2466 条)按名单分 4 片、一片一个 job:片内保持 `--test-threads=1`
|
|
||||||
# (当年线程并行会互相干扰的是进程内后台锁与异步终态),片与片之间靠 job 级并发摊开。
|
|
||||||
# 不要改回「一个 job 里多进程并行这几片」:同一容器内它们会争抢共享 HOME、target 与固定
|
|
||||||
# 临时路径,实测比整套串行还慢。每个分片 job 都会自校验「片并集等于全集且互斥」。
|
|
||||||
jobs:
|
jobs:
|
||||||
# AGC 壳自身的 Rust bin 单测分片,4 片各自独立 job 并发执行、片内仍保持
|
repository-checks:
|
||||||
# `--test-threads=1`。这里不装 npm 依赖:壳 Rust 门禁只用 cargo 与 node 内建模块,
|
name: Repository checks
|
||||||
# 也只需要 AGC 壳自己那份锁定依赖。
|
|
||||||
ai-game-creator-shell-rust-shard-1:
|
|
||||||
name: AI game creator shell Rust shard 1/4
|
|
||||||
runs-on: genarrative-ci
|
runs-on: genarrative-ci
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout full history from Gitea
|
- name: Checkout full history from Gitea
|
||||||
@@ -60,228 +41,76 @@ jobs:
|
|||||||
- name: Validate preinstalled CI job image and sandbox
|
- name: Validate preinstalled CI job image and sandbox
|
||||||
run: GENARRATIVE_GITEA_CI_CHECK_RUNTIME=1 bash scripts/check-gitea-ci-job-image.sh
|
run: GENARRATIVE_GITEA_CI_CHECK_RUNTIME=1 bash scripts/check-gitea-ci-job-image.sh
|
||||||
|
|
||||||
- name: Prepare AI game creator shell Rust dependencies
|
- name: Resolve comparison base
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
# AGC 壳有独立 Cargo.lock,其 path 依赖已含 platform-llm、platform-agent、
|
base_ref="$(node -e '
|
||||||
# agent-runtime-core 与 shared-contracts,因此只锁这一份 manifest 就能覆盖壳测试
|
const fs = require("node:fs");
|
||||||
# 与 smoke 的全部第三方依赖;server-rs 那次预热归 crate 级 job,不在这里重复。
|
const event = JSON.parse(fs.readFileSync(process.env.GITHUB_EVENT_PATH, "utf8"));
|
||||||
for attempt in $(seq 1 5); do
|
process.stdout.write(event.pull_request?.base?.sha ?? event.before ?? "");
|
||||||
if cargo fetch --locked \
|
')"
|
||||||
--target x86_64-unknown-linux-gnu \
|
if [[ -n "${base_ref}" && ! "${base_ref}" =~ ^0+$ ]]; then
|
||||||
--manifest-path apps/ai-game-creator-shell/src-tauri/Cargo.toml; then
|
git cat-file -e "${base_ref}^{commit}" 2>/dev/null || {
|
||||||
break
|
echo "comparison base commit is unavailable: ${base_ref}" >&2
|
||||||
fi
|
|
||||||
if [[ "${attempt}" -eq 5 ]]; then
|
|
||||||
echo 'AI game creator shell Cargo dependency fetch failed after 5 attempts.' >&2
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
}
|
||||||
sleep $((attempt * 2))
|
else
|
||||||
done
|
base_ref="$(git merge-base HEAD origin/master 2>/dev/null || git rev-parse HEAD)"
|
||||||
|
fi
|
||||||
|
resolved_base_ref="$(git rev-parse --verify "${base_ref}^{commit}" 2>/dev/null || true)"
|
||||||
|
head_ref="$(git rev-parse HEAD)"
|
||||||
|
if [[ "${resolved_base_ref}" == "${head_ref}" ]]; then
|
||||||
|
resolved_base_ref="$(git rev-parse --verify HEAD^ 2>/dev/null || true)"
|
||||||
|
fi
|
||||||
|
if [[ -z "${resolved_base_ref}" ]]; then
|
||||||
|
echo 'comparison base must resolve to a commit distinct from HEAD.' >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
base_ref="${resolved_base_ref}"
|
||||||
|
if [[ "${GITHUB_EVENT_NAME:-}" == 'pull_request' ]] \
|
||||||
|
&& ! git merge-base --is-ancestor "${base_ref}" HEAD; then
|
||||||
|
echo 'pull request head does not contain the latest base commit; update the branch and rerun CI.' >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "SPACETIME_SCHEMA_BASE_REF=${base_ref}" >> "${GITHUB_ENV}"
|
||||||
|
|
||||||
- name: Run AI game creator shell Rust shard 1/4
|
- name: Install npm dependencies
|
||||||
run: npm run check:native-shells:agc-rust-shard-1
|
run: bash scripts/ci-npm-ci-with-retry.sh
|
||||||
|
|
||||||
ai-game-creator-shell-rust-shard-2:
|
- name: Run repository checks
|
||||||
name: AI game creator shell Rust shard 2/4
|
run: npm run check:repository-ci
|
||||||
|
|
||||||
|
frontend-tests:
|
||||||
|
name: Frontend tests
|
||||||
runs-on: genarrative-ci
|
runs-on: genarrative-ci
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout full history from Gitea
|
- name: Checkout source from Gitea
|
||||||
env:
|
env:
|
||||||
GENARRATIVE_GITEA_FETCH_DEPTH: '0'
|
GENARRATIVE_GITEA_FETCH_DEPTH: '1'
|
||||||
GENARRATIVE_GITEA_TOKEN: ${{ github.token }}
|
GENARRATIVE_GITEA_TOKEN: ${{ github.token }}
|
||||||
run: genarrative-gitea-checkout
|
run: genarrative-gitea-checkout
|
||||||
|
|
||||||
- name: Validate preinstalled CI job image and sandbox
|
- name: Validate preinstalled CI job image and sandbox
|
||||||
run: GENARRATIVE_GITEA_CI_CHECK_RUNTIME=1 bash scripts/check-gitea-ci-job-image.sh
|
run: GENARRATIVE_GITEA_CI_CHECK_RUNTIME=1 bash scripts/check-gitea-ci-job-image.sh
|
||||||
|
|
||||||
- name: Prepare AI game creator shell Rust dependencies
|
- name: Install npm dependencies
|
||||||
shell: bash
|
run: bash scripts/ci-npm-ci-with-retry.sh
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
for attempt in $(seq 1 5); do
|
|
||||||
if cargo fetch --locked \
|
|
||||||
--target x86_64-unknown-linux-gnu \
|
|
||||||
--manifest-path apps/ai-game-creator-shell/src-tauri/Cargo.toml; then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
if [[ "${attempt}" -eq 5 ]]; then
|
|
||||||
echo 'AI game creator shell Cargo dependency fetch failed after 5 attempts.' >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
sleep $((attempt * 2))
|
|
||||||
done
|
|
||||||
|
|
||||||
- name: Run AI game creator shell Rust shard 2/4
|
- name: Run frontend and script tests
|
||||||
run: npm run check:native-shells:agc-rust-shard-2
|
run: npm run test
|
||||||
|
|
||||||
ai-game-creator-shell-rust-shard-3:
|
- name: Run BgFilter worker smoke harness tests
|
||||||
name: AI game creator shell Rust shard 3/4
|
run: npm run bgfilter-worker:smoke-test
|
||||||
runs-on: genarrative-ci
|
|
||||||
steps:
|
|
||||||
- name: Checkout full history from Gitea
|
|
||||||
env:
|
|
||||||
GENARRATIVE_GITEA_FETCH_DEPTH: '0'
|
|
||||||
GENARRATIVE_GITEA_TOKEN: ${{ github.token }}
|
|
||||||
run: genarrative-gitea-checkout
|
|
||||||
|
|
||||||
- name: Validate preinstalled CI job image and sandbox
|
- name: Validate production health patrol behavior
|
||||||
run: GENARRATIVE_GITEA_CI_CHECK_RUNTIME=1 bash scripts/check-gitea-ci-job-image.sh
|
run: npm run check:production-health-patrol
|
||||||
|
|
||||||
- name: Prepare AI game creator shell Rust dependencies
|
- name: Validate production API release behavior
|
||||||
shell: bash
|
run: npm run check:production-api-release
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
for attempt in $(seq 1 5); do
|
|
||||||
if cargo fetch --locked \
|
|
||||||
--target x86_64-unknown-linux-gnu \
|
|
||||||
--manifest-path apps/ai-game-creator-shell/src-tauri/Cargo.toml; then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
if [[ "${attempt}" -eq 5 ]]; then
|
|
||||||
echo 'AI game creator shell Cargo dependency fetch failed after 5 attempts.' >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
sleep $((attempt * 2))
|
|
||||||
done
|
|
||||||
|
|
||||||
- name: Run AI game creator shell Rust shard 3/4
|
- name: Validate production API deploy behavior
|
||||||
run: npm run check:native-shells:agc-rust-shard-3
|
run: npm run check:production-api-deploy
|
||||||
|
|
||||||
ai-game-creator-shell-rust-shard-4:
|
|
||||||
name: AI game creator shell Rust shard 4/4
|
|
||||||
runs-on: genarrative-ci
|
|
||||||
steps:
|
|
||||||
- name: Checkout full history from Gitea
|
|
||||||
env:
|
|
||||||
GENARRATIVE_GITEA_FETCH_DEPTH: '0'
|
|
||||||
GENARRATIVE_GITEA_TOKEN: ${{ github.token }}
|
|
||||||
run: genarrative-gitea-checkout
|
|
||||||
|
|
||||||
- name: Validate preinstalled CI job image and sandbox
|
|
||||||
run: GENARRATIVE_GITEA_CI_CHECK_RUNTIME=1 bash scripts/check-gitea-ci-job-image.sh
|
|
||||||
|
|
||||||
- name: Prepare AI game creator shell Rust dependencies
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
for attempt in $(seq 1 5); do
|
|
||||||
if cargo fetch --locked \
|
|
||||||
--target x86_64-unknown-linux-gnu \
|
|
||||||
--manifest-path apps/ai-game-creator-shell/src-tauri/Cargo.toml; then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
if [[ "${attempt}" -eq 5 ]]; then
|
|
||||||
echo 'AI game creator shell Cargo dependency fetch failed after 5 attempts.' >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
sleep $((attempt * 2))
|
|
||||||
done
|
|
||||||
|
|
||||||
- name: Run AI game creator shell Rust shard 4/4
|
|
||||||
run: npm run check:native-shells:agc-rust-shard-4
|
|
||||||
|
|
||||||
# agent-run smoke 会 spawn `cargo run`(走壳自己的 manifest),同样不装 npm 依赖,
|
|
||||||
# 单独一个 job,免得把已经压到 4 分钟级的片 job 拖长。
|
|
||||||
ai-game-creator-shell-rust-smoke:
|
|
||||||
name: AI game creator shell Rust smoke
|
|
||||||
runs-on: genarrative-ci
|
|
||||||
steps:
|
|
||||||
- name: Checkout full history from Gitea
|
|
||||||
env:
|
|
||||||
GENARRATIVE_GITEA_FETCH_DEPTH: '0'
|
|
||||||
GENARRATIVE_GITEA_TOKEN: ${{ github.token }}
|
|
||||||
run: genarrative-gitea-checkout
|
|
||||||
|
|
||||||
- name: Validate preinstalled CI job image and sandbox
|
|
||||||
run: GENARRATIVE_GITEA_CI_CHECK_RUNTIME=1 bash scripts/check-gitea-ci-job-image.sh
|
|
||||||
|
|
||||||
- name: Prepare AI game creator shell Rust dependencies
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
for attempt in $(seq 1 5); do
|
|
||||||
if cargo fetch --locked \
|
|
||||||
--target x86_64-unknown-linux-gnu \
|
|
||||||
--manifest-path apps/ai-game-creator-shell/src-tauri/Cargo.toml; then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
if [[ "${attempt}" -eq 5 ]]; then
|
|
||||||
echo 'AI game creator shell Cargo dependency fetch failed after 5 attempts.' >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
sleep $((attempt * 2))
|
|
||||||
done
|
|
||||||
|
|
||||||
- name: Run AI game creator shell agent-run smoke
|
|
||||||
run: npm run check:native-shells:agc-rust-smoke
|
|
||||||
|
|
||||||
# AGC 壳依赖的共享 / 平台 crate 测试用的是 server-rs workspace 与两个无锁独立 crate
|
|
||||||
# 的 manifest,属另一套依赖图,因此单独一个 job 预热、单独跑。
|
|
||||||
ai-game-creator-shell-rust-crates:
|
|
||||||
name: AI game creator shell Rust crates
|
|
||||||
runs-on: genarrative-ci
|
|
||||||
steps:
|
|
||||||
- name: Checkout full history from Gitea
|
|
||||||
env:
|
|
||||||
GENARRATIVE_GITEA_FETCH_DEPTH: '0'
|
|
||||||
GENARRATIVE_GITEA_TOKEN: ${{ github.token }}
|
|
||||||
run: genarrative-gitea-checkout
|
|
||||||
|
|
||||||
- name: Validate preinstalled CI job image and sandbox
|
|
||||||
run: GENARRATIVE_GITEA_CI_CHECK_RUNTIME=1 bash scripts/check-gitea-ci-job-image.sh
|
|
||||||
|
|
||||||
- name: Prepare server-rs Rust dependencies
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
for attempt in $(seq 1 5); do
|
|
||||||
if cargo fetch --locked \
|
|
||||||
--target x86_64-unknown-linux-gnu \
|
|
||||||
--manifest-path server-rs/Cargo.toml; then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
if [[ "${attempt}" -eq 5 ]]; then
|
|
||||||
echo 'server-rs Cargo dependency fetch failed after 5 attempts.' >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
sleep $((attempt * 2))
|
|
||||||
done
|
|
||||||
|
|
||||||
- name: Prepare standalone Rust crate dependencies
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
# agent-runtime-core / agent-runtime-orchestration 被 server-rs/Cargo.toml 的
|
|
||||||
# exclude 排除,不参与上面的 workspace 锁文件,因此上面那次锁定 fetch 覆盖不到它们;
|
|
||||||
# 而 `npm run ai-game-creator-shell:check:rust:crates` 会用
|
|
||||||
# `cargo test --manifest-path` 单独跑这两个 crate。不在这里预热的话,这两条测试
|
|
||||||
# 会在测试阶段自己 `Updating crates.io index`,crates.io 一抖动整条 job 就红
|
|
||||||
# (见 #327 / PR #316 run 1950)。
|
|
||||||
# 两个 crate 都没有提交 Cargo.lock,所以这里只能做不带锁标志的 fetch:
|
|
||||||
# 加锁标志会因为缺少锁文件直接失败。生成的 Cargo.lock 落在两个 crate 目录内,
|
|
||||||
# 已被各自的 .gitignore 忽略,只留在容器里;随后的测试阶段因此能用锁定版本
|
|
||||||
# 解析,不再触碰 registry index。
|
|
||||||
for manifest_path in \
|
|
||||||
server-rs/crates/agent-runtime-core/Cargo.toml \
|
|
||||||
server-rs/crates/agent-runtime-orchestration/Cargo.toml; do
|
|
||||||
for attempt in $(seq 1 5); do
|
|
||||||
if cargo fetch \
|
|
||||||
--target x86_64-unknown-linux-gnu \
|
|
||||||
--manifest-path "${manifest_path}"; then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
if [[ "${attempt}" -eq 5 ]]; then
|
|
||||||
echo "standalone crate dependency fetch failed after 5 attempts: ${manifest_path}" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
sleep $((attempt * 2))
|
|
||||||
done
|
|
||||||
done
|
|
||||||
|
|
||||||
- name: Run AI game creator shell shared crate gates
|
|
||||||
run: npm run check:native-shells:agc-rust-crates
|
|
||||||
|
|
||||||
backend-tests:
|
backend-tests:
|
||||||
name: Backend tests
|
name: Backend tests
|
||||||
@@ -365,8 +194,6 @@ jobs:
|
|||||||
- name: Check SpacetimeDB module
|
- name: Check SpacetimeDB module
|
||||||
run: cargo check --locked -p spacetime-module --manifest-path server-rs/Cargo.toml
|
run: cargo check --locked -p spacetime-module --manifest-path server-rs/Cargo.toml
|
||||||
|
|
||||||
# 客户端的壳级与契约门禁:静态契约断言、H5 / 微信 / 移动 / 桌面壳运行时门禁,
|
|
||||||
# 以及依赖发布产物的构建 smoke。
|
|
||||||
native-shell-tests:
|
native-shell-tests:
|
||||||
name: Native shell tests
|
name: Native shell tests
|
||||||
runs-on: genarrative-ci
|
runs-on: genarrative-ci
|
||||||
@@ -388,6 +215,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
for manifest_path in \
|
for manifest_path in \
|
||||||
|
server-rs/Cargo.toml \
|
||||||
apps/desktop-shell/src-tauri/Cargo.toml \
|
apps/desktop-shell/src-tauri/Cargo.toml \
|
||||||
apps/ai-game-creator-shell/src-tauri/Cargo.toml; do
|
apps/ai-game-creator-shell/src-tauri/Cargo.toml; do
|
||||||
for attempt in $(seq 1 5); do
|
for attempt in $(seq 1 5); do
|
||||||
@@ -404,118 +232,8 @@ jobs:
|
|||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
- name: Run native shell contract gates
|
|
||||||
run: npm run check:native-shells:contract
|
|
||||||
|
|
||||||
- name: Run native shell gates
|
- name: Run native shell gates
|
||||||
run: npm run check:native-shells:shells
|
run: npm run check:native-shells
|
||||||
|
|
||||||
- name: Run native shell release build smoke
|
|
||||||
run: npm run check:native-shells:release
|
|
||||||
|
|
||||||
- name: Ensure native lockfiles are unchanged
|
- name: Ensure native lockfiles are unchanged
|
||||||
run: git diff --exit-code -- apps/desktop-shell/src-tauri/Cargo.lock apps/ai-game-creator-shell/src-tauri/Cargo.lock
|
run: git diff --exit-code -- apps/desktop-shell/src-tauri/Cargo.lock apps/ai-game-creator-shell/src-tauri/Cargo.lock
|
||||||
|
|
||||||
frontend-tests:
|
|
||||||
name: Frontend tests
|
|
||||||
runs-on: genarrative-ci
|
|
||||||
steps:
|
|
||||||
- name: Checkout source from Gitea
|
|
||||||
env:
|
|
||||||
GENARRATIVE_GITEA_FETCH_DEPTH: '1'
|
|
||||||
GENARRATIVE_GITEA_TOKEN: ${{ github.token }}
|
|
||||||
run: genarrative-gitea-checkout
|
|
||||||
|
|
||||||
- name: Validate preinstalled CI job image and sandbox
|
|
||||||
run: GENARRATIVE_GITEA_CI_CHECK_RUNTIME=1 bash scripts/check-gitea-ci-job-image.sh
|
|
||||||
|
|
||||||
- name: Install npm dependencies
|
|
||||||
run: bash scripts/ci-npm-ci-with-retry.sh
|
|
||||||
|
|
||||||
- name: Run frontend and script tests
|
|
||||||
run: npm run test
|
|
||||||
|
|
||||||
- name: Run BgFilter worker smoke harness tests
|
|
||||||
run: npm run bgfilter-worker:smoke-test
|
|
||||||
|
|
||||||
- name: Validate production health patrol behavior
|
|
||||||
run: npm run check:production-health-patrol
|
|
||||||
|
|
||||||
- name: Validate production API release behavior
|
|
||||||
run: npm run check:production-api-release
|
|
||||||
|
|
||||||
- name: Validate production API deploy behavior
|
|
||||||
run: npm run check:production-api-deploy
|
|
||||||
|
|
||||||
repository-checks:
|
|
||||||
name: Repository checks
|
|
||||||
runs-on: genarrative-ci
|
|
||||||
steps:
|
|
||||||
- name: Checkout full history from Gitea
|
|
||||||
env:
|
|
||||||
GENARRATIVE_GITEA_FETCH_DEPTH: '0'
|
|
||||||
GENARRATIVE_GITEA_TOKEN: ${{ github.token }}
|
|
||||||
run: genarrative-gitea-checkout
|
|
||||||
|
|
||||||
- name: Validate preinstalled CI job image and sandbox
|
|
||||||
run: GENARRATIVE_GITEA_CI_CHECK_RUNTIME=1 bash scripts/check-gitea-ci-job-image.sh
|
|
||||||
|
|
||||||
- name: Resolve comparison base
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
base_ref="$(node -e '
|
|
||||||
const fs = require("node:fs");
|
|
||||||
const event = JSON.parse(fs.readFileSync(process.env.GITHUB_EVENT_PATH, "utf8"));
|
|
||||||
process.stdout.write(event.pull_request?.base?.sha ?? event.before ?? "");
|
|
||||||
')"
|
|
||||||
if [[ -n "${base_ref}" && ! "${base_ref}" =~ ^0+$ ]]; then
|
|
||||||
git cat-file -e "${base_ref}^{commit}" 2>/dev/null || {
|
|
||||||
echo "comparison base commit is unavailable: ${base_ref}" >&2
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
else
|
|
||||||
base_ref="$(git merge-base HEAD origin/master 2>/dev/null || git rev-parse HEAD)"
|
|
||||||
fi
|
|
||||||
resolved_base_ref="$(git rev-parse --verify "${base_ref}^{commit}" 2>/dev/null || true)"
|
|
||||||
head_ref="$(git rev-parse HEAD)"
|
|
||||||
if [[ "${resolved_base_ref}" == "${head_ref}" ]]; then
|
|
||||||
resolved_base_ref="$(git rev-parse --verify HEAD^ 2>/dev/null || true)"
|
|
||||||
fi
|
|
||||||
if [[ -z "${resolved_base_ref}" ]]; then
|
|
||||||
echo 'comparison base must resolve to a commit distinct from HEAD.' >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
base_ref="${resolved_base_ref}"
|
|
||||||
if [[ "${GITHUB_EVENT_NAME:-}" == 'pull_request' ]] \
|
|
||||||
&& ! git merge-base --is-ancestor "${base_ref}" HEAD; then
|
|
||||||
echo 'pull request head does not contain the latest base commit; update the branch and rerun CI.' >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo "SPACETIME_SCHEMA_BASE_REF=${base_ref}" >> "${GITHUB_ENV}"
|
|
||||||
|
|
||||||
- name: Install npm dependencies
|
|
||||||
run: bash scripts/ci-npm-ci-with-retry.sh
|
|
||||||
|
|
||||||
- name: Run repository checks
|
|
||||||
run: npm run check:repository-ci
|
|
||||||
|
|
||||||
# 客户端的 AI 游戏创作壳前端门禁:typecheck 与壳内测试,不触碰 Cargo。
|
|
||||||
ai-game-creator-shell-web-tests:
|
|
||||||
name: AI game creator shell web tests
|
|
||||||
runs-on: genarrative-ci
|
|
||||||
steps:
|
|
||||||
- name: Checkout full history from Gitea
|
|
||||||
env:
|
|
||||||
GENARRATIVE_GITEA_FETCH_DEPTH: '0'
|
|
||||||
GENARRATIVE_GITEA_TOKEN: ${{ github.token }}
|
|
||||||
run: genarrative-gitea-checkout
|
|
||||||
|
|
||||||
- name: Validate preinstalled CI job image and sandbox
|
|
||||||
run: GENARRATIVE_GITEA_CI_CHECK_RUNTIME=1 bash scripts/check-gitea-ci-job-image.sh
|
|
||||||
|
|
||||||
- name: Install npm dependencies
|
|
||||||
run: bash scripts/ci-npm-ci-with-retry.sh
|
|
||||||
|
|
||||||
- name: Run AI game creator shell web gates
|
|
||||||
run: npm run check:native-shells:agc-web
|
|
||||||
|
|||||||
@@ -40,8 +40,6 @@ temp*build*/
|
|||||||
/apps/ai-game-creator-shell/src-tauri/resources/codex/win-x64/codex-path/
|
/apps/ai-game-creator-shell/src-tauri/resources/codex/win-x64/codex-path/
|
||||||
/apps/ai-game-creator-shell/src-tauri/resources/codex/win-x64/codex-resources/
|
/apps/ai-game-creator-shell/src-tauri/resources/codex/win-x64/codex-resources/
|
||||||
/apps/ai-game-creator-shell/src-tauri/resources/codex/win-x64/codex-package.json
|
/apps/ai-game-creator-shell/src-tauri/resources/codex/win-x64/codex-package.json
|
||||||
/apps/ai-game-creator-shell/src-tauri/resources/plugins/
|
|
||||||
/plugins/agc-cocos-editor/native/payload/
|
|
||||||
/apps/ai-game-creator-shell/logs/
|
/apps/ai-game-creator-shell/logs/
|
||||||
/apps/ai-game-creator-shell/.llm-drafts/
|
/apps/ai-game-creator-shell/.llm-drafts/
|
||||||
/apps/ai-game-creator-shell/game-creator.config.local.json
|
/apps/ai-game-creator-shell/game-creator.config.local.json
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
3. [`docs/project-memory/README.md`](docs/project-memory/README.md)、[`project-overview.md`](docs/project-memory/shared-memory/project-overview.md)、[`team-conventions.md`](docs/project-memory/shared-memory/team-conventions.md)、[`development-workflow.md`](docs/project-memory/shared-memory/development-workflow.md)。
|
3. [`docs/project-memory/README.md`](docs/project-memory/README.md)、[`project-overview.md`](docs/project-memory/shared-memory/project-overview.md)、[`team-conventions.md`](docs/project-memory/shared-memory/team-conventions.md)、[`development-workflow.md`](docs/project-memory/shared-memory/development-workflow.md)。
|
||||||
4. 与任务相关的 [`decision-log.md`](docs/project-memory/shared-memory/decision-log.md)、[`pitfalls.md`](docs/project-memory/shared-memory/pitfalls.md)、[`docs/README.md`](docs/README.md) 和当前专题文档。
|
4. 与任务相关的 [`decision-log.md`](docs/project-memory/shared-memory/decision-log.md)、[`pitfalls.md`](docs/project-memory/shared-memory/pitfalls.md)、[`docs/README.md`](docs/README.md) 和当前专题文档。
|
||||||
- 落地工程修改前,先确认是否已有足够具体的 PRD、技术方案或当前融合文档;文档仍存在编码级歧义时,先补文档再编码。
|
- 落地工程修改前,先确认是否已有足够具体的 PRD、技术方案或当前融合文档;文档仍存在编码级歧义时,先补文档再编码。
|
||||||
- 跨模块功能、公开 API/DTO、SpacetimeDB schema、AGC/Runtime 或复杂 UI 状态链路必须按 [`docs/【协作规范】规范驱动开发工作流-2026-09-12.md`](docs/【协作规范】规范驱动开发工作流-2026-09-12.md) 先完成主规范、里程碑规范和单里程碑实现计划;评审与验收门禁未通过前不得进入下一里程碑。局部修复、文案和无行为变化重构继续走轻量流程。
|
|
||||||
- 本仓库的本地 RAG 位于 [`scripts/rag/`](scripts/rag/);RAG 只作为候选上下文,不替代打开源文件核对。默认不安装 RAG 运行时依赖,需要启用时必须先询问用户,并只安装到 gitignored 的 `.rag/runtime/`。
|
- 本仓库的本地 RAG 位于 [`scripts/rag/`](scripts/rag/);RAG 只作为候选上下文,不替代打开源文件核对。默认不安装 RAG 运行时依赖,需要启用时必须先询问用户,并只安装到 gitignored 的 `.rag/runtime/`。
|
||||||
|
|
||||||
## 绝对约束
|
## 绝对约束
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
# resources/plugins 由 build.rs 从 plugins/ 复制生成,属于构建产物。
|
|
||||||
# 它在 dev 监听范围内,重新生成会让 Tauri dev 误判为源码改动而触发
|
|
||||||
# “构建 -> 监听 -> 再构建”的自触发循环。
|
|
||||||
resources/plugins/
|
|
||||||
@@ -16,5 +16,8 @@
|
|||||||
"maxRetries": 2,
|
"maxRetries": 2,
|
||||||
"retryBackoffMs": 500
|
"retryBackoffMs": 500
|
||||||
},
|
},
|
||||||
"agentLlm": {}
|
"agentLlm": {},
|
||||||
|
"planning": {
|
||||||
|
"capabilityEnabled": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@genarrative/ai-game-creator-shell",
|
"name": "@genarrative/ai-game-creator-shell",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.1.29",
|
"version": "0.1.19",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "node scripts/start-tauri-dev.mjs",
|
"dev": "node scripts/start-tauri-dev.mjs",
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
"dev-stack": "node scripts/start-dev-stack.mjs",
|
"dev-stack": "node scripts/start-dev-stack.mjs",
|
||||||
"build": "node scripts/build-release.mjs",
|
"build": "node scripts/build-release.mjs",
|
||||||
"release:upload": "node scripts/release-upload.mjs",
|
"release:upload": "node scripts/release-upload.mjs",
|
||||||
|
"bump-version": "node scripts/bump-version.mjs",
|
||||||
"skill-pack:check": "node scripts/check-skill-pack.mjs",
|
"skill-pack:check": "node scripts/check-skill-pack.mjs",
|
||||||
"skill-pack:sync": "node scripts/check-skill-pack.mjs --write",
|
"skill-pack:sync": "node scripts/check-skill-pack.mjs --write",
|
||||||
"skill-pack:test": "node --test scripts/check-skill-pack.test.mjs",
|
"skill-pack:test": "node --test scripts/check-skill-pack.test.mjs",
|
||||||
@@ -19,6 +20,8 @@
|
|||||||
"config": "node scripts/game-creator-config-wizard.mjs",
|
"config": "node scripts/game-creator-config-wizard.mjs",
|
||||||
"test:chat": "node scripts/agent-swarm-test-chat.mjs --task \"制作一个可直接试玩的原创植物塔防小游戏:玩家选择并放置原创守卫阻挡敌人,完成波次后可以进入下一关并重新开始。主题、单位名称与视觉语言必须原创,不使用任何现有游戏角色、单位名、Logo 或受保护视觉语言。请自主完成正式产物、静态检查和双视口试玩验证。\" --no-open",
|
"test:chat": "node scripts/agent-swarm-test-chat.mjs --task \"制作一个可直接试玩的原创植物塔防小游戏:玩家选择并放置原创守卫阻挡敌人,完成波次后可以进入下一关并重新开始。主题、单位名称与视觉语言必须原创,不使用任何现有游戏角色、单位名、Logo 或受保护视觉语言。请自主完成正式产物、静态检查和双视口试玩验证。\" --no-open",
|
||||||
"test:chat:manual": "node scripts/agent-swarm-test-chat.mjs",
|
"test:chat:manual": "node scripts/agent-swarm-test-chat.mjs",
|
||||||
|
"test:plan": "node scripts/agent-swarm-test-chat.mjs --plan --task \"我想做一款原创横版像素解谜小游戏,主角是一个能操控自己影子的小机器人,影子可以变成平台和开关。请完成立项策划并给出 Fast GDD。主题、角色名与视觉语言必须原创,不使用任何现有游戏角色、名称、Logo 或受保护视觉语言。\"",
|
||||||
|
"test:plan:manual": "node scripts/agent-swarm-test-chat.mjs --plan",
|
||||||
"agent-run": "node scripts/run-cli-with-config.mjs --agent-run",
|
"agent-run": "node scripts/run-cli-with-config.mjs --agent-run",
|
||||||
"agent-run:smoke": "node scripts/smoke-agent-run-local-provider.mjs",
|
"agent-run:smoke": "node scripts/smoke-agent-run-local-provider.mjs",
|
||||||
"agent-runtime:real-e2e": "node scripts/agent-runtime-real-e2e.mjs",
|
"agent-runtime:real-e2e": "node scripts/agent-runtime-real-e2e.mjs",
|
||||||
@@ -51,7 +54,6 @@
|
|||||||
"focus-trap-react": "^12.0.3",
|
"focus-trap-react": "^12.0.3",
|
||||||
"lexical": "^0.47.0",
|
"lexical": "^0.47.0",
|
||||||
"lucide-react": "^0.546.0",
|
"lucide-react": "^0.546.0",
|
||||||
"phaser": "^4.2.1",
|
|
||||||
"react": "^19.0.0",
|
"react": "^19.0.0",
|
||||||
"react-arborist": "^3.16.0",
|
"react-arborist": "^3.16.0",
|
||||||
"react-colorful": "^5.8.0",
|
"react-colorful": "^5.8.0",
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ export const ungeneratedGameEntryMarker =
|
|||||||
'还没有生成游戏。回到聊天输入创意并确认生成后';
|
'还没有生成游戏。回到聊天输入创意并确认生成后';
|
||||||
export const defaultRealSwarmTestTask =
|
export const defaultRealSwarmTestTask =
|
||||||
'制作一个可直接试玩的原创植物塔防小游戏:玩家选择并放置原创守卫阻挡敌人,完成波次后可以进入下一关并重新开始。主题、单位名称与视觉语言必须原创,不使用任何现有游戏角色、单位名、Logo 或受保护视觉语言。请自主完成正式产物、静态检查和双视口试玩验证。';
|
'制作一个可直接试玩的原创植物塔防小游戏:玩家选择并放置原创守卫阻挡敌人,完成波次后可以进入下一关并重新开始。主题、单位名称与视觉语言必须原创,不使用任何现有游戏角色、单位名、Logo 或受保护视觉语言。请自主完成正式产物、静态检查和双视口试玩验证。';
|
||||||
|
export const defaultRealSwarmPlanTask =
|
||||||
|
'我想做一款原创横版像素解谜小游戏,主角是一个能操控自己影子的小机器人,影子可以变成平台和开关。请完成立项策划并给出 Fast GDD。主题、角色名与视觉语言必须原创,不使用任何现有游戏角色、名称、Logo 或受保护视觉语言。';
|
||||||
export const swarmTurnReportPrefix = '[turn.report] ';
|
export const swarmTurnReportPrefix = '[turn.report] ';
|
||||||
export const swarmTurnReportSchema = 'game-creator-swarm-turn-report.v1';
|
export const swarmTurnReportSchema = 'game-creator-swarm-turn-report.v1';
|
||||||
|
|
||||||
@@ -138,10 +140,15 @@ export const usage = `用法:
|
|||||||
--keep-project 保留自动创建的一次性项目
|
--keep-project 保留自动创建的一次性项目
|
||||||
--no-open 手工模式启动预览但不自动打开浏览器
|
--no-open 手工模式启动预览但不自动打开浏览器
|
||||||
--task <需求> 通过 manual 入口非交互提交自定义需求
|
--task <需求> 通过 manual 入口非交互提交自定义需求
|
||||||
--timeout-minutes <分钟> 设置本次执行期限;自动任务默认 50 分钟,手工模式默认不限时
|
--plan 走「做方案」立项策划入口,不做游戏,不做产物验收和试玩
|
||||||
|
--timeout-minutes <分钟> 设置本次执行期限;自动任务默认 50 分钟,--plan 默认 6 分钟,手工模式默认不限时
|
||||||
--dry-run 只检查目录发现和项目准备,不启动 LLM
|
--dry-run 只检查目录发现和项目准备,不启动 LLM
|
||||||
-h, --help 显示帮助
|
-h, --help 显示帮助
|
||||||
`;
|
|
||||||
|
环境变量:
|
||||||
|
AGC_PLAN_GDD_DECISION 审批卡自动应答动作,默认 approve;revise/reject 必须
|
||||||
|
同时用 AGC_PLAN_GDD_COMMENT 给出真实修改意见
|
||||||
|
AGC_PLAN_GDD_COMMENT revise/reject 的意见原文`;
|
||||||
|
|
||||||
function readOptionValue(args, index, option) {
|
function readOptionValue(args, index, option) {
|
||||||
const value = args[index + 1]?.trim();
|
const value = args[index + 1]?.trim();
|
||||||
@@ -170,6 +177,7 @@ export function parseSwarmTestArguments(args) {
|
|||||||
keepProject: false,
|
keepProject: false,
|
||||||
openBrowser: true,
|
openBrowser: true,
|
||||||
task: null,
|
task: null,
|
||||||
|
plan: false,
|
||||||
timeoutMinutes: null,
|
timeoutMinutes: null,
|
||||||
dryRun: false,
|
dryRun: false,
|
||||||
help: false,
|
help: false,
|
||||||
@@ -194,6 +202,8 @@ export function parseSwarmTestArguments(args) {
|
|||||||
if (task.length > 4_000) throw new Error('--task 不能超过 4000 字符');
|
if (task.length > 4_000) throw new Error('--task 不能超过 4000 字符');
|
||||||
options.task = task;
|
options.task = task;
|
||||||
index += 1;
|
index += 1;
|
||||||
|
} else if (argument === '--plan') {
|
||||||
|
options.plan = true;
|
||||||
} else if (argument === '--timeout-minutes') {
|
} else if (argument === '--timeout-minutes') {
|
||||||
if (options.timeoutMinutes !== null) {
|
if (options.timeoutMinutes !== null) {
|
||||||
throw new Error('--timeout-minutes 只能指定一次');
|
throw new Error('--timeout-minutes 只能指定一次');
|
||||||
@@ -212,11 +222,16 @@ export function parseSwarmTestArguments(args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function shouldStartPersistentPreview(options) {
|
export function shouldStartPersistentPreview(options) {
|
||||||
return !options.task;
|
// 立项策划链路只出 GDD,没有可试玩产物,任何模式都不该起预览。
|
||||||
|
return !options.task && !options.plan;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveSwarmTestTimeoutMs(options) {
|
export function resolveSwarmTestTimeoutMs(options) {
|
||||||
const minutes = options.timeoutMinutes ?? (options.task ? 50 : null);
|
// 立项策划的设计目标是五分钟出方案,给一分钟余量;再久就是卡住了,早失败
|
||||||
|
// 比让 harness 空等更有用。做游戏那条链路的 50 分钟不变。
|
||||||
|
const planMinutes = options.plan ? 6 : null;
|
||||||
|
const minutes =
|
||||||
|
options.timeoutMinutes ?? planMinutes ?? (options.task ? 50 : null);
|
||||||
return minutes === null ? null : minutes * 60_000;
|
return minutes === null ? null : minutes * 60_000;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -371,15 +386,7 @@ async function runMissingConfigWizard(setActiveChild, explicitConfigDir) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function secureWindowsPrivateRuntimePath(
|
async function secureWindowsPrivateRuntimePath(targetPath, options) {
|
||||||
targetPath,
|
|
||||||
options,
|
|
||||||
secureWindowsPath = null,
|
|
||||||
) {
|
|
||||||
if (secureWindowsPath) {
|
|
||||||
await secureWindowsPath(targetPath, options);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const { secureWindowsGameCreatorPathForCurrentUser } = await import(
|
const { secureWindowsGameCreatorPathForCurrentUser } = await import(
|
||||||
'./game-creator-config-wizard.mjs'
|
'./game-creator-config-wizard.mjs'
|
||||||
);
|
);
|
||||||
@@ -391,7 +398,6 @@ async function copyPrivateRuntimeConfigEntry(
|
|||||||
runtimeConfigDir,
|
runtimeConfigDir,
|
||||||
fileName,
|
fileName,
|
||||||
required,
|
required,
|
||||||
secureWindowsPath = null,
|
|
||||||
) {
|
) {
|
||||||
const sourcePath = path.join(sourceConfigDir, fileName);
|
const sourcePath = path.join(sourceConfigDir, fileName);
|
||||||
const sourceMetadata = await lstat(sourcePath).catch((error) => {
|
const sourceMetadata = await lstat(sourcePath).catch((error) => {
|
||||||
@@ -411,11 +417,9 @@ async function copyPrivateRuntimeConfigEntry(
|
|||||||
const sourceBytes = await readFile(sourcePath);
|
const sourceBytes = await readFile(sourcePath);
|
||||||
const destinationFile = await open(destinationPath, 'wx', 0o600);
|
const destinationFile = await open(destinationPath, 'wx', 0o600);
|
||||||
try {
|
try {
|
||||||
await secureWindowsPrivateRuntimePath(
|
await secureWindowsPrivateRuntimePath(destinationPath, {
|
||||||
destinationPath,
|
isDirectory: false,
|
||||||
{ isDirectory: false },
|
});
|
||||||
secureWindowsPath,
|
|
||||||
);
|
|
||||||
await destinationFile.writeFile(sourceBytes);
|
await destinationFile.writeFile(sourceBytes);
|
||||||
await destinationFile.sync();
|
await destinationFile.sync();
|
||||||
} finally {
|
} finally {
|
||||||
@@ -448,11 +452,7 @@ async function copyPrivateRuntimeConfigEntry(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function prepareSwarmTestRuntimeConfig(
|
export async function prepareSwarmTestRuntimeConfig(sourceConfigDir, tempRoot) {
|
||||||
sourceConfigDir,
|
|
||||||
tempRoot,
|
|
||||||
{ secureWindowsPath = null } = {},
|
|
||||||
) {
|
|
||||||
if (!path.isAbsolute(sourceConfigDir)) {
|
if (!path.isAbsolute(sourceConfigDir)) {
|
||||||
throw new Error('配置来源目录必须是绝对路径');
|
throw new Error('配置来源目录必须是绝对路径');
|
||||||
}
|
}
|
||||||
@@ -472,11 +472,9 @@ export async function prepareSwarmTestRuntimeConfig(
|
|||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
await secureWindowsPrivateRuntimePath(
|
await secureWindowsPrivateRuntimePath(runtimeConfigDir, {
|
||||||
runtimeConfigDir,
|
isDirectory: true,
|
||||||
{ isDirectory: true },
|
});
|
||||||
secureWindowsPath,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
await chmod(runtimeConfigDir, 0o700);
|
await chmod(runtimeConfigDir, 0o700);
|
||||||
}
|
}
|
||||||
@@ -494,14 +492,12 @@ export async function prepareSwarmTestRuntimeConfig(
|
|||||||
runtimeConfigDir,
|
runtimeConfigDir,
|
||||||
configFileName,
|
configFileName,
|
||||||
true,
|
true,
|
||||||
secureWindowsPath,
|
|
||||||
);
|
);
|
||||||
await copyPrivateRuntimeConfigEntry(
|
await copyPrivateRuntimeConfigEntry(
|
||||||
canonicalSourceConfigDir,
|
canonicalSourceConfigDir,
|
||||||
runtimeConfigDir,
|
runtimeConfigDir,
|
||||||
localConfigFileName,
|
localConfigFileName,
|
||||||
false,
|
false,
|
||||||
secureWindowsPath,
|
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
path: await realpath(runtimeConfigDir),
|
path: await realpath(runtimeConfigDir),
|
||||||
@@ -983,12 +979,25 @@ export function swarmAutoPilotShouldCloseInput(output, promptsAfterSubmit) {
|
|||||||
return swarmAutoPilotSitsAtPrompt(output) && promptsAfterSubmit >= 1;
|
return swarmAutoPilotSitsAtPrompt(output) && promptsAfterSubmit >= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GDD 审批位不能等 CLI 退出之后再处理:Run 停在这里时状态是 waiting-for-user-input,
|
||||||
|
// 而 swarm CLI 恰好把这个状态算作「本轮还在跑」,turn 永远不 settle,CLI 也就永远
|
||||||
|
// 不退出。所以审批必须在 CLI 还活着的时候并发做完,让 Run 自己继续跑到收束。
|
||||||
|
// 这一句是 PlanGddCompletionBlockerKind::AwaitingApprovalDecision 专有的投影文案,
|
||||||
|
// 另外三个 blocked 子状态都不会打出它;即便认错了,真正的判据也是随后那次
|
||||||
|
// --plan-gdd-status,没有待决定审批时不会有任何写入。
|
||||||
|
const planGddApprovalWaitPattern = /等待 Fast GDD 审批决定/u;
|
||||||
|
|
||||||
|
export function swarmOutputAwaitsPlanGddApproval(line) {
|
||||||
|
return planGddApprovalWaitPattern.test(line);
|
||||||
|
}
|
||||||
|
|
||||||
async function runTaskCargo(
|
async function runTaskCargo(
|
||||||
cliArguments,
|
cliArguments,
|
||||||
task,
|
task,
|
||||||
setActiveChild,
|
setActiveChild,
|
||||||
timeoutMs,
|
timeoutMs,
|
||||||
autoPilot = false,
|
autoPilot = false,
|
||||||
|
onPlanGddApprovalWait = null,
|
||||||
) {
|
) {
|
||||||
const child = spawnChild(cargoCommand, buildCargoCliArguments(cliArguments), {
|
const child = spawnChild(cargoCommand, buildCargoCliArguments(cliArguments), {
|
||||||
stdio: ['pipe', 'pipe', 'inherit'],
|
stdio: ['pipe', 'pipe', 'inherit'],
|
||||||
@@ -1000,6 +1009,25 @@ async function runTaskCargo(
|
|||||||
let taskSubmitted = false;
|
let taskSubmitted = false;
|
||||||
let promptsSeen = 0;
|
let promptsSeen = 0;
|
||||||
let sittingAtPrompt = false;
|
let sittingAtPrompt = false;
|
||||||
|
let planGddApproval = null;
|
||||||
|
let planGddApprovalError = null;
|
||||||
|
let planGddApprovalStarted = false;
|
||||||
|
let planGddApprovalPromise = null;
|
||||||
|
const startPlanGddApproval = () => {
|
||||||
|
planGddApprovalStarted = true;
|
||||||
|
console.log(
|
||||||
|
`[自动审批] 检测到 Fast GDD 审批位,正在提交 ${resolvePlanGddAutoDecision().action}`,
|
||||||
|
);
|
||||||
|
planGddApprovalPromise = onPlanGddApprovalWait()
|
||||||
|
.then((value) => {
|
||||||
|
planGddApproval = value;
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
planGddApprovalError = error;
|
||||||
|
// 审批没成的话 Run 会一直停在等待位,干等到超时只会把真正的原因埋掉。
|
||||||
|
void terminateChildTree(child).catch(() => {});
|
||||||
|
});
|
||||||
|
};
|
||||||
child.stdout.setEncoding('utf8');
|
child.stdout.setEncoding('utf8');
|
||||||
child.stdout.on('data', (chunk) => {
|
child.stdout.on('data', (chunk) => {
|
||||||
process.stdout.write(chunk);
|
process.stdout.write(chunk);
|
||||||
@@ -1012,6 +1040,13 @@ async function runTaskCargo(
|
|||||||
reportLines.push(normalizedLine);
|
reportLines.push(normalizedLine);
|
||||||
settled = true;
|
settled = true;
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
onPlanGddApprovalWait &&
|
||||||
|
!planGddApprovalStarted &&
|
||||||
|
swarmOutputAwaitsPlanGddApproval(normalizedLine)
|
||||||
|
) {
|
||||||
|
startPlanGddApproval();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!autoPilot || child.stdin.writableEnded) return;
|
if (!autoPilot || child.stdin.writableEnded) return;
|
||||||
const atPrompt = swarmAutoPilotSitsAtPrompt(pendingLine);
|
const atPrompt = swarmAutoPilotSitsAtPrompt(pendingLine);
|
||||||
@@ -1050,9 +1085,12 @@ async function runTaskCargo(
|
|||||||
if (normalizedPendingLine.startsWith(swarmTurnReportPrefix)) {
|
if (normalizedPendingLine.startsWith(swarmTurnReportPrefix)) {
|
||||||
reportLines.push(normalizedPendingLine);
|
reportLines.push(normalizedPendingLine);
|
||||||
}
|
}
|
||||||
|
await planGddApprovalPromise;
|
||||||
|
if (planGddApprovalError) throw planGddApprovalError;
|
||||||
return {
|
return {
|
||||||
...result,
|
...result,
|
||||||
turnReportOutput: reportLines.join('\n'),
|
turnReportOutput: reportLines.join('\n'),
|
||||||
|
planGddApproval,
|
||||||
};
|
};
|
||||||
} finally {
|
} finally {
|
||||||
setActiveChild(null);
|
setActiveChild(null);
|
||||||
@@ -1742,6 +1780,196 @@ export async function validateSwarmProjectArtifacts(projectPath, options) {
|
|||||||
return inspection;
|
return inspection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 这四条路径的权威定义都在 Rust 侧 `planning_storage.rs`(`PLAN_SESSION_PATH`、
|
||||||
|
// `PLAN_GDD_INDEX_PATH`、`PLAN_STORAGE_ROOT`、`PLAN_FAST_GDD_PATH`)。跨语言没有共享
|
||||||
|
// 常量的通道,改路径时要连同 `GddApprovalCard.tsx` 一起动。
|
||||||
|
export const planningOutputPaths = [
|
||||||
|
'.agent/planning/session.json',
|
||||||
|
'.agent/planning/index.json',
|
||||||
|
'.agent/planning/pending.json',
|
||||||
|
'game/fast_gdd.md',
|
||||||
|
];
|
||||||
|
|
||||||
|
export async function inspectPlanningOutputs(projectPath) {
|
||||||
|
const outputs = [];
|
||||||
|
for (const relativePath of planningOutputPaths) {
|
||||||
|
const absolutePath = path.join(projectPath, ...relativePath.split('/'));
|
||||||
|
const metadata = await lstat(absolutePath).catch((error) => {
|
||||||
|
if (error?.code === 'ENOENT') return null;
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
outputs.push({
|
||||||
|
path: relativePath,
|
||||||
|
exists: Boolean(metadata?.isFile()),
|
||||||
|
bytes: metadata?.isFile() ? metadata.size : 0,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return outputs;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function reportPlanningOutputs(projectPath) {
|
||||||
|
const outputs = await inspectPlanningOutputs(projectPath);
|
||||||
|
console.log('\n立项策划产物:');
|
||||||
|
for (const output of outputs) {
|
||||||
|
console.log(
|
||||||
|
output.exists
|
||||||
|
? ` [有] ${output.path}(${output.bytes} 字节)`
|
||||||
|
: ` [无] ${output.path}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const planGddApprovalTimeoutMs = 60_000;
|
||||||
|
export const planGddStatusOutputPrefix = 'planGddStateJson=';
|
||||||
|
export const planGddDecisionOutputPrefix = 'planGddDecisionJson=';
|
||||||
|
|
||||||
|
function parsePrefixedJsonLine(output, prefix, label) {
|
||||||
|
const line = output
|
||||||
|
.split('\n')
|
||||||
|
.map((value) => (value.endsWith('\r') ? value.slice(0, -1) : value))
|
||||||
|
.find((value) => value.startsWith(prefix));
|
||||||
|
if (!line) throw new Error(`${label}缺少 ${prefix} 输出`);
|
||||||
|
try {
|
||||||
|
return JSON.parse(line.slice(prefix.length));
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(`解析${label}失败:${error.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parsePlanGddStatusOutput(output) {
|
||||||
|
return parsePrefixedJsonLine(
|
||||||
|
output,
|
||||||
|
planGddStatusOutputPrefix,
|
||||||
|
'Fast GDD 审批状态',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parsePlanGddDecisionOutput(output) {
|
||||||
|
return parsePrefixedJsonLine(
|
||||||
|
output,
|
||||||
|
planGddDecisionOutputPrefix,
|
||||||
|
'Fast GDD 审批回执',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 审批卡是这条链路唯一的人类判据,所以自动应答默认只投 approve,且只在投影确实有
|
||||||
|
// 一张待决定审批时出手。revise/reject 需要一段真实的修改意见,让机器编一段等于把
|
||||||
|
// 判据换成噪声——所以那两条分支只在跑的人自己用 AGC_PLAN_GDD_COMMENT 给出意见时
|
||||||
|
// 才走。手工调 --plan-gdd-decide 也能达到同样效果,但那要求 plan 根 run 仍然活着,
|
||||||
|
// 而它恰好是本进程持有的 CLI 子进程。
|
||||||
|
export function planGddAutoApprovalIsPending(state) {
|
||||||
|
return Boolean(state?.pendingApproval);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolvePlanGddAutoDecision(env = process.env) {
|
||||||
|
const action = (env.AGC_PLAN_GDD_DECISION ?? 'approve').trim();
|
||||||
|
if (!['approve', 'revise', 'reject'].includes(action)) {
|
||||||
|
throw new Error('AGC_PLAN_GDD_DECISION 只能是 approve / revise / reject');
|
||||||
|
}
|
||||||
|
const comment = (env.AGC_PLAN_GDD_COMMENT ?? '').trim();
|
||||||
|
if (action === 'approve') return { action, comment: null };
|
||||||
|
if (!comment) {
|
||||||
|
throw new Error(
|
||||||
|
`${action} 必须同时设 AGC_PLAN_GDD_COMMENT 提供真实修改意见`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return { action, comment };
|
||||||
|
}
|
||||||
|
|
||||||
|
async function settlePlanGddApproval(
|
||||||
|
projectPath,
|
||||||
|
runtimeConfigPath,
|
||||||
|
setActiveChild,
|
||||||
|
) {
|
||||||
|
const readStatus = async () => {
|
||||||
|
const result = await runCapturedCargo(
|
||||||
|
['--config-dir', runtimeConfigPath, '--plan-gdd-status', projectPath],
|
||||||
|
setActiveChild,
|
||||||
|
{
|
||||||
|
timeoutMs: planGddApprovalTimeoutMs,
|
||||||
|
label: 'Fast GDD 审批状态查询',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (result.code !== 0 || result.signal) {
|
||||||
|
throw new Error(
|
||||||
|
`读取 Fast GDD 审批状态失败:${result.stderr.trim() || result.stdout.trim()}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return parsePlanGddStatusOutput(result.stdout);
|
||||||
|
};
|
||||||
|
|
||||||
|
const before = await readStatus();
|
||||||
|
if (!planGddAutoApprovalIsPending(before)) {
|
||||||
|
return { decided: false, state: before };
|
||||||
|
}
|
||||||
|
const { action, comment } = resolvePlanGddAutoDecision();
|
||||||
|
const decision = await runCapturedCargo(
|
||||||
|
[
|
||||||
|
'--config-dir',
|
||||||
|
runtimeConfigPath,
|
||||||
|
'--plan-gdd-decide',
|
||||||
|
projectPath,
|
||||||
|
action,
|
||||||
|
...(comment === null ? [] : ['--stdin']),
|
||||||
|
],
|
||||||
|
setActiveChild,
|
||||||
|
{
|
||||||
|
timeoutMs: planGddApprovalTimeoutMs,
|
||||||
|
label: 'Fast GDD 审批决定',
|
||||||
|
stdin: comment,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (decision.code !== 0 || decision.signal) {
|
||||||
|
throw new Error(
|
||||||
|
`提交 Fast GDD 审批决定失败:${decision.stderr.trim() || decision.stdout.trim()}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const receipt = parsePlanGddDecisionOutput(decision.stdout);
|
||||||
|
// 回执落盘和唤醒后台任务是两件事:decide 命令把唤醒失败降级成 recoveryPending,
|
||||||
|
// 于是审批已经生效、Run 却仍停在 waiting-for-user-input。实测就是这样——只有
|
||||||
|
// 补一次 --agent-resume 才会重新起 turn。这是仓库自己给这个状态定义的恢复动作。
|
||||||
|
let recovered = false;
|
||||||
|
if (receipt.recoveryPending) {
|
||||||
|
const resume = await runCapturedCargo(
|
||||||
|
['--config-dir', runtimeConfigPath, '--agent-resume', projectPath],
|
||||||
|
setActiveChild,
|
||||||
|
{
|
||||||
|
timeoutMs: planGddApprovalTimeoutMs,
|
||||||
|
label: 'Fast GDD 审批后恢复后台任务',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (resume.code !== 0 || resume.signal) {
|
||||||
|
throw new Error(
|
||||||
|
`审批已提交但恢复后台任务失败:${resume.stderr.trim() || resume.stdout.trim()}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
recovered = true;
|
||||||
|
}
|
||||||
|
return { decided: true, receipt, recovered, state: await readStatus() };
|
||||||
|
}
|
||||||
|
|
||||||
|
async function reportPlanGddApproval(approval) {
|
||||||
|
const { state } = approval;
|
||||||
|
console.log('\nFast GDD 审批:');
|
||||||
|
if (!approval.decided) {
|
||||||
|
console.log(` [无待决定审批] 当前投影状态=${state.state}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log(
|
||||||
|
` [已决定 ${approval.receipt.decisionRef.action}] outcome=${approval.receipt.outcome} v${approval.receipt.decisionRef.version} 投影状态=${state.state}`,
|
||||||
|
);
|
||||||
|
if (approval.recovered) {
|
||||||
|
console.log(
|
||||||
|
' [已恢复] 审批回执的 recoveryPending 由一次 --agent-resume 收口',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (state.session) {
|
||||||
|
console.log(
|
||||||
|
` 澄清轮次=${state.session.clarificationRound} 返工深度=${state.session.repairDepth} phase=${state.session.phase}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function hasConfiguredEditorApiKey(configDir) {
|
export async function hasConfiguredEditorApiKey(configDir) {
|
||||||
let configured = false;
|
let configured = false;
|
||||||
for (const fileName of [configFileName, localConfigFileName]) {
|
for (const fileName of [configFileName, localConfigFileName]) {
|
||||||
@@ -1894,7 +2122,13 @@ export async function runSwarmTestChat(options) {
|
|||||||
const setActiveChild = (child) => {
|
const setActiveChild = (child) => {
|
||||||
activeChild = child;
|
activeChild = child;
|
||||||
};
|
};
|
||||||
|
// GDD 审批要和 swarm CLI 并发跑,两者不能共用 activeChild 这一个槽位:审批子进程
|
||||||
|
// 结束时的 setActiveChild(null) 会把 CLI 从槽里抹掉,Ctrl-C 就杀不到它了。
|
||||||
const concurrentChildren = new Set();
|
const concurrentChildren = new Set();
|
||||||
|
const setConcurrentChild = (child) => {
|
||||||
|
if (child) concurrentChildren.add(child);
|
||||||
|
else concurrentChildren.clear();
|
||||||
|
};
|
||||||
const stopRequested = () => receivedSignal !== null;
|
const stopRequested = () => receivedSignal !== null;
|
||||||
const handleSignal = (signal) => {
|
const handleSignal = (signal) => {
|
||||||
const repeatedSignal = receivedSignal !== null;
|
const repeatedSignal = receivedSignal !== null;
|
||||||
@@ -1972,10 +2206,11 @@ export async function runSwarmTestChat(options) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
console.log('LLM 配置已就绪。');
|
console.log('LLM 配置已就绪。');
|
||||||
|
const requirementNoun = options.plan ? '立项策划需求' : '游戏需求';
|
||||||
console.log(
|
console.log(
|
||||||
options.task
|
options.task
|
||||||
? '已提交一条非交互游戏需求,正在等待 Swarm 自主完成。\n'
|
? `已提交一条非交互${requirementNoun},正在等待 Swarm 自主完成。\n`
|
||||||
: '输入一条游戏需求并回车;提交后按 Ctrl+D,让 Swarm 自主完成。\n',
|
: `输入一条${requirementNoun}并回车;提交后按 Ctrl+D,让 Swarm 自主完成。\n`,
|
||||||
);
|
);
|
||||||
|
|
||||||
phase = 'chat';
|
phase = 'chat';
|
||||||
@@ -1985,7 +2220,8 @@ export async function runSwarmTestChat(options) {
|
|||||||
runtimeConfig.path,
|
runtimeConfig.path,
|
||||||
'--swarm-chat',
|
'--swarm-chat',
|
||||||
'--init',
|
'--init',
|
||||||
'--autonomous-game-build',
|
// 做方案链路只能跑 standard 档,后端对 plan + autonomous 是硬否决。
|
||||||
|
options.plan ? '--plan' : '--autonomous-game-build',
|
||||||
project.path,
|
project.path,
|
||||||
];
|
];
|
||||||
let chat;
|
let chat;
|
||||||
@@ -1998,6 +2234,15 @@ export async function runSwarmTestChat(options) {
|
|||||||
timeoutDeadline === null
|
timeoutDeadline === null
|
||||||
? null
|
? null
|
||||||
: Math.max(1, timeoutDeadline - Date.now()),
|
: Math.max(1, timeoutDeadline - Date.now()),
|
||||||
|
options.plan,
|
||||||
|
options.plan
|
||||||
|
? () =>
|
||||||
|
settlePlanGddApproval(
|
||||||
|
project.path,
|
||||||
|
runtimeConfig.path,
|
||||||
|
setConcurrentChild,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
)
|
)
|
||||||
: await runInteractiveCargo(chatArguments, setActiveChild);
|
: await runInteractiveCargo(chatArguments, setActiveChild);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -2013,6 +2258,32 @@ export async function runSwarmTestChat(options) {
|
|||||||
if (options.task) {
|
if (options.task) {
|
||||||
turnReport = parseSettledSwarmTurnReport(chat.turnReportOutput);
|
turnReport = parseSettledSwarmTurnReport(chat.turnReportOutput);
|
||||||
}
|
}
|
||||||
|
if (options.plan) {
|
||||||
|
// 立项策划不出游戏产物,正式验收在 GDD 审批卡上;这里只报告落盘情况,
|
||||||
|
// 是否收束已经由 CLI 的退出码判过了。
|
||||||
|
// 自动任务档的审批已经在 CLI 运行期间并发做完了;手工档(人自己敲 Ctrl+D
|
||||||
|
// 退出)没有那次触发,退出后补一次,没有待决定审批时它是只读的。
|
||||||
|
phase = 'plan-approval';
|
||||||
|
const approval =
|
||||||
|
chat.planGddApproval ??
|
||||||
|
(await settlePlanGddApproval(
|
||||||
|
project.path,
|
||||||
|
runtimeConfig.path,
|
||||||
|
setConcurrentChild,
|
||||||
|
));
|
||||||
|
if (receivedSignal) break session;
|
||||||
|
phase = 'plan-report';
|
||||||
|
await reportPlanGddApproval(approval);
|
||||||
|
await reportPlanningOutputs(project.path);
|
||||||
|
phase = 'complete';
|
||||||
|
console.log(
|
||||||
|
approval.decided
|
||||||
|
? '\n立项策划链路已收束:Fast GDD 已批准,策划产物见上方清单。'
|
||||||
|
: '\n立项策划链路已收束:Run 正常结束但没有待决定审批,策划产物见上方清单。',
|
||||||
|
);
|
||||||
|
break session;
|
||||||
|
}
|
||||||
|
phase = 'artifact-validation';
|
||||||
const requireEditorImages = await hasConfiguredEditorApiKey(
|
const requireEditorImages = await hasConfiguredEditorApiKey(
|
||||||
runtimeConfig.path,
|
runtimeConfig.path,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -4,12 +4,8 @@ import fs from 'node:fs';
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
import {
|
|
||||||
defaultEditorFeatures,
|
|
||||||
withDefaultCargoFeatures,
|
|
||||||
} from './cargo-features.mjs';
|
|
||||||
|
|
||||||
const appRoot = fileURLToPath(new URL('..', import.meta.url));
|
const appRoot = fileURLToPath(new URL('..', import.meta.url));
|
||||||
|
const repoRoot = path.resolve(appRoot, '../..');
|
||||||
const defaultReleaseTarget = 'x86_64-pc-windows-msvc';
|
const defaultReleaseTarget = 'x86_64-pc-windows-msvc';
|
||||||
const releaseTarget =
|
const releaseTarget =
|
||||||
process.env.AGC_BUILD_TARGET?.trim() || defaultReleaseTarget;
|
process.env.AGC_BUILD_TARGET?.trim() || defaultReleaseTarget;
|
||||||
@@ -54,16 +50,23 @@ function parseVersion(value, label) {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function nextPatchVersion(localVersion, remoteVersion) {
|
export function bumpVersion(current, target = 'patch') {
|
||||||
const local = parseVersion(localVersion, '本地版本');
|
const [major, minor, patch] =
|
||||||
const remote =
|
parseVersion(current, '当前版本').split('.').map(Number);
|
||||||
remoteVersion == null ? null : parseVersion(remoteVersion, 'OSS版本');
|
if (target === 'major') return `${major + 1}.0.0`;
|
||||||
const base = remote && compareVersions(remote, local) > 0 ? remote : local;
|
if (target === 'minor') return `${major}.${minor + 1}.0`;
|
||||||
const [major, minor, patch] = base.split('.').map(Number);
|
if (target === 'patch' || target == null) {
|
||||||
if (patch === Number.MAX_SAFE_INTEGER) {
|
if (patch === Number.MAX_SAFE_INTEGER) {
|
||||||
throw new Error(`版本号 patch 已达到上限:${base}`);
|
throw new Error(`版本号 patch 已达到上限:${current}`);
|
||||||
|
}
|
||||||
|
return `${major}.${minor}.${patch + 1}`;
|
||||||
}
|
}
|
||||||
return `${major}.${minor}.${patch + 1}`;
|
if (typeof target === 'string' && /^\d+\.\d+\.\d+$/u.test(target)) {
|
||||||
|
return parseVersion(target, '指定版本');
|
||||||
|
}
|
||||||
|
throw new Error(
|
||||||
|
`无法识别的版本目标:${String(target)}(支持 patch / minor / major / 明确的三段版本号)`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function readRemoteVersion() {
|
async function readRemoteVersion() {
|
||||||
@@ -93,14 +96,52 @@ function replaceVersionLine(source, version, pattern, label) {
|
|||||||
return source.replace(pattern, `$1${version}$3`);
|
return source.replace(pattern, `$1${version}$3`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function prepareReleaseVersion() {
|
const versionFileSources = [
|
||||||
const localVersion = parseVersion(readPackageJson().version, '本地版本');
|
{
|
||||||
const remoteVersion = await readRemoteVersion();
|
file: packageJsonPath,
|
||||||
const requestedVersion = process.env.AGC_RELEASE_VERSION?.trim();
|
pattern: /("version"\s*:\s*")([^"]+)(")/u,
|
||||||
const nextVersion = requestedVersion
|
label: 'package.json',
|
||||||
? parseVersion(requestedVersion, '指定版本')
|
},
|
||||||
: nextPatchVersion(localVersion, remoteVersion);
|
{
|
||||||
|
file: rootPackageLockPath,
|
||||||
|
pattern: /("apps\/ai-game-creator-shell"\s*:\s*\{\s*\n\s*"name"\s*:\s*"@genarrative\/ai-game-creator-shell"\s*,\s*\n\s*"version"\s*:\s*")([^"]+)(")/u,
|
||||||
|
label: 'package-lock.json',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
file: tauriConfigPath,
|
||||||
|
pattern: /("version"\s*:\s*")([^"]+)(")/u,
|
||||||
|
label: 'tauri.conf.json',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
file: cargoManifestPath,
|
||||||
|
pattern: /(^\[package\][\s\S]*?^version\s*=\s*")([^"]+)(")/mu,
|
||||||
|
label: 'Cargo.toml',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
file: cargoLockPath,
|
||||||
|
pattern: /(^name\s*=\s*"genarrative-ai-game-creator-shell"\s*\nversion\s*=\s*")([^"]+)(")/mu,
|
||||||
|
label: 'Cargo.lock',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export function readLocalVersion() {
|
||||||
|
return parseVersion(readPackageJson().version, '本地版本');
|
||||||
|
}
|
||||||
|
|
||||||
|
export function validateVersionConsistency(expectedVersion) {
|
||||||
|
for (const source of versionFileSources) {
|
||||||
|
const match = fs.readFileSync(source.file, 'utf8').match(source.pattern);
|
||||||
|
const actual = match ? match[2].trim() : '<未找到>';
|
||||||
|
if (actual !== expectedVersion) {
|
||||||
|
throw new Error(
|
||||||
|
`AGC 版本号不一致:${source.label} 应为 ${expectedVersion},实际 ${actual}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function writeVersionFiles(version) {
|
||||||
|
const nextVersion = parseVersion(version, '目标版本');
|
||||||
const packageSource = fs.readFileSync(packageJsonPath, 'utf8');
|
const packageSource = fs.readFileSync(packageJsonPath, 'utf8');
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
packageJsonPath,
|
packageJsonPath,
|
||||||
@@ -156,38 +197,51 @@ export async function prepareReleaseVersion() {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(
|
|
||||||
requestedVersion
|
|
||||||
? `[ai-game-creator-shell] 使用指定版本 ${nextVersion}(本地 ${localVersion} / OSS ${remoteVersion ?? '不存在'})`
|
|
||||||
: `[ai-game-creator-shell] 版本 ${localVersion} / OSS ${remoteVersion ?? '不存在'} -> ${nextVersion}`,
|
|
||||||
);
|
|
||||||
return nextVersion;
|
return nextVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildTauriBuildArguments(
|
export function assertVersionCommitted() {
|
||||||
args = [],
|
const repoPaths = versionFileSources.map((source) =>
|
||||||
target = releaseTarget,
|
path.relative(repoRoot, source.file).replaceAll('\\', '/'),
|
||||||
platform = process.platform,
|
);
|
||||||
) {
|
const changed =
|
||||||
const noBundle = args.includes('--no-bundle');
|
spawnSync(
|
||||||
const targetIndex = args.indexOf('--target');
|
'git',
|
||||||
const explicitTarget =
|
['diff', '--quiet', 'HEAD', '--', ...repoPaths],
|
||||||
targetIndex >= 0
|
{ cwd: repoRoot },
|
||||||
? args[targetIndex + 1]
|
).status === 1;
|
||||||
: args
|
if (changed) {
|
||||||
.find((value) => value.startsWith('--target='))
|
throw new Error(
|
||||||
?.slice('--target='.length);
|
'版本文件相对 HEAD 存在未提交改动,请先提交后再发布:运行 npm --prefix apps/ai-game-creator-shell run bump-version -- --commit',
|
||||||
const targetArgs = noBundle || explicitTarget ? [] : ['--target', target];
|
);
|
||||||
const features = defaultEditorFeatures(
|
}
|
||||||
explicitTarget || (noBundle ? platform : target),
|
}
|
||||||
|
|
||||||
|
export function prepareReleaseVersion() {
|
||||||
|
const localVersion = readLocalVersion();
|
||||||
|
validateVersionConsistency(localVersion);
|
||||||
|
console.log(
|
||||||
|
`[ai-game-creator-shell] 使用仓库版本 ${localVersion}(不再自动递增或自由指定版本)`,
|
||||||
|
);
|
||||||
|
return localVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function assertVersionNotBelowOss(version) {
|
||||||
|
const remoteVersion = await readRemoteVersion();
|
||||||
|
if (remoteVersion && compareVersions(version, remoteVersion) < 0) {
|
||||||
|
throw new Error(
|
||||||
|
`仓库版本 ${version} 低于线上 OSS 版本 ${remoteVersion}。请先运行 npm --prefix apps/ai-game-creator-shell run bump-version 提升版本后再发布。`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
console.log(
|
||||||
|
`[ai-game-creator-shell] 线上 OSS 版本 ${remoteVersion ?? '不存在'},发布版本 ${version}`,
|
||||||
);
|
);
|
||||||
return [
|
|
||||||
'build',
|
|
||||||
...withDefaultCargoFeatures([...targetArgs, ...args], features),
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function runTauriBuild(args = []) {
|
export function runTauriBuild(args = []) {
|
||||||
|
const noBundle = args.includes('--no-bundle');
|
||||||
|
const hasTarget = args.includes('--target');
|
||||||
|
const targetArgs = noBundle || hasTarget ? [] : ['--target', releaseTarget];
|
||||||
const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
||||||
const result = spawnSync(
|
const result = spawnSync(
|
||||||
npmCommand,
|
npmCommand,
|
||||||
@@ -197,7 +251,9 @@ export function runTauriBuild(args = []) {
|
|||||||
'exec',
|
'exec',
|
||||||
'tauri',
|
'tauri',
|
||||||
'--',
|
'--',
|
||||||
...buildTauriBuildArguments(args),
|
'build',
|
||||||
|
...targetArgs,
|
||||||
|
...args,
|
||||||
],
|
],
|
||||||
{ cwd: appRoot, stdio: 'inherit', shell: process.platform === 'win32' },
|
{ cwd: appRoot, stdio: 'inherit', shell: process.platform === 'win32' },
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
import assert from 'node:assert/strict';
|
import assert from 'node:assert/strict';
|
||||||
import { readFileSync } from 'node:fs';
|
import { readFileSync } from 'node:fs';
|
||||||
import { test } from 'node:test';
|
import { test } from 'node:test';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
bumpVersion,
|
||||||
compareVersions,
|
compareVersions,
|
||||||
createUpdateManifest,
|
createUpdateManifest,
|
||||||
nextPatchVersion,
|
|
||||||
selectReleaseArtifact,
|
selectReleaseArtifact,
|
||||||
} from './build-release.mjs';
|
} from './build-release.mjs';
|
||||||
|
|
||||||
test('selects an explicit release artifact when configured', () => {
|
test('selects an explicit release artifact when configured', () => {
|
||||||
const artifactPath = new URL('../package.json', import.meta.url).pathname;
|
const artifactPath = fileURLToPath(
|
||||||
|
new URL('../package.json', import.meta.url),
|
||||||
|
);
|
||||||
const previous = process.env.AGC_UPDATE_ARTIFACT;
|
const previous = process.env.AGC_UPDATE_ARTIFACT;
|
||||||
process.env.AGC_UPDATE_ARTIFACT = artifactPath;
|
process.env.AGC_UPDATE_ARTIFACT = artifactPath;
|
||||||
try {
|
try {
|
||||||
@@ -30,7 +33,7 @@ test('does not select unsupported files', () => {
|
|||||||
|
|
||||||
test('manifest contains version, download URL and integrity fields', () => {
|
test('manifest contains version, download URL and integrity fields', () => {
|
||||||
const manifest = createUpdateManifest(
|
const manifest = createUpdateManifest(
|
||||||
new URL('../package.json', import.meta.url).pathname,
|
fileURLToPath(new URL('../package.json', import.meta.url)),
|
||||||
);
|
);
|
||||||
assert.match(manifest.version, /^\d+\.\d+\.\d+$/u);
|
assert.match(manifest.version, /^\d+\.\d+\.\d+$/u);
|
||||||
assert.match(
|
assert.match(
|
||||||
@@ -46,7 +49,7 @@ test('manifest preserves multiline release notes', () => {
|
|||||||
process.env.AGC_UPDATE_RELEASE_NOTES = '第一行\n第二行\r\n第三行';
|
process.env.AGC_UPDATE_RELEASE_NOTES = '第一行\n第二行\r\n第三行';
|
||||||
try {
|
try {
|
||||||
const manifest = createUpdateManifest(
|
const manifest = createUpdateManifest(
|
||||||
new URL('../package.json', import.meta.url).pathname,
|
fileURLToPath(new URL('../package.json', import.meta.url)),
|
||||||
);
|
);
|
||||||
assert.equal(manifest.releaseNotes, '第一行\n第二行\r\n第三行');
|
assert.equal(manifest.releaseNotes, '第一行\n第二行\r\n第三行');
|
||||||
} finally {
|
} finally {
|
||||||
@@ -55,11 +58,14 @@ test('manifest preserves multiline release notes', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('next release version follows the higher local or OSS version', () => {
|
test('bump version follows the requested target', () => {
|
||||||
assert.equal(compareVersions('0.1.15', '0.1.12'), 1);
|
assert.equal(compareVersions('0.1.15', '0.1.12'), 1);
|
||||||
assert.equal(nextPatchVersion('0.1.12', '0.1.15'), '0.1.16');
|
assert.equal(compareVersions('0.1.12', '0.1.12'), 0);
|
||||||
assert.equal(nextPatchVersion('0.1.18', '0.1.15'), '0.1.19');
|
assert.equal(bumpVersion('0.1.19', 'patch'), '0.1.20');
|
||||||
assert.equal(nextPatchVersion('0.1.12', null), '0.1.13');
|
assert.equal(bumpVersion('0.1.19'), '0.1.20');
|
||||||
|
assert.equal(bumpVersion('0.1.19', 'minor'), '0.2.0');
|
||||||
|
assert.equal(bumpVersion('0.1.19', 'major'), '1.0.0');
|
||||||
|
assert.equal(bumpVersion('0.1.12', '0.1.25'), '0.1.25');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('release upload forces overwrite for versioned artifact and latest pointer', () => {
|
test('release upload forces overwrite for versioned artifact and latest pointer', () => {
|
||||||
@@ -72,3 +78,12 @@ test('release upload forces overwrite for versioned artifact and latest pointer'
|
|||||||
2,
|
2,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('release upload verifies the version is committed and not below OSS', () => {
|
||||||
|
const source = readFileSync(
|
||||||
|
new URL('./release-upload.mjs', import.meta.url),
|
||||||
|
'utf8',
|
||||||
|
);
|
||||||
|
assert.match(source, /assertVersionCommitted\(\)/u);
|
||||||
|
assert.match(source, /assertVersionNotBelowOss\(/u);
|
||||||
|
});
|
||||||
|
|||||||
@@ -0,0 +1,121 @@
|
|||||||
|
import { spawnSync } from 'node:child_process';
|
||||||
|
import path from 'node:path';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
|
const appRoot = fileURLToPath(new URL('..', import.meta.url));
|
||||||
|
const repoRoot = path.resolve(appRoot, '../..');
|
||||||
|
|
||||||
|
const {
|
||||||
|
bumpVersion,
|
||||||
|
readLocalVersion,
|
||||||
|
writeVersionFiles,
|
||||||
|
} = await import('./build-release.mjs');
|
||||||
|
|
||||||
|
const versionFiles = [
|
||||||
|
'apps/ai-game-creator-shell/package.json',
|
||||||
|
'package-lock.json',
|
||||||
|
'apps/ai-game-creator-shell/src-tauri/tauri.conf.json',
|
||||||
|
'apps/ai-game-creator-shell/src-tauri/Cargo.toml',
|
||||||
|
'apps/ai-game-creator-shell/src-tauri/Cargo.lock',
|
||||||
|
];
|
||||||
|
|
||||||
|
function parseArgs(argv) {
|
||||||
|
const args = argv.slice(2);
|
||||||
|
const explicitIndex = args.indexOf('--version');
|
||||||
|
const explicit = explicitIndex >= 0 ? args[explicitIndex + 1] : null;
|
||||||
|
const target =
|
||||||
|
explicit ??
|
||||||
|
args.find((arg) => arg === 'patch' || arg === 'minor' || arg === 'major') ??
|
||||||
|
'patch';
|
||||||
|
return { target, commit: args.includes('--commit') };
|
||||||
|
}
|
||||||
|
|
||||||
|
function runGit(args) {
|
||||||
|
const result = spawnSync('git', args, { cwd: repoRoot, stdio: 'inherit' });
|
||||||
|
if (result.error) throw result.error;
|
||||||
|
return result.status ?? 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasUncommittedVersionChanges() {
|
||||||
|
return (
|
||||||
|
spawnSync('git', ['diff', '--quiet', '--', ...versionFiles], {
|
||||||
|
cwd: repoRoot,
|
||||||
|
}).status === 1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function otherStagedFiles() {
|
||||||
|
const result = spawnSync(
|
||||||
|
'git',
|
||||||
|
['diff', '--cached', '--name-only'],
|
||||||
|
{ cwd: repoRoot, encoding: 'utf8' },
|
||||||
|
);
|
||||||
|
if (result.status !== 0) {
|
||||||
|
throw new Error('无法读取已暂存文件列表');
|
||||||
|
}
|
||||||
|
const versionSet = new Set(versionFiles);
|
||||||
|
return result.stdout
|
||||||
|
.split('\n')
|
||||||
|
.map((file) => file.trim())
|
||||||
|
.filter(Boolean)
|
||||||
|
.filter((file) => !versionSet.has(file));
|
||||||
|
}
|
||||||
|
|
||||||
|
const { target, commit } = parseArgs(process.argv);
|
||||||
|
|
||||||
|
// 提交前先确认没有其他已暂存改动,避免把无关改动一并提交;若存在则在改动任何文件前中止。
|
||||||
|
if (commit) {
|
||||||
|
const others = otherStagedFiles();
|
||||||
|
if (others.length > 0) {
|
||||||
|
console.error(
|
||||||
|
`[bump-version] 检测到其他已暂存改动,为避免误提交,请先单独处理后再运行 --commit:\n ${others.join('\n ')}`,
|
||||||
|
);
|
||||||
|
console.error(
|
||||||
|
'提示:用 git restore --staged <file> 取消暂存,或先提交这些改动。',
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const current = readLocalVersion();
|
||||||
|
|
||||||
|
// 若版本文件已带着一次未提交的提升(例如先默认跑过一次),再 --commit 时不再重复递增,直接提交现有改动。
|
||||||
|
const next =
|
||||||
|
commit && hasUncommittedVersionChanges()
|
||||||
|
? current
|
||||||
|
: bumpVersion(current, target);
|
||||||
|
|
||||||
|
writeVersionFiles(next);
|
||||||
|
|
||||||
|
if (!commit) {
|
||||||
|
console.log(
|
||||||
|
`[bump-version] 版本 ${current} -> ${next}(已写入版本文件,未创建提交;如需提交加 --commit)`,
|
||||||
|
);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
const addStatus = runGit(['add', ...versionFiles]);
|
||||||
|
if (addStatus !== 0) process.exit(addStatus);
|
||||||
|
|
||||||
|
const hasDiff =
|
||||||
|
spawnSync('git', ['diff', '--cached', '--quiet'], {
|
||||||
|
cwd: repoRoot,
|
||||||
|
}).status === 1;
|
||||||
|
|
||||||
|
if (!hasDiff) {
|
||||||
|
console.log(`[bump-version] 版本未变化(已是 ${current}),未创建提交`);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
const commitStatus = runGit([
|
||||||
|
'commit',
|
||||||
|
'-m',
|
||||||
|
`提升 AGC 版本至 ${next}`,
|
||||||
|
'-m',
|
||||||
|
`- AGC 客户端版本提升至 ${next}`,
|
||||||
|
'-m',
|
||||||
|
'- 同步更新 package.json、根 package-lock.json、tauri.conf.json、Cargo.toml、Cargo.lock 中的 AGC 包条目',
|
||||||
|
]);
|
||||||
|
if (commitStatus !== 0) process.exit(commitStatus);
|
||||||
|
|
||||||
|
console.log(`[bump-version] 已提交版本 ${next}(本地提交,未推送)`);
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
/** 默认桌面能力;显式 feature 参数优先,不把应用参数当 Cargo 参数。 */
|
|
||||||
export function withDefaultCargoFeatures(argv, features) {
|
|
||||||
const separator = argv.indexOf('--');
|
|
||||||
const cargoArgs = separator < 0 ? argv : argv.slice(0, separator);
|
|
||||||
if (
|
|
||||||
!features.length ||
|
|
||||||
cargoArgs.some(
|
|
||||||
(value) =>
|
|
||||||
value === '--features' ||
|
|
||||||
value === '-f' ||
|
|
||||||
value.startsWith('--features=') ||
|
|
||||||
/^-f.+/u.test(value),
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
return argv;
|
|
||||||
}
|
|
||||||
return [`--features=${features.join(',')}`, ...argv];
|
|
||||||
}
|
|
||||||
|
|
||||||
export function defaultEditorFeatures(target) {
|
|
||||||
return target === 'win32' || target.includes('windows')
|
|
||||||
? ['cocos-editor-execute']
|
|
||||||
: [];
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
import assert from 'node:assert/strict';
|
|
||||||
import { test } from 'node:test';
|
|
||||||
|
|
||||||
import { buildTauriBuildArguments } from './build-release.mjs';
|
|
||||||
import { withDefaultCargoFeatures } from './cargo-features.mjs';
|
|
||||||
|
|
||||||
test('Windows release includes the same editor feature as development', () => {
|
|
||||||
assert.deepEqual(
|
|
||||||
buildTauriBuildArguments([], 'x86_64-pc-windows-msvc', 'win32'),
|
|
||||||
[
|
|
||||||
'build',
|
|
||||||
'--features=cocos-editor-execute',
|
|
||||||
'--target',
|
|
||||||
'x86_64-pc-windows-msvc',
|
|
||||||
],
|
|
||||||
);
|
|
||||||
assert.deepEqual(
|
|
||||||
buildTauriBuildArguments(
|
|
||||||
['--no-bundle'],
|
|
||||||
'x86_64-pc-windows-msvc',
|
|
||||||
'linux',
|
|
||||||
),
|
|
||||||
['build', '--no-bundle'],
|
|
||||||
);
|
|
||||||
assert.deepEqual(
|
|
||||||
buildTauriBuildArguments(['--target=aarch64-apple-darwin']),
|
|
||||||
['build', '--target=aarch64-apple-darwin'],
|
|
||||||
);
|
|
||||||
});
|
|
||||||
test('explicit Cargo features override defaults in every supported spelling', () => {
|
|
||||||
for (const args of [
|
|
||||||
['--features', 'custom'],
|
|
||||||
['--features=custom'],
|
|
||||||
['-f', 'custom'],
|
|
||||||
['-fcustom'],
|
|
||||||
]) {
|
|
||||||
assert.deepEqual(
|
|
||||||
withDefaultCargoFeatures(args, ['cocos-editor-execute']),
|
|
||||||
args,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
assert.deepEqual(
|
|
||||||
withDefaultCargoFeatures(
|
|
||||||
['--', '--features=app'],
|
|
||||||
['cocos-editor-execute'],
|
|
||||||
),
|
|
||||||
['--features=cocos-editor-execute', '--', '--features=app'],
|
|
||||||
);
|
|
||||||
});
|
|
||||||
@@ -107,29 +107,12 @@ const rustSharedContractSource = fs.readFileSync(
|
|||||||
'utf8',
|
'utf8',
|
||||||
);
|
);
|
||||||
const allowedUncalledTauriCommands = [
|
const allowedUncalledTauriCommands = [
|
||||||
'append_direct_project_conversation_message',
|
|
||||||
// TODO: Remove the retired binding command after the legacy runtime path is removed.
|
|
||||||
'bind_components',
|
|
||||||
'chat_with_game_creator_agent',
|
'chat_with_game_creator_agent',
|
||||||
'check_ui_editor_font_glyph_coverage',
|
'check_ui_editor_font_glyph_coverage',
|
||||||
'create_ui_design_resource',
|
'create_ui_design_resource',
|
||||||
'open_game_creator_launcher_window',
|
'open_game_creator_launcher_window',
|
||||||
'open_game_creator_workspace_window',
|
'open_game_creator_workspace_window',
|
||||||
'read_direct_project_conversation',
|
|
||||||
'reset_design_agent_session',
|
|
||||||
'stop_local_game_preview_if_matches',
|
'stop_local_game_preview_if_matches',
|
||||||
'start_game_creator_external_mcp',
|
|
||||||
'stop_game_creator_external_mcp',
|
|
||||||
'list_agc_plugins',
|
|
||||||
'list_agc_extensions',
|
|
||||||
'refresh_agc_plugins',
|
|
||||||
'start_agc_plugin',
|
|
||||||
'stop_agc_plugin',
|
|
||||||
'reload_agc_plugin',
|
|
||||||
'call_agc_plugin',
|
|
||||||
'read_agc_plugin_panel',
|
|
||||||
'set_agc_plugin_project_path',
|
|
||||||
'set_agc_plugin_enabled',
|
|
||||||
];
|
];
|
||||||
const sourceExtensions = new Set([
|
const sourceExtensions = new Set([
|
||||||
'.json',
|
'.json',
|
||||||
@@ -1298,10 +1281,7 @@ if (tauriConfig.identifier !== 'world.genarrative.ai-game-creator') {
|
|||||||
throw new Error('AI game creator shell identifier drifted');
|
throw new Error('AI game creator shell identifier drifted');
|
||||||
}
|
}
|
||||||
|
|
||||||
const expectedBundledDesignAgentResources = {
|
const expectedBundledCodexResources = {
|
||||||
'design-agent': 'design-agent',
|
|
||||||
};
|
|
||||||
const expectedBundledWindowsResources = {
|
|
||||||
'resources/codex/win-x64/bin/codex.exe': 'codex/win-x64/bin/codex.exe',
|
'resources/codex/win-x64/bin/codex.exe': 'codex/win-x64/bin/codex.exe',
|
||||||
'resources/codex/win-x64/bin/codex-code-mode-host.exe':
|
'resources/codex/win-x64/bin/codex-code-mode-host.exe':
|
||||||
'codex/win-x64/bin/codex-code-mode-host.exe',
|
'codex/win-x64/bin/codex-code-mode-host.exe',
|
||||||
@@ -1315,35 +1295,17 @@ const expectedBundledWindowsResources = {
|
|||||||
'codex/win-x64/codex-package.json',
|
'codex/win-x64/codex-package.json',
|
||||||
'resources/codex/win-x64/NOTICE.md': 'codex/win-x64/NOTICE.md',
|
'resources/codex/win-x64/NOTICE.md': 'codex/win-x64/NOTICE.md',
|
||||||
'resources/codex/win-x64/manifest.json': 'codex/win-x64/manifest.json',
|
'resources/codex/win-x64/manifest.json': 'codex/win-x64/manifest.json',
|
||||||
'resources/plugins': 'plugins',
|
|
||||||
};
|
};
|
||||||
assert.deepEqual(
|
if (tauriConfig.bundle?.resources !== undefined) {
|
||||||
tauriConfig.bundle?.resources,
|
throw new Error(
|
||||||
expectedBundledDesignAgentResources,
|
'AI game creator shell base Tauri config must not require Windows-only Codex resources',
|
||||||
'AI game creator shell base Tauri config must bundle the design-agent resource pack',
|
);
|
||||||
);
|
|
||||||
for (const key of Object.keys(tauriConfig.bundle?.resources ?? {})) {
|
|
||||||
if (String(key).includes('codex')) {
|
|
||||||
throw new Error(
|
|
||||||
'AI game creator shell base Tauri config must not require Windows-only Codex resources',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
windowsTauriConfig.bundle?.resources,
|
windowsTauriConfig.bundle?.resources,
|
||||||
expectedBundledWindowsResources,
|
expectedBundledCodexResources,
|
||||||
'AI game creator shell Windows Tauri config must bundle the complete pinned Codex resource set and Cocos bridge payload directory',
|
'AI game creator shell Windows Tauri config must bundle the complete pinned Codex resource set',
|
||||||
);
|
);
|
||||||
if (
|
|
||||||
Object.prototype.hasOwnProperty.call(
|
|
||||||
windowsTauriConfig.bundle?.resources ?? {},
|
|
||||||
'design-agent',
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
throw new Error(
|
|
||||||
'design-agent resource pack must not be mixed into the Windows Codex sidecar bundle',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (windowsTauriConfig.bundle?.useLocalToolsDir !== true) {
|
if (windowsTauriConfig.bundle?.useLocalToolsDir !== true) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'AI game creator shell Windows Tauri config must cache bundling tools in the project target directory',
|
'AI game creator shell Windows Tauri config must cache bundling tools in the project target directory',
|
||||||
@@ -1739,16 +1701,10 @@ if (
|
|||||||
runtimeConfigSetupStart === -1 ||
|
runtimeConfigSetupStart === -1 ||
|
||||||
runtimeConfigSetupEnd === -1 ||
|
runtimeConfigSetupEnd === -1 ||
|
||||||
!runtimeConfigSetupSource.includes('sanitize_diagnostic_message(') ||
|
!runtimeConfigSetupSource.includes('sanitize_diagnostic_message(') ||
|
||||||
!runtimeConfigSetupSource.includes('setup_log.fail(') ||
|
!runtimeConfigSetupSource.includes('append_bounded_diagnostic_line(') ||
|
||||||
!runtimeConfigSetupSource.includes(
|
!runtimeConfigSetupSource.includes(
|
||||||
'startup.appdata.configure.failed details={details}',
|
'startup.appdata.configure.failed details={details}',
|
||||||
) ||
|
)
|
||||||
!tauriHandlerSource.includes('impl StartupLogSlot {') ||
|
|
||||||
!tauriHandlerSource.includes('append_bounded_diagnostic_line(&path, line)') ||
|
|
||||||
!tauriHandlerSource.includes(
|
|
||||||
'self.append(line);\n show_startup_error_dialog(self.path().as_deref());',
|
|
||||||
) ||
|
|
||||||
!tauriHandlerSource.includes('early_startup_log_path(')
|
|
||||||
) {
|
) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'AI game creator setup must configure the runtime AppData directory and log sanitized setup failures',
|
'AI game creator setup must configure the runtime AppData directory and log sanitized setup failures',
|
||||||
|
|||||||
@@ -9,8 +9,13 @@ if (!/^[a-z0-9][a-z0-9.-]{1,62}$/u.test(bucket) || /[\r\n\0]/u.test(endpoint)) {
|
|||||||
}
|
}
|
||||||
process.env.AGC_UPDATE_OSS_BASE_URL ||= `https://${bucket}.${endpoint}/agc`;
|
process.env.AGC_UPDATE_OSS_BASE_URL ||= `https://${bucket}.${endpoint}/agc`;
|
||||||
|
|
||||||
const { generateUpdateManifest, prepareReleaseVersion, runTauriBuild } =
|
const {
|
||||||
await import('./build-release.mjs');
|
assertVersionCommitted,
|
||||||
|
assertVersionNotBelowOss,
|
||||||
|
generateUpdateManifest,
|
||||||
|
prepareReleaseVersion,
|
||||||
|
runTauriBuild,
|
||||||
|
} = await import('./build-release.mjs');
|
||||||
|
|
||||||
function runOssutil(args) {
|
function runOssutil(args) {
|
||||||
const binary = process.env.OSSUTIL_BIN?.trim() || 'ossutil';
|
const binary = process.env.OSSUTIL_BIN?.trim() || 'ossutil';
|
||||||
@@ -36,7 +41,9 @@ function runOssutil(args) {
|
|||||||
if (result.status !== 0) process.exit(result.status ?? 1);
|
if (result.status !== 0) process.exit(result.status ?? 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
await prepareReleaseVersion();
|
const releaseVersion = await prepareReleaseVersion();
|
||||||
|
assertVersionCommitted();
|
||||||
|
await assertVersionNotBelowOss(releaseVersion);
|
||||||
runTauriBuild([]);
|
runTauriBuild([]);
|
||||||
const { artifact, manifestPath, manifest } = generateUpdateManifest();
|
const { artifact, manifestPath, manifest } = generateUpdateManifest();
|
||||||
const artifactKey = `agc/${manifest.version}/${path.basename(artifact)}`;
|
const artifactKey = `agc/${manifest.version}/${path.basename(artifact)}`;
|
||||||
|
|||||||
@@ -1,461 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
// AGC 壳 Rust 套件的分片运行器。
|
|
||||||
//
|
|
||||||
// 背景:AGC 壳的 Rust 单测集中在 src/main.rs 的 bin target(实测 2466 条),仓库口径用
|
|
||||||
// `--test-threads=1` 跑,理由是并行调度会让共享 Agent Runtime 后台锁与异步终态的用例在
|
|
||||||
// **同一进程内**互相干扰(见 development-workflow 的 Tauri suite 单线程口径)。代价是
|
|
||||||
// 整套用例串行跑满 507 秒,占掉 CI 上 `AI game creator shell Rust tests` job 的大头。
|
|
||||||
//
|
|
||||||
// 这里保留「片内串行」的既有口径,只把用例集合切成 N 片:
|
|
||||||
// - CI 用 `--shard-index=<i>` 让**每个 job 只跑一片**,靠多个 job 并发把整套用例摊开;
|
|
||||||
// - 本地不传 `--shard-index` 时把 N 片放进 N 个**独立进程**并行(--concurrency 可调),
|
|
||||||
// 保留一条命令跑全量的入口。
|
|
||||||
// 片并集必须等于全集、且不得重复,数量不符即失败,防止分片规则改动后静默漏跑;该校验
|
|
||||||
// 与「只跑一片」无关,因此在每个 job 上都会执行。
|
|
||||||
//
|
|
||||||
// 注意:同一容器内多进程并行这套用例(共享 HOME、target、固定临时路径)实测会互相拖慢,
|
|
||||||
// 比串行还慢,所以 CI 走「一个 job 一片」而不是单 job 内并行。
|
|
||||||
//
|
|
||||||
// 用法:
|
|
||||||
// node scripts/run-rust-shell-test-shards.mjs --shards=4 --shard-index=2 # CI:只跑第 2 片
|
|
||||||
// node scripts/run-rust-shell-test-shards.mjs [--shards=4] [--concurrency=4] # 本地:全量
|
|
||||||
// node scripts/run-rust-shell-test-shards.mjs --manifest=<Cargo.toml> --target-kind=lib --no-locked
|
|
||||||
//
|
|
||||||
// 参数:
|
|
||||||
// --shards=<n> 分片数,默认 4
|
|
||||||
// --shard-index=<i> 只跑第 i 片(1..shards);不传则跑全部分片
|
|
||||||
// --concurrency=<n> 同时运行的片数,默认等于分片数;--shard-index 时恒为 1
|
|
||||||
// --manifest=<path> Cargo.toml,默认 ../src-tauri/Cargo.toml(相对本脚本)
|
|
||||||
// --target-kind=<k> bin | lib,默认 bin(本地自测小 crate 时用 lib)
|
|
||||||
// --bin=<name> bin target 名,默认 genarrative-ai-game-creator-shell
|
|
||||||
// --package=<name> target-kind=lib 时要跑的包名(配合 lib 目标使用)
|
|
||||||
// --no-locked 传给 cargo 时不带 --locked(只对没有提交 Cargo.lock 的 crate 需要)
|
|
||||||
// --shard-tmp-root=<path> 片专属 TMPDIR 的父目录,默认 <系统临时目录>/agc-rust-shards
|
|
||||||
|
|
||||||
import { spawn } from 'node:child_process';
|
|
||||||
import fs from 'node:fs';
|
|
||||||
import os from 'node:os';
|
|
||||||
import path from 'node:path';
|
|
||||||
import { fileURLToPath } from 'node:url';
|
|
||||||
|
|
||||||
const scriptDirectory = path.dirname(fileURLToPath(import.meta.url));
|
|
||||||
const shellRoot = path.resolve(scriptDirectory, '..');
|
|
||||||
|
|
||||||
function fail(message) {
|
|
||||||
console.error(`[rust-shards] ${message}`);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function parsePositiveInteger(name, rawValue) {
|
|
||||||
if (!/^[1-9][0-9]*$/.test(rawValue)) {
|
|
||||||
fail(`${name} must be a positive integer, received: ${rawValue}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Number(rawValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
const options = {
|
|
||||||
shards: 4,
|
|
||||||
shardIndex: undefined,
|
|
||||||
concurrency: undefined,
|
|
||||||
manifestPath: path.join(shellRoot, 'src-tauri', 'Cargo.toml'),
|
|
||||||
targetKind: 'bin',
|
|
||||||
binName: 'genarrative-ai-game-creator-shell',
|
|
||||||
packageName: undefined,
|
|
||||||
locked: true,
|
|
||||||
shardTmpRoot: path.join(os.tmpdir(), 'agc-rust-shards'),
|
|
||||||
};
|
|
||||||
|
|
||||||
for (const rawArgument of process.argv.slice(2)) {
|
|
||||||
if (rawArgument === '--no-locked') {
|
|
||||||
options.locked = false;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const separatorIndex = rawArgument.indexOf('=');
|
|
||||||
if (!rawArgument.startsWith('--') || separatorIndex === -1) {
|
|
||||||
fail(`unexpected argument: ${rawArgument}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const name = rawArgument.slice(2, separatorIndex);
|
|
||||||
const value = rawArgument.slice(separatorIndex + 1);
|
|
||||||
switch (name) {
|
|
||||||
case 'shards':
|
|
||||||
options.shards = parsePositiveInteger('--shards', value);
|
|
||||||
break;
|
|
||||||
case 'shard-index':
|
|
||||||
options.shardIndex = parsePositiveInteger('--shard-index', value);
|
|
||||||
break;
|
|
||||||
case 'concurrency':
|
|
||||||
options.concurrency = parsePositiveInteger('--concurrency', value);
|
|
||||||
break;
|
|
||||||
case 'manifest':
|
|
||||||
options.manifestPath = path.resolve(process.cwd(), value);
|
|
||||||
break;
|
|
||||||
case 'target-kind':
|
|
||||||
if (value !== 'bin' && value !== 'lib') {
|
|
||||||
fail(`--target-kind must be bin or lib, received: ${value}`);
|
|
||||||
}
|
|
||||||
options.targetKind = value;
|
|
||||||
break;
|
|
||||||
case 'bin':
|
|
||||||
options.binName = value;
|
|
||||||
break;
|
|
||||||
case 'package':
|
|
||||||
options.packageName = value;
|
|
||||||
break;
|
|
||||||
case 'shard-tmp-root':
|
|
||||||
options.shardTmpRoot = path.resolve(process.cwd(), value);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
fail(`unexpected argument: ${rawArgument}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fs.existsSync(options.manifestPath)) {
|
|
||||||
fail(`manifest does not exist: ${options.manifestPath}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.shardIndex !== undefined && options.shardIndex > options.shards) {
|
|
||||||
fail(
|
|
||||||
`--shard-index (${options.shardIndex}) must be within --shards (${options.shards})`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const concurrency = options.concurrency ?? options.shards;
|
|
||||||
const crateRoot = path.dirname(options.manifestPath);
|
|
||||||
|
|
||||||
function buildCargoArguments(target) {
|
|
||||||
const cargoArguments = ['test'];
|
|
||||||
if (options.locked) {
|
|
||||||
cargoArguments.push('--locked');
|
|
||||||
}
|
|
||||||
cargoArguments.push('--manifest-path', options.manifestPath);
|
|
||||||
if (target.kind === 'lib') {
|
|
||||||
if (options.packageName !== undefined) {
|
|
||||||
cargoArguments.push('-p', options.packageName);
|
|
||||||
}
|
|
||||||
cargoArguments.push('--lib');
|
|
||||||
return cargoArguments;
|
|
||||||
}
|
|
||||||
cargoArguments.push('--bin', target.name);
|
|
||||||
return cargoArguments;
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatDuration(milliseconds) {
|
|
||||||
return `${(milliseconds / 1000).toFixed(1)}s`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 编译一次,直接拿到测试可执行文件:后续每片都运行同一个二进制,不再各自调用 cargo,
|
|
||||||
// 免得 N 个 cargo 去争 package cache 与 target 目录锁。
|
|
||||||
function resolveTestExecutable() {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const cargoArguments = buildCargoArguments({
|
|
||||||
kind: options.targetKind,
|
|
||||||
name: options.binName,
|
|
||||||
});
|
|
||||||
cargoArguments.push('--no-run', '--message-format=json');
|
|
||||||
console.log(`[rust-shards] cargo ${cargoArguments.join(' ')}`);
|
|
||||||
|
|
||||||
const child = spawn('cargo', cargoArguments, {
|
|
||||||
cwd: crateRoot,
|
|
||||||
env: process.env,
|
|
||||||
stdio: ['ignore', 'pipe', 'inherit'],
|
|
||||||
});
|
|
||||||
|
|
||||||
let buffered = '';
|
|
||||||
const executables = [];
|
|
||||||
child.stdout.setEncoding('utf8');
|
|
||||||
child.stdout.on('data', (chunk) => {
|
|
||||||
buffered += chunk;
|
|
||||||
const lines = buffered.split('\n');
|
|
||||||
buffered = lines.pop() ?? '';
|
|
||||||
for (const line of lines) {
|
|
||||||
if (!line.startsWith('{')) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let message;
|
|
||||||
try {
|
|
||||||
message = JSON.parse(line);
|
|
||||||
} catch {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
message.reason === 'compiler-artifact' &&
|
|
||||||
typeof message.executable === 'string'
|
|
||||||
) {
|
|
||||||
executables.push(message.executable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
child.on('error', (error) => {
|
|
||||||
reject(new Error(`unable to start cargo: ${error.message}`));
|
|
||||||
});
|
|
||||||
child.on('close', (code) => {
|
|
||||||
if (code !== 0) {
|
|
||||||
reject(
|
|
||||||
new Error(
|
|
||||||
`cargo ${cargoArguments.join(' ')} failed with exit code ${code}`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const uniqueExecutables = [...new Set(executables)];
|
|
||||||
if (uniqueExecutables.length !== 1) {
|
|
||||||
reject(
|
|
||||||
new Error(
|
|
||||||
`expected exactly one test executable for the ${options.targetKind} target, found ${uniqueExecutables.length}: ${uniqueExecutables.join(', ')}`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
resolve(uniqueExecutables[0]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function listTestNames(executable) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const child = spawn(executable, ['--list'], {
|
|
||||||
cwd: crateRoot,
|
|
||||||
env: process.env,
|
|
||||||
stdio: ['ignore', 'pipe', 'pipe'],
|
|
||||||
});
|
|
||||||
|
|
||||||
let stdout = '';
|
|
||||||
let stderr = '';
|
|
||||||
child.stdout.setEncoding('utf8');
|
|
||||||
child.stderr.setEncoding('utf8');
|
|
||||||
child.stdout.on('data', (chunk) => {
|
|
||||||
stdout += chunk;
|
|
||||||
});
|
|
||||||
child.stderr.on('data', (chunk) => {
|
|
||||||
stderr += chunk;
|
|
||||||
});
|
|
||||||
child.on('error', (error) => {
|
|
||||||
reject(new Error(`unable to list tests: ${error.message}`));
|
|
||||||
});
|
|
||||||
child.on('close', (code) => {
|
|
||||||
if (code !== 0) {
|
|
||||||
reject(
|
|
||||||
new Error(
|
|
||||||
`listing tests failed with exit code ${code}: ${stderr.trim()}`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const names = [];
|
|
||||||
for (const line of stdout.split('\n')) {
|
|
||||||
const match = /^(.*): test$/.exec(line.trim());
|
|
||||||
if (match !== null && match[1].length > 0) {
|
|
||||||
names.push(match[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
resolve(names);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function splitTestNames(testNames, shardCount) {
|
|
||||||
const sortedNames = [...testNames].sort();
|
|
||||||
const shards = Array.from({ length: shardCount }, () => []);
|
|
||||||
sortedNames.forEach((testName, index) => {
|
|
||||||
shards[index % shardCount].push(testName);
|
|
||||||
});
|
|
||||||
return shards;
|
|
||||||
}
|
|
||||||
|
|
||||||
function assertShardsCoverEveryTest(testNames, shards) {
|
|
||||||
const flattened = shards.flat();
|
|
||||||
if (flattened.length !== testNames.length) {
|
|
||||||
fail(
|
|
||||||
`shard split covered ${flattened.length} of ${testNames.length} tests; the split rule must be exhaustive`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (new Set(flattened).size !== flattened.length) {
|
|
||||||
fail(
|
|
||||||
'shard split selected the same test more than once; the split rule must be disjoint',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const missing = testNames.filter((testName) => !flattened.includes(testName));
|
|
||||||
if (missing.length > 0) {
|
|
||||||
fail(
|
|
||||||
`shard split is missing tests, for example: ${missing.slice(0, 5).join(', ')}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function runShard(executable, shardIndex, shardCount, shardTestNames) {
|
|
||||||
const label = `shard ${shardIndex + 1}/${shardCount}`;
|
|
||||||
const shardTmpDirectory = path.join(
|
|
||||||
options.shardTmpRoot,
|
|
||||||
`shard-${shardIndex + 1}`,
|
|
||||||
);
|
|
||||||
fs.rmSync(shardTmpDirectory, { recursive: true, force: true });
|
|
||||||
fs.mkdirSync(shardTmpDirectory, { recursive: true });
|
|
||||||
const startedAt = Date.now();
|
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
const child = spawn(
|
|
||||||
executable,
|
|
||||||
['--exact', ...shardTestNames, '--test-threads=1'],
|
|
||||||
{
|
|
||||||
cwd: crateRoot,
|
|
||||||
env: {
|
|
||||||
...process.env,
|
|
||||||
TMPDIR: shardTmpDirectory,
|
|
||||||
TMP: shardTmpDirectory,
|
|
||||||
TEMP: shardTmpDirectory,
|
|
||||||
},
|
|
||||||
stdio: ['ignore', 'pipe', 'pipe'],
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const failureLines = [];
|
|
||||||
let inFailureList = false;
|
|
||||||
let stderr = '';
|
|
||||||
const consumeLine = (rawLine) => {
|
|
||||||
const line = rawLine.replace(/\r$/, '');
|
|
||||||
if (line.includes('failures:')) {
|
|
||||||
inFailureList = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (inFailureList) {
|
|
||||||
if (line.trim().length === 0) {
|
|
||||||
inFailureList = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
failureLines.push(line.trim());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
child.stdout.setEncoding('utf8');
|
|
||||||
child.stderr.setEncoding('utf8');
|
|
||||||
let stdoutBuffer = '';
|
|
||||||
child.stdout.on('data', (chunk) => {
|
|
||||||
stdoutBuffer += chunk;
|
|
||||||
const lines = stdoutBuffer.split('\n');
|
|
||||||
stdoutBuffer = lines.pop() ?? '';
|
|
||||||
for (const line of lines) {
|
|
||||||
consumeLine(line);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
child.stderr.on('data', (chunk) => {
|
|
||||||
stderr += chunk;
|
|
||||||
});
|
|
||||||
|
|
||||||
child.on('error', (error) => {
|
|
||||||
resolve({
|
|
||||||
label,
|
|
||||||
ok: false,
|
|
||||||
durationMs: Date.now() - startedAt,
|
|
||||||
testCount: shardTestNames.length,
|
|
||||||
failures: [`unable to start test binary: ${error.message}`],
|
|
||||||
stderr,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
child.on('close', (code) => {
|
|
||||||
resolve({
|
|
||||||
label,
|
|
||||||
ok: code === 0,
|
|
||||||
durationMs: Date.now() - startedAt,
|
|
||||||
testCount: shardTestNames.length,
|
|
||||||
failures: failureLines,
|
|
||||||
stderr,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function runWithConcurrency(shards, runner) {
|
|
||||||
const results = new Array(shards.length);
|
|
||||||
let nextIndex = 0;
|
|
||||||
const workers = Array.from(
|
|
||||||
{ length: Math.min(concurrency, shards.length) },
|
|
||||||
async () => {
|
|
||||||
while (nextIndex < shards.length) {
|
|
||||||
const index = nextIndex;
|
|
||||||
nextIndex += 1;
|
|
||||||
results[index] = await runner(shards[index], index);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
await Promise.all(workers);
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
const executable = await resolveTestExecutable();
|
|
||||||
const testNames = await listTestNames(executable);
|
|
||||||
if (testNames.length === 0) {
|
|
||||||
fail(
|
|
||||||
`no tests discovered in ${options.manifestPath} (${options.targetKind})`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const shards = splitTestNames(testNames, options.shards);
|
|
||||||
assertShardsCoverEveryTest(testNames, shards);
|
|
||||||
|
|
||||||
const selectedShards =
|
|
||||||
options.shardIndex === undefined
|
|
||||||
? shards.map((shardTestNames, index) => ({ index, shardTestNames }))
|
|
||||||
: [
|
|
||||||
{
|
|
||||||
index: options.shardIndex - 1,
|
|
||||||
shardTestNames: shards[options.shardIndex - 1],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
if (options.shardIndex === undefined) {
|
|
||||||
console.log(
|
|
||||||
`[rust-shards] ${testNames.length} tests, ${shards.length} shard(s), concurrency ${Math.min(concurrency, shards.length)}`,
|
|
||||||
);
|
|
||||||
for (const { index, shardTestNames } of selectedShards) {
|
|
||||||
console.log(
|
|
||||||
`[rust-shards] shard ${index + 1}/${shards.length}: ${shardTestNames.length} test(s)`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.log(
|
|
||||||
`[rust-shards] ${testNames.length} tests, ${shards.length} shard(s), running shard ${options.shardIndex}/${shards.length} (${selectedShards[0].shardTestNames.length} test(s))`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const results = await runWithConcurrency(
|
|
||||||
selectedShards,
|
|
||||||
({ index, shardTestNames }) =>
|
|
||||||
runShard(executable, index, shards.length, shardTestNames),
|
|
||||||
);
|
|
||||||
|
|
||||||
let failed = false;
|
|
||||||
for (const result of results) {
|
|
||||||
if (result.ok) {
|
|
||||||
console.log(
|
|
||||||
`[rust-shards] ${result.label} ok: ${result.testCount} test(s) in ${formatDuration(result.durationMs)}`,
|
|
||||||
);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
failed = true;
|
|
||||||
console.error(
|
|
||||||
`[rust-shards] ${result.label} FAILED: ${result.testCount} test(s) in ${formatDuration(result.durationMs)}`,
|
|
||||||
);
|
|
||||||
for (const failure of result.failures) {
|
|
||||||
console.error(`[rust-shards] ${failure}`);
|
|
||||||
}
|
|
||||||
if (result.stderr.trim().length > 0) {
|
|
||||||
console.error(
|
|
||||||
`[rust-shards] stderr: ${result.stderr.trim().split('\n').slice(-20).join('\n[rust-shards] ')}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (failed) {
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
console.log('[rust-shards] OK');
|
|
||||||
}
|
|
||||||
|
|
||||||
main().catch((error) => {
|
|
||||||
fail(error instanceof Error ? error.message : String(error));
|
|
||||||
});
|
|
||||||
@@ -8,7 +8,6 @@ export const SKILL_PACK_SCHEMA_VERSION = 'agc-skill-pack.v1';
|
|||||||
export const EXPECTED_SKILL_NAMES = Object.freeze([
|
export const EXPECTED_SKILL_NAMES = Object.freeze([
|
||||||
'agc-browser-playtest',
|
'agc-browser-playtest',
|
||||||
'agc-client-projection',
|
'agc-client-projection',
|
||||||
'agc-game-production-workflow',
|
|
||||||
'agc-project-structure',
|
'agc-project-structure',
|
||||||
'agc-web-game-development',
|
'agc-web-game-development',
|
||||||
'taonier-art-assets',
|
'taonier-art-assets',
|
||||||
|
|||||||
@@ -722,7 +722,7 @@ function runAgent() {
|
|||||||
stderr += chunk.toString();
|
stderr += chunk.toString();
|
||||||
});
|
});
|
||||||
child.on('error', reject);
|
child.on('error', reject);
|
||||||
child.on('close', (code, signal) => {
|
child.on('close', (code) => {
|
||||||
const output = `${stdout}${stderr}`;
|
const output = `${stdout}${stderr}`;
|
||||||
if (previewReadError) {
|
if (previewReadError) {
|
||||||
reject(previewReadError);
|
reject(previewReadError);
|
||||||
@@ -740,24 +740,13 @@ function runAgent() {
|
|||||||
previewDom,
|
previewDom,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
reject(
|
reject(new Error(output || `agent run exited with ${code}`));
|
||||||
new Error(
|
|
||||||
`agent run failed: exitCode=${code}, signal=${signal ?? 'none'}\n` +
|
|
||||||
`stderr tail (last 8000 characters):\n${stderr.slice(-8000)}\n` +
|
|
||||||
`stdout tail (last 4000 characters):\n${stdout.slice(-4000)}`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function seedLocalAsset() {
|
async function seedLocalAsset() {
|
||||||
await fs.mkdir(path.join(projectRoot, 'game'), { recursive: true });
|
|
||||||
await fs.writeFile(
|
|
||||||
path.join(projectRoot, 'game/index.html'),
|
|
||||||
'<!doctype html><html lang="zh-CN"><meta charset="UTF-8"><body>还没有生成游戏</body></html>',
|
|
||||||
);
|
|
||||||
await fs.mkdir(path.join(projectRoot, 'assets/uploads'), { recursive: true });
|
await fs.mkdir(path.join(projectRoot, 'assets/uploads'), { recursive: true });
|
||||||
await fs.mkdir(path.join(projectRoot, '.agent'), { recursive: true });
|
await fs.mkdir(path.join(projectRoot, '.agent'), { recursive: true });
|
||||||
await seedConversationContext();
|
await seedConversationContext();
|
||||||
|
|||||||
@@ -1,16 +1,10 @@
|
|||||||
import { spawn, spawnSync } from 'node:child_process';
|
import { spawn } from 'node:child_process';
|
||||||
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
||||||
import http from 'node:http';
|
import http from 'node:http';
|
||||||
import net from 'node:net';
|
import net from 'node:net';
|
||||||
import { resolve } from 'node:path';
|
import { resolve } from 'node:path';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
import {
|
|
||||||
normalizeWindowsPath,
|
|
||||||
parseWindowsProcessSnapshot,
|
|
||||||
stopWindowsProcessTree,
|
|
||||||
stopWindowsWorktreeProcesses,
|
|
||||||
} from '../../../scripts/dev-windows-process.mjs';
|
|
||||||
import {
|
import {
|
||||||
agcVitePortEnvKey,
|
agcVitePortEnvKey,
|
||||||
readAgcDevEndpoint,
|
readAgcDevEndpoint,
|
||||||
@@ -21,10 +15,6 @@ import {
|
|||||||
const appRoot = fileURLToPath(new URL('..', import.meta.url));
|
const appRoot = fileURLToPath(new URL('..', import.meta.url));
|
||||||
const repoRoot = resolve(appRoot, '../..');
|
const repoRoot = resolve(appRoot, '../..');
|
||||||
const devStackStatePath = resolve(repoRoot, '.app/dev-stack.json');
|
const devStackStatePath = resolve(repoRoot, '.app/dev-stack.json');
|
||||||
const apiServerExePath = resolve(
|
|
||||||
repoRoot,
|
|
||||||
'server-rs/target/debug/api-server.exe',
|
|
||||||
);
|
|
||||||
const defaultApiTarget =
|
const defaultApiTarget =
|
||||||
process.env.RUST_SERVER_TARGET || 'http://127.0.0.1:8082';
|
process.env.RUST_SERVER_TARGET || 'http://127.0.0.1:8082';
|
||||||
const backendDatabase = 'genarrative-game-creator-dev';
|
const backendDatabase = 'genarrative-game-creator-dev';
|
||||||
@@ -84,7 +74,6 @@ function resolveBackendTargetsFromState(
|
|||||||
requireAgcBackend = false,
|
requireAgcBackend = false,
|
||||||
expectedDatabase = backendDatabase,
|
expectedDatabase = backendDatabase,
|
||||||
expectedSpacetimeDataDir = backendSpacetimeDataDir,
|
expectedSpacetimeDataDir = backendSpacetimeDataDir,
|
||||||
expectedRepoRoot = repoRoot,
|
|
||||||
fallbackApiTarget = defaultApiTarget,
|
fallbackApiTarget = defaultApiTarget,
|
||||||
} = {},
|
} = {},
|
||||||
) {
|
) {
|
||||||
@@ -102,25 +91,7 @@ function resolveBackendTargetsFromState(
|
|||||||
const hasMatchingDataDir =
|
const hasMatchingDataDir =
|
||||||
Boolean(spacetimeDataDir) &&
|
Boolean(spacetimeDataDir) &&
|
||||||
spacetimeDataDir === resolve(expectedSpacetimeDataDir);
|
spacetimeDataDir === resolve(expectedSpacetimeDataDir);
|
||||||
const instanceId =
|
const hasMatchingBackend = hasMatchingDatabase && hasMatchingDataDir;
|
||||||
typeof state?.instanceId === 'string' ? state.instanceId.trim() : '';
|
|
||||||
const hasMatchingRepoRoot =
|
|
||||||
typeof state?.repoRoot === 'string' &&
|
|
||||||
resolve(state.repoRoot) === resolve(expectedRepoRoot);
|
|
||||||
const hasMatchingInstance =
|
|
||||||
Boolean(instanceId) &&
|
|
||||||
[apiServer, spacetime, bgfilterWorker]
|
|
||||||
.filter(Boolean)
|
|
||||||
.every(
|
|
||||||
(service) =>
|
|
||||||
service.repoRoot &&
|
|
||||||
resolve(service.repoRoot) === resolve(expectedRepoRoot) &&
|
|
||||||
service.instanceId === instanceId,
|
|
||||||
);
|
|
||||||
const hasMatchingBackend =
|
|
||||||
hasMatchingDatabase &&
|
|
||||||
hasMatchingDataDir &&
|
|
||||||
(!requireAgcBackend || (hasMatchingRepoRoot && hasMatchingInstance));
|
|
||||||
const canReuseState = !requireAgcBackend || hasMatchingBackend;
|
const canReuseState = !requireAgcBackend || hasMatchingBackend;
|
||||||
const apiUrl =
|
const apiUrl =
|
||||||
canReuseState && isActive(apiServer) && apiServer.url
|
canReuseState && isActive(apiServer) && apiServer.url
|
||||||
@@ -146,8 +117,6 @@ function resolveBackendTargetsFromState(
|
|||||||
spacetimeDataDir,
|
spacetimeDataDir,
|
||||||
hasMatchingDatabase,
|
hasMatchingDatabase,
|
||||||
hasMatchingDataDir,
|
hasMatchingDataDir,
|
||||||
hasMatchingRepoRoot,
|
|
||||||
hasMatchingInstance,
|
|
||||||
hasMatchingBackend,
|
hasMatchingBackend,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -158,217 +127,19 @@ function readBackendTargets({ requireAgcBackend = false } = {}) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function readBackendServiceFailure(
|
|
||||||
state,
|
|
||||||
{
|
|
||||||
expectedDatabase = backendDatabase,
|
|
||||||
expectedSpacetimeDataDir = backendSpacetimeDataDir,
|
|
||||||
} = {},
|
|
||||||
) {
|
|
||||||
const targets = resolveBackendTargetsFromState(state, {
|
|
||||||
requireAgcBackend: true,
|
|
||||||
expectedDatabase,
|
|
||||||
expectedSpacetimeDataDir,
|
|
||||||
});
|
|
||||||
if (!targets.hasMatchingBackend) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const serviceName of ['spacetime', 'api-server', 'bgfilter-worker']) {
|
|
||||||
const service = state?.services?.[serviceName];
|
|
||||||
if (service?.status !== 'failed') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
serviceName,
|
|
||||||
failure: service.signal
|
|
||||||
? `signal=${service.signal}`
|
|
||||||
: `code=${service.exitCode ?? 1}`,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function urlPort(url) {
|
|
||||||
try {
|
|
||||||
const port = Number(new URL(url).port);
|
|
||||||
return Number.isInteger(port) && port > 0 ? port : 0;
|
|
||||||
} catch {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 读取端口当前真正的监听进程身份。返回 null 表示探测本身不可用(例如缺少
|
|
||||||
// Get-NetTCPConnection),此时调用方必须退化为旧行为,不能让本地启动直接失败。
|
|
||||||
function readWindowsPortOwnerIdentities(
|
|
||||||
ports,
|
|
||||||
{ spawnImpl = spawnSync, env = process.env } = {},
|
|
||||||
) {
|
|
||||||
const uniquePorts = [...new Set(ports.filter((port) => port > 0))];
|
|
||||||
if (uniquePorts.length === 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const command = [
|
|
||||||
'$ErrorActionPreference = "SilentlyContinue"',
|
|
||||||
'$ports = ($env:GENARRATIVE_QUERY_PORTS -split ",") | Where-Object { $_ }',
|
|
||||||
'$result = @()',
|
|
||||||
'foreach ($port in $ports) {',
|
|
||||||
' $connection = Get-NetTCPConnection -State Listen -LocalPort ([int]$port) -ErrorAction SilentlyContinue | Select-Object -First 1',
|
|
||||||
' if (-not $connection) { continue }',
|
|
||||||
' $owner = Get-CimInstance Win32_Process -Filter ("ProcessId=" + $connection.OwningProcess) -ErrorAction SilentlyContinue',
|
|
||||||
' $result += [pscustomobject]@{ port = [int]$port; processId = [int]$connection.OwningProcess; name = $owner.Name; executablePath = $owner.ExecutablePath; commandLine = $owner.CommandLine }',
|
|
||||||
'}',
|
|
||||||
'ConvertTo-Json -InputObject @($result) -Compress',
|
|
||||||
].join('\n');
|
|
||||||
|
|
||||||
const result = spawnImpl(
|
|
||||||
'powershell.exe',
|
|
||||||
['-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', command],
|
|
||||||
{
|
|
||||||
encoding: 'utf8',
|
|
||||||
env: { ...env, GENARRATIVE_QUERY_PORTS: uniquePorts.join(',') },
|
|
||||||
maxBuffer: 8 * 1024 * 1024,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
if (result?.error || result?.status !== 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const owners = new Map();
|
|
||||||
for (const entry of parseWindowsProcessSnapshot(result.stdout)) {
|
|
||||||
const port = Number(entry?.port);
|
|
||||||
if (Number.isInteger(port) && port > 0) {
|
|
||||||
owners.set(port, entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return owners;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isWorktreeApiServerOwner(
|
|
||||||
owner,
|
|
||||||
{ expectedExePath = apiServerExePath } = {},
|
|
||||||
) {
|
|
||||||
if (!owner) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const expected = normalizeWindowsPath(expectedExePath);
|
|
||||||
const actual = normalizeWindowsPath(owner.executablePath);
|
|
||||||
return Boolean(expected) && actual === expected;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isWorktreeSpacetimeOwner(
|
|
||||||
owner,
|
|
||||||
{ expectedDataDir = backendSpacetimeDataDir } = {},
|
|
||||||
) {
|
|
||||||
if (!owner) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const expected = normalizeWindowsPath(expectedDataDir);
|
|
||||||
if (!expected) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const name = String(owner.name ?? '').toLowerCase();
|
|
||||||
if (!name.startsWith('spacetime')) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return normalizeWindowsPath(owner.commandLine).includes(expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 端口健康不代表后端属于当前工作树:上个工作树 Ctrl+C 残留的 api-server 仍会
|
|
||||||
// 应答 /healthz。复用前必须证明端口上的进程就是本工作树的可执行文件与数据目录。
|
|
||||||
function verifyAgcBackendOwnership({
|
|
||||||
apiUrl,
|
|
||||||
spacetimeUrl,
|
|
||||||
bgfilterWorkerUrl,
|
|
||||||
platform = process.platform,
|
|
||||||
expectedExePath = apiServerExePath,
|
|
||||||
expectedDataDir = backendSpacetimeDataDir,
|
|
||||||
readPortOwners = readWindowsPortOwnerIdentities,
|
|
||||||
} = {}) {
|
|
||||||
if (platform !== 'win32') {
|
|
||||||
return { ok: true, reason: 'platform-unsupported', owners: new Map() };
|
|
||||||
}
|
|
||||||
|
|
||||||
const ports = [
|
|
||||||
urlPort(apiUrl),
|
|
||||||
urlPort(bgfilterWorkerUrl),
|
|
||||||
urlPort(spacetimeUrl),
|
|
||||||
];
|
|
||||||
const owners = readPortOwners(ports);
|
|
||||||
if (!owners) {
|
|
||||||
return { ok: true, reason: 'owner-probe-unavailable', owners: new Map() };
|
|
||||||
}
|
|
||||||
|
|
||||||
const apiOwner = owners.get(urlPort(apiUrl));
|
|
||||||
if (!isWorktreeApiServerOwner(apiOwner, { expectedExePath })) {
|
|
||||||
return { ok: false, reason: 'api-server-owner-mismatch', owners, apiOwner };
|
|
||||||
}
|
|
||||||
|
|
||||||
const workerOwner = owners.get(urlPort(bgfilterWorkerUrl));
|
|
||||||
if (!isWorktreeApiServerOwner(workerOwner, { expectedExePath })) {
|
|
||||||
return {
|
|
||||||
ok: false,
|
|
||||||
reason: 'bgfilter-worker-owner-mismatch',
|
|
||||||
owners,
|
|
||||||
workerOwner,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const spacetimeOwner = owners.get(urlPort(spacetimeUrl));
|
|
||||||
if (!isWorktreeSpacetimeOwner(spacetimeOwner, { expectedDataDir })) {
|
|
||||||
return {
|
|
||||||
ok: false,
|
|
||||||
reason: 'spacetime-owner-mismatch',
|
|
||||||
owners,
|
|
||||||
spacetimeOwner,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return { ok: true, reason: 'owned', owners };
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatOwnerLabel(owner) {
|
|
||||||
if (!owner) {
|
|
||||||
return '未知进程';
|
|
||||||
}
|
|
||||||
const pid = Number(owner.processId);
|
|
||||||
const label = owner.executablePath || owner.commandLine || owner.name || '';
|
|
||||||
return `${Number.isInteger(pid) ? `pid=${pid} ` : ''}${String(label).trim()}`.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function isBackendReady({
|
async function isBackendReady({
|
||||||
state = readJson(devStackStatePath),
|
state = readJson(devStackStatePath),
|
||||||
isReady = isHttpReady,
|
isReady = isHttpReady,
|
||||||
verifyOwnership = verifyAgcBackendOwnership,
|
|
||||||
onOwnershipRejected = null,
|
|
||||||
} = {}) {
|
} = {}) {
|
||||||
const { apiUrl, spacetimeUrl, bgfilterWorkerUrl, hasMatchingBackend } =
|
const { apiUrl, spacetimeUrl, bgfilterWorkerUrl, hasMatchingBackend } =
|
||||||
resolveBackendTargetsFromState(state, {
|
resolveBackendTargetsFromState(state, {
|
||||||
requireAgcBackend: true,
|
requireAgcBackend: true,
|
||||||
});
|
});
|
||||||
if (!hasMatchingBackend || !apiUrl || !spacetimeUrl || !bgfilterWorkerUrl) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ownership = await verifyOwnership({
|
|
||||||
apiUrl,
|
|
||||||
spacetimeUrl,
|
|
||||||
bgfilterWorkerUrl,
|
|
||||||
});
|
|
||||||
if (!ownership?.ok) {
|
|
||||||
onOwnershipRejected?.(ownership);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (ownership.reason === 'owner-probe-unavailable') {
|
|
||||||
console.warn(
|
|
||||||
'[ai-game-creator-shell] 无法读取端口监听进程归属,本次按旧行为复用配套后端。',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
hasMatchingBackend &&
|
||||||
|
Boolean(apiUrl) &&
|
||||||
|
Boolean(spacetimeUrl) &&
|
||||||
|
Boolean(bgfilterWorkerUrl) &&
|
||||||
(await isReady(`${apiUrl}/healthz`)) &&
|
(await isReady(`${apiUrl}/healthz`)) &&
|
||||||
(await isReady(`${spacetimeUrl}/v1/ping`)) &&
|
(await isReady(`${spacetimeUrl}/v1/ping`)) &&
|
||||||
(await isReady(`${bgfilterWorkerUrl}/readyz`))
|
(await isReady(`${bgfilterWorkerUrl}/readyz`))
|
||||||
@@ -457,10 +228,6 @@ function spawnChild(command, args, options, spawnImpl = spawn) {
|
|||||||
const child = spawnImpl(command, args, {
|
const child = spawnImpl(command, args, {
|
||||||
...options,
|
...options,
|
||||||
shell: useShell,
|
shell: useShell,
|
||||||
// npm.cmd and the Windows shell otherwise create a visible console for
|
|
||||||
// every service in the dev stack. Their stdout/stderr is already inherited
|
|
||||||
// by the launcher, so no separate terminal window is useful.
|
|
||||||
windowsHide: process.platform === 'win32' ? true : options.windowsHide,
|
|
||||||
// POSIX 下让每个长驻服务拥有独立进程组,退出时可以连同 npm、
|
// POSIX 下让每个长驻服务拥有独立进程组,退出时可以连同 npm、
|
||||||
// Node、Cargo 及其子进程一起清理,避免残留订阅任务持续刷日志。
|
// Node、Cargo 及其子进程一起清理,避免残留订阅任务持续刷日志。
|
||||||
detached: isPosix,
|
detached: isPosix,
|
||||||
@@ -685,18 +452,14 @@ async function terminateChildTree(
|
|||||||
return { stopped: true, forced: false };
|
return { stopped: true, forced: false };
|
||||||
}
|
}
|
||||||
const result = await taskkillImpl(child.pid);
|
const result = await taskkillImpl(child.pid);
|
||||||
const taskkillStopped =
|
return {
|
||||||
!result?.timedOut &&
|
stopped:
|
||||||
!result?.error &&
|
!result?.timedOut &&
|
||||||
[0, 128].includes(result?.code ?? 0);
|
!result?.error &&
|
||||||
if (taskkillStopped) {
|
[0, 128].includes(result?.code ?? 0),
|
||||||
return { stopped: true, forced: true, result };
|
forced: true,
|
||||||
}
|
result,
|
||||||
|
};
|
||||||
// 包装层(cmd.exe / npm.cmd)先被 Ctrl+C 杀掉时 taskkill 拿不到活着的 PID,
|
|
||||||
// 这里继续按记录下来的根 PID 遍历,尽量收掉更深的后端进程。
|
|
||||||
const treeStopped = stopWindowsProcessTree(child.pid);
|
|
||||||
return { stopped: treeStopped.length > 0, forced: true, result };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const processGroupId = childLifecycles.get(child)?.processGroupId;
|
const processGroupId = childLifecycles.get(child)?.processGroupId;
|
||||||
@@ -742,43 +505,11 @@ async function terminateChildTree(
|
|||||||
return { stopped, forced: true };
|
return { stopped, forced: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
async function waitForBackendReady(
|
async function waitForBackendReady(backendChild, timeoutMs = 600_000) {
|
||||||
backendChild,
|
|
||||||
timeoutMs = 600_000,
|
|
||||||
{
|
|
||||||
checkBackendReady = (onOwnershipRejected) =>
|
|
||||||
isBackendReady({ onOwnershipRejected }),
|
|
||||||
readState = () => readJson(devStackStatePath),
|
|
||||||
resolveTargets = readBackendTargets,
|
|
||||||
} = {},
|
|
||||||
) {
|
|
||||||
const initialStateUpdatedAt = readState()?.updatedAt ?? '';
|
|
||||||
const startedAt = Date.now();
|
const startedAt = Date.now();
|
||||||
let lastOwnershipReason = '';
|
|
||||||
while (Date.now() - startedAt < timeoutMs) {
|
while (Date.now() - startedAt < timeoutMs) {
|
||||||
if (
|
if (await isBackendReady()) {
|
||||||
await checkBackendReady((ownership) => {
|
return readBackendTargets();
|
||||||
if (ownership.reason === lastOwnershipReason) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
lastOwnershipReason = ownership.reason;
|
|
||||||
// 本次自己拉起的后端如果归属校验一直不通过,必须把原因打出来,
|
|
||||||
// 否则只会表现为等待 600 秒后超时。
|
|
||||||
console.warn(
|
|
||||||
`[ai-game-creator-shell] 等待配套后端就绪时归属校验未通过(${ownership.reason}: ${formatOwnerLabel(ownership.apiOwner ?? ownership.spacetimeOwner ?? ownership.workerOwner)})。`,
|
|
||||||
);
|
|
||||||
})
|
|
||||||
) {
|
|
||||||
return resolveTargets();
|
|
||||||
}
|
|
||||||
const state = readState();
|
|
||||||
if ((state?.updatedAt ?? '') !== initialStateUpdatedAt) {
|
|
||||||
const serviceFailure = readBackendServiceFailure(state);
|
|
||||||
if (serviceFailure) {
|
|
||||||
throw new Error(
|
|
||||||
`配套后端启动失败: ${serviceFailure.serviceName} ${serviceFailure.failure}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const failure = readChildFailure(backendChild);
|
const failure = readChildFailure(backendChild);
|
||||||
if (failure) {
|
if (failure) {
|
||||||
@@ -794,14 +525,7 @@ async function waitForBackendReady(
|
|||||||
|
|
||||||
async function ensureBackend({
|
async function ensureBackend({
|
||||||
onBackendChild = () => {},
|
onBackendChild = () => {},
|
||||||
checkBackendReady = () =>
|
checkBackendReady = isBackendReady,
|
||||||
isBackendReady({
|
|
||||||
onOwnershipRejected(ownership) {
|
|
||||||
console.warn(
|
|
||||||
`[ai-game-creator-shell] 端口上的配套后端不属于当前工作树(${ownership.reason}: ${formatOwnerLabel(ownership.apiOwner ?? ownership.spacetimeOwner ?? ownership.workerOwner)}),改为启动本工作树自己的后端。`,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
resolveTargets = readBackendTargets,
|
resolveTargets = readBackendTargets,
|
||||||
spawnBackend = () =>
|
spawnBackend = () =>
|
||||||
spawnChild(
|
spawnChild(
|
||||||
@@ -881,33 +605,15 @@ async function startVite(apiTarget, endpoint = readAgcDevEndpoint()) {
|
|||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
let backendChild = null;
|
let backendChild = null;
|
||||||
let startedBackend = false;
|
|
||||||
let viteChild = null;
|
let viteChild = null;
|
||||||
let shutdownSignal = '';
|
let shutdownSignal = '';
|
||||||
const signalHandlers = new Map();
|
const signalHandlers = new Map();
|
||||||
|
|
||||||
// 只有本次会话真正拉起过配套后端时才做兜底清扫:复用别人后端时不能连带
|
|
||||||
// 杀掉对方的进程。dev.mjs 的清理依赖它的 shell 包装层仍然活着,而 Ctrl+C
|
|
||||||
// 往往先杀掉包装层,所以这里必须按本工作树 api-server.exe 的身份再收一次。
|
|
||||||
const sweepStartedBackend = () => {
|
|
||||||
if (!startedBackend || process.platform !== 'win32') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const stopped = stopWindowsWorktreeProcesses({ apiServerExePath });
|
|
||||||
if (stopped.length > 0) {
|
|
||||||
console.log(
|
|
||||||
`[ai-game-creator-shell] 已清理残留后端进程: ${stopped.join(', ')}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
for (const signal of ['SIGINT', 'SIGTERM']) {
|
for (const signal of ['SIGINT', 'SIGTERM']) {
|
||||||
const handler = () => {
|
const handler = () => {
|
||||||
shutdownSignal = signal;
|
shutdownSignal = signal;
|
||||||
stopChild(viteChild, signal);
|
stopChild(viteChild, signal);
|
||||||
stopChild(backendChild, signal);
|
stopChild(backendChild, signal);
|
||||||
// 立刻清扫,避免外层 taskkill /F 抢在 finally 之前把本进程杀掉。
|
|
||||||
sweepStartedBackend();
|
|
||||||
};
|
};
|
||||||
signalHandlers.set(signal, handler);
|
signalHandlers.set(signal, handler);
|
||||||
process.on(signal, handler);
|
process.on(signal, handler);
|
||||||
@@ -926,7 +632,6 @@ async function main() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
backendChild = backend.backendChild;
|
backendChild = backend.backendChild;
|
||||||
startedBackend = Boolean(backendChild);
|
|
||||||
if (shutdownSignal) {
|
if (shutdownSignal) {
|
||||||
throw new Error(`启动期收到 ${shutdownSignal},已停止配套后端`);
|
throw new Error(`启动期收到 ${shutdownSignal},已停止配套后端`);
|
||||||
}
|
}
|
||||||
@@ -960,7 +665,6 @@ async function main() {
|
|||||||
terminateChildTree(viteChild),
|
terminateChildTree(viteChild),
|
||||||
terminateChildTree(backendChild),
|
terminateChildTree(backendChild),
|
||||||
]);
|
]);
|
||||||
sweepStartedBackend();
|
|
||||||
for (const [signal, handler] of signalHandlers) {
|
for (const [signal, handler] of signalHandlers) {
|
||||||
process.off(signal, handler);
|
process.off(signal, handler);
|
||||||
}
|
}
|
||||||
@@ -977,25 +681,19 @@ function isDirectModuleExecution() {
|
|||||||
export {
|
export {
|
||||||
ensureBackend,
|
ensureBackend,
|
||||||
formatChildFailure,
|
formatChildFailure,
|
||||||
formatOwnerLabel,
|
|
||||||
isAiGameCreatorServer,
|
isAiGameCreatorServer,
|
||||||
isBackendReady,
|
isBackendReady,
|
||||||
isDirectModuleExecution,
|
isDirectModuleExecution,
|
||||||
isProcessGroupAlive,
|
isProcessGroupAlive,
|
||||||
isWorktreeApiServerOwner,
|
|
||||||
isWorktreeSpacetimeOwner,
|
|
||||||
preflightExistingVite,
|
preflightExistingVite,
|
||||||
readBackendServiceFailure,
|
|
||||||
readChildFailure,
|
readChildFailure,
|
||||||
readExistingViteServer,
|
readExistingViteServer,
|
||||||
readLinuxProcessGroupAlive,
|
readLinuxProcessGroupAlive,
|
||||||
readWindowsPortOwnerIdentities,
|
|
||||||
resolveBackendTargetsFromState,
|
resolveBackendTargetsFromState,
|
||||||
runWindowsTaskkill,
|
runWindowsTaskkill,
|
||||||
spawnChild,
|
spawnChild,
|
||||||
stopChild,
|
stopChild,
|
||||||
terminateChildTree,
|
terminateChildTree,
|
||||||
verifyAgcBackendOwnership,
|
|
||||||
waitForBackendReady,
|
waitForBackendReady,
|
||||||
waitForChildTermination,
|
waitForChildTermination,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { resolve } from 'node:path';
|
import { resolve } from 'node:path';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
import { withDefaultCargoFeatures } from './cargo-features.mjs';
|
|
||||||
import {
|
import {
|
||||||
readAgcDevEndpoint,
|
readAgcDevEndpoint,
|
||||||
resolveAgcDevEndpoint,
|
resolveAgcDevEndpoint,
|
||||||
@@ -21,10 +20,6 @@ import {
|
|||||||
const appRoot = fileURLToPath(new URL('..', import.meta.url));
|
const appRoot = fileURLToPath(new URL('..', import.meta.url));
|
||||||
const repoRoot = resolve(appRoot, '../..');
|
const repoRoot = resolve(appRoot, '../..');
|
||||||
const tauriCliPath = resolve(repoRoot, 'node_modules/@tauri-apps/cli/tauri.js');
|
const tauriCliPath = resolve(repoRoot, 'node_modules/@tauri-apps/cli/tauri.js');
|
||||||
const AGC_DESIGN_DEBUG_ENV = 'GENARRATIVE_AGC_DESIGN_DEBUG';
|
|
||||||
const AGC_DESIGN_DEBUG_VITE_ENV = 'VITE_GENARRATIVE_AGC_DESIGN_DEBUG';
|
|
||||||
const designDebugEnabled =
|
|
||||||
process.env[AGC_DESIGN_DEBUG_ENV]?.trim() === '0' ? '0' : '1';
|
|
||||||
|
|
||||||
function buildTauriArguments(argv, devUrl = readAgcDevEndpoint().url) {
|
function buildTauriArguments(argv, devUrl = readAgcDevEndpoint().url) {
|
||||||
const args = [...argv];
|
const args = [...argv];
|
||||||
@@ -48,24 +43,6 @@ function buildTauriArguments(argv, devUrl = readAgcDevEndpoint().url) {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// `agc_cocos_execute` 与 Cocos 编辑器适配器只在 `cocos-editor-execute` feature 下
|
|
||||||
// 注册。开发构建默认在 Windows 打开它,否则 Agent 的工具清单里根本没有该工具,
|
|
||||||
// 只能退化成改写脚本。可用 AGC_DEV_CARGO_FEATURES(逗号分隔)覆盖,传空串即关闭。
|
|
||||||
function readDevCargoFeatures(env = process.env) {
|
|
||||||
const override = env.AGC_DEV_CARGO_FEATURES;
|
|
||||||
if (override !== undefined) {
|
|
||||||
return override
|
|
||||||
.split(',')
|
|
||||||
.map((value) => value.trim())
|
|
||||||
.filter(Boolean);
|
|
||||||
}
|
|
||||||
return process.platform === 'win32' ? ['cocos-editor-execute'] : [];
|
|
||||||
}
|
|
||||||
|
|
||||||
function withDevCargoFeatures(argv, features = readDevCargoFeatures()) {
|
|
||||||
return withDefaultCargoFeatures(argv, features);
|
|
||||||
}
|
|
||||||
|
|
||||||
function spawnTauriCli(argv, { env = process.env } = {}) {
|
function spawnTauriCli(argv, { env = process.env } = {}) {
|
||||||
return spawnChild(process.execPath, [tauriCliPath, ...argv], {
|
return spawnChild(process.execPath, [tauriCliPath, ...argv], {
|
||||||
cwd: appRoot,
|
cwd: appRoot,
|
||||||
@@ -129,16 +106,9 @@ async function runTauriDev(
|
|||||||
shutdownRequested.then(() => false),
|
shutdownRequested.then(() => false),
|
||||||
]);
|
]);
|
||||||
if (!prepared || shutdownSignal) return 1;
|
if (!prepared || shutdownSignal) return 1;
|
||||||
const tauriArguments = buildTauriArguments(
|
const tauriArguments = buildTauriArguments(argv, endpoint.url);
|
||||||
withDevCargoFeatures(argv),
|
|
||||||
endpoint.url,
|
|
||||||
);
|
|
||||||
child = spawnCli(tauriArguments, {
|
child = spawnCli(tauriArguments, {
|
||||||
env: {
|
env: withAgcDevEndpointEnv(endpoint),
|
||||||
...withAgcDevEndpointEnv(endpoint),
|
|
||||||
[AGC_DESIGN_DEBUG_ENV]: designDebugEnabled,
|
|
||||||
[AGC_DESIGN_DEBUG_VITE_ENV]: designDebugEnabled,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
const childResult = waitForCli(child);
|
const childResult = waitForCli(child);
|
||||||
const outcome = await Promise.race([
|
const outcome = await Promise.race([
|
||||||
@@ -187,13 +157,7 @@ async function prepareFrontendDev(endpoint, { onChild, signal }) {
|
|||||||
const frontend = spawnChild(
|
const frontend = spawnChild(
|
||||||
process.platform === 'win32' ? 'npm.cmd' : 'npm',
|
process.platform === 'win32' ? 'npm.cmd' : 'npm',
|
||||||
['run', 'agc:serve'],
|
['run', 'agc:serve'],
|
||||||
{
|
{ cwd: repoRoot, env: withAgcDevEndpointEnv(endpoint) },
|
||||||
cwd: repoRoot,
|
|
||||||
env: {
|
|
||||||
...withAgcDevEndpointEnv(endpoint),
|
|
||||||
[AGC_DESIGN_DEBUG_VITE_ENV]: designDebugEnabled,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
onChild(frontend);
|
onChild(frontend);
|
||||||
console.log(
|
console.log(
|
||||||
@@ -229,7 +193,6 @@ export {
|
|||||||
isDirectModuleExecution,
|
isDirectModuleExecution,
|
||||||
runTauriDev,
|
runTauriDev,
|
||||||
spawnTauriCli,
|
spawnTauriCli,
|
||||||
withDevCargoFeatures,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (isDirectModuleExecution()) {
|
if (isDirectModuleExecution()) {
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
# resources/plugins 由 build.rs 从 plugins/ 复制生成,属于构建产物。
|
|
||||||
# 它在 dev 监听范围内,重新生成会让 Tauri dev 误判为源码改动而触发
|
|
||||||
# “构建 -> 监听 -> 再构建”的自触发循环。
|
|
||||||
resources/plugins/
|
|
||||||
+1
-26
@@ -733,20 +733,6 @@ dependencies = [
|
|||||||
"error-code",
|
"error-code",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cocos-editor-bridge"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"cc",
|
|
||||||
"editor-adapter-api",
|
|
||||||
"reqwest 0.12.28",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"sha2",
|
|
||||||
"tungstenite",
|
|
||||||
"windows-sys 0.61.2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "combine"
|
name = "combine"
|
||||||
version = "4.6.7"
|
version = "4.6.7"
|
||||||
@@ -1219,14 +1205,6 @@ version = "1.0.20"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555"
|
checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "editor-adapter-api"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "either"
|
name = "either"
|
||||||
version = "1.16.0"
|
version = "1.16.0"
|
||||||
@@ -1725,14 +1703,12 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "genarrative-ai-game-creator-shell"
|
name = "genarrative-ai-game-creator-shell"
|
||||||
version = "0.1.29"
|
version = "0.1.19"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"agent-runtime-core",
|
"agent-runtime-core",
|
||||||
"axum",
|
"axum",
|
||||||
"base64 0.22.1",
|
"base64 0.22.1",
|
||||||
"chromiumoxide",
|
"chromiumoxide",
|
||||||
"cocos-editor-bridge",
|
|
||||||
"editor-adapter-api",
|
|
||||||
"futures",
|
"futures",
|
||||||
"getrandom 0.3.4",
|
"getrandom 0.3.4",
|
||||||
"http",
|
"http",
|
||||||
@@ -4305,7 +4281,6 @@ dependencies = [
|
|||||||
"cookie",
|
"cookie",
|
||||||
"cookie_store",
|
"cookie_store",
|
||||||
"encoding_rs",
|
"encoding_rs",
|
||||||
"futures-channel",
|
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"h2",
|
"h2",
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "genarrative-ai-game-creator-shell"
|
name = "genarrative-ai-game-creator-shell"
|
||||||
version = "0.1.29"
|
version = "0.1.19"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
cocos-editor = ["cocos-editor-bridge/process-discovery"]
|
|
||||||
cocos-editor-execute = ["cocos-editor", "cocos-editor-bridge/windows-bootstrap"]
|
|
||||||
cocos-editor-injection = ["cocos-editor-execute", "cocos-editor-bridge/windows-injection"]
|
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
@@ -22,8 +19,6 @@ ts-rs = "12.0.1"
|
|||||||
typed_floats = { version = "1.0.7", features = ["serde"] }
|
typed_floats = { version = "1.0.7", features = ["serde"] }
|
||||||
nalgebra = { version = "0.35.0", features = ["serde-serialize"] }
|
nalgebra = { version = "0.35.0", features = ["serde-serialize"] }
|
||||||
agent-runtime-core = { path = "../../../server-rs/crates/agent-runtime-core" }
|
agent-runtime-core = { path = "../../../server-rs/crates/agent-runtime-core" }
|
||||||
cocos-editor-bridge = { path = "../../../plugins/agc-cocos-editor/native/cocos-editor-bridge", default-features = false }
|
|
||||||
editor-adapter-api = { path = "../../../server-rs/crates/editor-adapter-api" }
|
|
||||||
base64 = "0.22"
|
base64 = "0.22"
|
||||||
axum = "0.8"
|
axum = "0.8"
|
||||||
chromiumoxide = "0.9.1"
|
chromiumoxide = "0.9.1"
|
||||||
@@ -79,14 +74,6 @@ codegen-units = 256
|
|||||||
lto = "off"
|
lto = "off"
|
||||||
incremental = true
|
incremental = true
|
||||||
|
|
||||||
# Runner 启动阶段会对当前 Debug 可执行文件计算 SHA-256。仅优化密码学依赖,
|
|
||||||
# 保持业务代码的 Debug 编译速度,同时避免整份 Debug 构建因未优化 hash 热点而阻塞启动。
|
|
||||||
[profile.dev.package.sha2]
|
|
||||||
opt-level = 3
|
|
||||||
|
|
||||||
[profile.dev.package.digest]
|
|
||||||
opt-level = 3
|
|
||||||
|
|
||||||
[profile.test]
|
[profile.test]
|
||||||
opt-level = 0
|
opt-level = 0
|
||||||
debug = 1
|
debug = 1
|
||||||
|
|||||||
@@ -182,8 +182,6 @@ fn main() {
|
|||||||
);
|
);
|
||||||
let manifest_path = manifest_dir.join("prompts/runtime/manifest.json");
|
let manifest_path = manifest_dir.join("prompts/runtime/manifest.json");
|
||||||
stage_bundled_codex_cli(&manifest_dir);
|
stage_bundled_codex_cli(&manifest_dir);
|
||||||
stage_plugin_workspace(&manifest_dir);
|
|
||||||
stage_cocos_editor_payload(&manifest_dir);
|
|
||||||
let compiled = runtime_prompt_bundle::compile_manifest(&manifest_path)
|
let compiled = runtime_prompt_bundle::compile_manifest(&manifest_path)
|
||||||
.unwrap_or_else(|error| panic!("Prompt Bundle 编译失败:{error}"));
|
.unwrap_or_else(|error| panic!("Prompt Bundle 编译失败:{error}"));
|
||||||
validate_seed_task_catalog(&compiled);
|
validate_seed_task_catalog(&compiled);
|
||||||
@@ -205,146 +203,3 @@ fn main() {
|
|||||||
}
|
}
|
||||||
tauri_build::build()
|
tauri_build::build()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
fn stage_cocos_editor_payload(manifest_dir: &std::path::Path) {
|
|
||||||
if std::env::var_os("CARGO_FEATURE_COCOS_EDITOR_INJECTION").is_none() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let out_dir = std::path::PathBuf::from(std::env::var_os("OUT_DIR").expect("OUT_DIR"));
|
|
||||||
let profile_dir = out_dir
|
|
||||||
.ancestors()
|
|
||||||
.find(|path| path.file_name().is_some_and(|name| name == "build"))
|
|
||||||
.and_then(|build_dir| build_dir.parent())
|
|
||||||
.expect("AGC Cargo profile directory not found");
|
|
||||||
let candidates = [
|
|
||||||
profile_dir.join("deps/cocos_editor_bridge.dll"),
|
|
||||||
profile_dir.join("cocos_editor_bridge.dll"),
|
|
||||||
];
|
|
||||||
let source = candidates
|
|
||||||
.iter()
|
|
||||||
.find(|path| path.is_file())
|
|
||||||
.unwrap_or_else(|| {
|
|
||||||
panic!(
|
|
||||||
"Cocos bridge native payload 未构建:{}",
|
|
||||||
candidates
|
|
||||||
.iter()
|
|
||||||
.map(|p| p.display().to_string())
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(";")
|
|
||||||
)
|
|
||||||
});
|
|
||||||
for destination in [
|
|
||||||
// 插件工作区里的 payload 是开发态与打包态的唯一真源。
|
|
||||||
manifest_dir
|
|
||||||
.join("../../../plugins/agc-cocos-editor/native/payload/cocos-editor-bridge.dll"),
|
|
||||||
// 随包资源目录与 tauri.windows.conf.json 的 `resources/plugins` 映射保持一致。
|
|
||||||
manifest_dir
|
|
||||||
.join("resources/plugins/agc-cocos-editor/native/payload/cocos-editor-bridge.dll"),
|
|
||||||
] {
|
|
||||||
std::fs::create_dir_all(destination.parent().expect("payload resource parent"))
|
|
||||||
.expect("创建 Cocos bridge payload 目录失败");
|
|
||||||
std::fs::copy(source, &destination).expect("复制 Cocos bridge native payload 失败");
|
|
||||||
}
|
|
||||||
println!("cargo:rerun-if-changed={}", source.display());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
|
||||||
fn stage_cocos_editor_payload(_manifest_dir: &std::path::Path) {}
|
|
||||||
|
|
||||||
/// 把 `plugins/` 工作区里的插件包随包映射到应用资源目录。
|
|
||||||
///
|
|
||||||
/// 只复制插件运行需要的清单、入口、面板和 native payload,不复制 native 源码、
|
|
||||||
/// Cargo target 目录或 node_modules。
|
|
||||||
#[cfg(windows)]
|
|
||||||
fn stage_plugin_workspace(manifest_dir: &std::path::Path) {
|
|
||||||
let repo_root = manifest_dir
|
|
||||||
.parent()
|
|
||||||
.and_then(|app_root| app_root.parent())
|
|
||||||
.and_then(|apps_dir| apps_dir.parent())
|
|
||||||
.expect("AGC 应用必须位于仓库 apps 目录下")
|
|
||||||
.to_path_buf();
|
|
||||||
let workspace = repo_root.join("plugins");
|
|
||||||
let destination_root = manifest_dir.join("resources/plugins");
|
|
||||||
std::fs::create_dir_all(&destination_root).expect("创建插件资源目录失败");
|
|
||||||
let entries = match std::fs::read_dir(&workspace) {
|
|
||||||
Ok(entries) => entries,
|
|
||||||
Err(_) => return,
|
|
||||||
};
|
|
||||||
for entry in entries.flatten() {
|
|
||||||
let plugin_root = entry.path();
|
|
||||||
if !plugin_root.is_dir() || !plugin_root.join("plugin.json").is_file() {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let name = entry.file_name();
|
|
||||||
let destination = destination_root.join(&name);
|
|
||||||
copy_plugin_file(
|
|
||||||
&plugin_root.join("plugin.json"),
|
|
||||||
&destination.join("plugin.json"),
|
|
||||||
);
|
|
||||||
for relative in [
|
|
||||||
std::path::PathBuf::from("src"),
|
|
||||||
std::path::PathBuf::from("panels"),
|
|
||||||
std::path::PathBuf::from("native/payload"),
|
|
||||||
] {
|
|
||||||
copy_plugin_tree(&plugin_root.join(&relative), &destination.join(&relative));
|
|
||||||
}
|
|
||||||
println!("cargo:rerun-if-changed={}", plugin_root.display());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
fn stage_plugin_file(source: &std::path::Path, destination: &std::path::Path) {
|
|
||||||
let Ok(bytes) = std::fs::read(source) else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
if std::fs::read(destination).is_ok_and(|existing| existing == bytes) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if let Some(parent) = destination.parent() {
|
|
||||||
std::fs::create_dir_all(parent).expect("创建插件资源目录失败");
|
|
||||||
}
|
|
||||||
std::fs::write(destination, bytes).expect("复制插件资源失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
fn copy_plugin_tree(source: &std::path::Path, destination: &std::path::Path) {
|
|
||||||
let entries = match std::fs::read_dir(source) {
|
|
||||||
Ok(entries) => entries,
|
|
||||||
Err(_) => return,
|
|
||||||
};
|
|
||||||
for entry in entries.flatten() {
|
|
||||||
let target = destination.join(entry.file_name());
|
|
||||||
let path = entry.path();
|
|
||||||
if path.is_dir() {
|
|
||||||
let name = entry.file_name();
|
|
||||||
let name = name.to_string_lossy();
|
|
||||||
if matches!(name.as_ref(), "target" | "node_modules" | ".git") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
std::fs::create_dir_all(&target).expect("创建插件资源目录失败");
|
|
||||||
copy_plugin_tree(&path, &target);
|
|
||||||
} else {
|
|
||||||
// 测试文件不随包分发。
|
|
||||||
let name = entry.file_name();
|
|
||||||
let name = name.to_string_lossy();
|
|
||||||
if name.contains(".test.") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
stage_plugin_file(&path, &target);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
fn copy_plugin_file(source: &std::path::Path, destination: &std::path::Path) {
|
|
||||||
if !source.is_file() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
std::fs::create_dir_all(destination.parent().expect("插件资源父目录"))
|
|
||||||
.expect("创建插件资源目录失败");
|
|
||||||
std::fs::copy(source, destination).expect("复制插件资源失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
|
||||||
fn stage_plugin_workspace(_manifest_dir: &std::path::Path) {}
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user