Compare commits
112 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 47c07f9d12 | |||
| 0904184412 | |||
| aaa2eb482a | |||
| 1679e72deb | |||
| 4844543061 | |||
| 99132c9fa7 | |||
| 944d2aa3db | |||
| 7c16a35fda | |||
| e4369cd82e | |||
| 54b9bd4354 | |||
| 365e530b5f | |||
| d46cdfb282 | |||
| 2142027f85 | |||
| 8fdf39f37e | |||
| 70c65c37d5 | |||
| e72637789c | |||
| 0a102ea1c3 | |||
| 1ab7fa9991 | |||
| 6d02a0c29f | |||
| a6c3db60fb | |||
| c921ae3b16 | |||
| 31c084fce6 | |||
| 1e7a3f17ff | |||
| 3ce2977e32 | |||
| f4e9414d63 | |||
| 2d8b51885a | |||
| 91f534ed66 | |||
| f455d3edb2 | |||
| bec225436f | |||
| ce309a3b28 | |||
| abd95a6231 | |||
| 08c3b89b67 | |||
| 3371337346 | |||
| 899a591cda | |||
| 0988c4907a | |||
| d370648867 | |||
| 4f4fb0873c | |||
| 6b8a106414 | |||
| 9a21690fe9 | |||
| deff6319e2 | |||
| 2257a78d6b | |||
| a0f6b7c67d | |||
| ee33af7b75 | |||
| be370cc615 | |||
| 21b059bd41 | |||
| 2d90b73b94 | |||
| cd8f480719 | |||
| 2ffccb844c | |||
| 1bd153d7f2 | |||
| 55a8513de4 | |||
| d986dbaeb0 | |||
| 16c6b9198e | |||
| f5a333b839 | |||
| 20b1fd63de | |||
| 105591bac5 | |||
| da44d66dc8 | |||
| 0a85c4f87e | |||
| efce7b102f | |||
| db5edc948c | |||
| 45c3780bf5 | |||
| 6fcf42e4ac | |||
| e0f9f811b7 | |||
| 03b5c1c9f4 | |||
| 58992330aa | |||
| 2c687b01a4 | |||
| c0e377f479 | |||
| 6001b87215 | |||
| b08ab6ee66 | |||
| 7f80012d7f | |||
| fbe95591d5 | |||
| d222aad2ec | |||
| 13b28ebbc7 | |||
| 30648e6b93 | |||
| 9dd1052374 | |||
| aec9568c39 | |||
| 0a1f0e0b26 | |||
| 5c31ae91ca | |||
| 3ba6168c6a | |||
| 2628b83d4b | |||
| a7b2b0e23b | |||
| ef982fdb78 | |||
| 91b65f94ca | |||
| 70513cf049 | |||
| 87aed0b765 | |||
| 733a7015af | |||
| 4df4708ba1 | |||
| 1e992bcdf8 | |||
| 8368aa262c | |||
| e9ddbf16da | |||
| 22ac1f4c0b | |||
| 9910a0eec0 | |||
| 70981b9ca9 | |||
| 8a0d5600b3 | |||
| 184d88dbb8 | |||
| 791794c0a6 | |||
| 9cfb47d945 | |||
| 27859d3e19 | |||
| 43f3780a38 | |||
| a1f9149c27 | |||
| f0bba18841 | |||
| f679cfa179 | |||
| f68ffcfecd | |||
| ec94a4fe00 | |||
| 46f8592375 | |||
| cdf2882302 | |||
| d156113e71 | |||
| a8f2ac17be | |||
| 43ac9a5761 | |||
| e992e0b35c | |||
| e389b54a3a | |||
| 84c780a6f8 | |||
| 03f900fbe5 |
@@ -1,11 +1,12 @@
|
|||||||
{
|
{
|
||||||
"$schema": "../gen/schemas/desktop-schema.json",
|
"$schema": "../gen/schemas/desktop-schema.json",
|
||||||
"identifier": "main",
|
"identifier": "main",
|
||||||
"description": "AI 游戏创作主窗口允许读取系统剪贴板图片,用于粘贴素材附件;允许弹出原生打开/保存对话框用于素材上传与导出。",
|
"description": "AI 游戏创作主窗口允许读写系统剪贴板,用于粘贴素材附件和复制生成文件路径;允许弹出原生打开/保存对话框用于素材上传与导出。",
|
||||||
"windows": ["client"],
|
"windows": ["client"],
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"clipboard-manager:allow-read-image",
|
"clipboard-manager:allow-read-image",
|
||||||
"clipboard-manager:allow-read-text",
|
"clipboard-manager:allow-read-text",
|
||||||
|
"clipboard-manager:allow-write-text",
|
||||||
"core:image:allow-rgba",
|
"core:image:allow-rgba",
|
||||||
"core:image:allow-size",
|
"core:image:allow-size",
|
||||||
"core:resources:allow-close",
|
"core:resources:allow-close",
|
||||||
|
|||||||
+3
@@ -14,6 +14,9 @@ Implement the user's actual game request in the current project as an npm-manage
|
|||||||
3. Build with the project's npm script before previewing. The playable entry is the package directory's `dist/index.html`; never report an unbuilt bare-module page as playable. Import assets or configure public assets so all runtime media is included in dist; preview and exports cannot read outside it.
|
3. Build with the project's npm script before previewing. The playable entry is the package directory's `dist/index.html`; never report an unbuilt bare-module page as playable. Import assets or configure public assets so all runtime media is included in dist; preview and exports cannot read outside it.
|
||||||
4. Build a complete playable loop: visible objective, responsive input, meaningful state changes, success or failure feedback, and a reliable restart path where the game needs one.
|
4. Build a complete playable loop: visible objective, responsive input, meaningful state changes, success or failure feedback, and a reliable restart path where the game needs one.
|
||||||
5. Fit the active game scene to desktop and mobile viewports without accidental page scrollbars. Reserve deliberate safe space for HUD elements instead of covering interactive content.
|
5. Fit the active game scene to desktop and mobile viewports without accidental page scrollbars. Reserve deliberate safe space for HUD elements instead of covering interactive content.
|
||||||
|
- **画布居中只能由一处负责。** 使用 `Phaser.Scale.FIT` 与 `autoCenter: Phaser.Scale.CENTER_BOTH` 时,canvas 的直接父容器应使用尺寸明确的普通块布局,不再对同一 canvas 叠加 Grid/Flex 居中、`place-items: center`、自动外边距或居中 transform。Phaser 自动计算的 margin 与 CSS 居中叠加会使竖屏画面向右偏移。
|
||||||
|
- 若决定由 CSS 居中,则显式使用 `autoCenter: Phaser.Scale.NO_CENTER`,由 CSS 独立完成定位;外围页面可以继续使用 Grid/Flex,限制只针对同一 canvas 的重复定位。
|
||||||
|
- 出现偏移先检查游戏自身的 CSS 与 Phaser scale 配置,不添加 AGC 预览容器固定偏移补偿。修改布局后重新构建 dist,在桌面、移动及窗口 resize 后检查 canvas 相对游戏父容器居中(误差不超过 1 CSS px)、画面完整且无意外滚动条;不能仅凭 build 成功宣称布局通过。
|
||||||
6. Invoke `taonier-art-assets` for every new game brief that needs visual assets. First reuse suitable registered Taonier art; when the brief's required visual elements are missing or unsuitable, call the reviewed `agc_tools` generation/edit workflow in the same task. After the tool returns, wire its relative paths into the game and verify the rendered result. A game with unused generated assets or placeholder emoji/CSS where requested art should appear is not complete. Load media defensively only for genuinely optional effects, and never relabel a local placeholder as platform art.
|
6. Invoke `taonier-art-assets` for every new game brief that needs visual assets. First reuse suitable registered Taonier art; when the brief's required visual elements are missing or unsuitable, call the reviewed `agc_tools` generation/edit workflow in the same task. After the tool returns, wire its relative paths into the game and verify the rendered result. A game with unused generated assets or placeholder emoji/CSS where requested art should appear is not complete. Load media defensively only for genuinely optional effects, and never relabel a local placeholder as platform art.
|
||||||
7. Let Phaser own the render loop and input dispatch. Avoid duplicate scenes, stale event listeners, and state that survives restart unintentionally.
|
7. Let Phaser own the render loop and input dispatch. Avoid duplicate scenes, stale event listeners, and state that survives restart unintentionally.
|
||||||
8. After a meaningful game change, use the browser playtest Skill and fix issues shown by real evidence before reporting completion.
|
8. After a meaningful game change, use the browser playtest Skill and fix issues shown by real evidence before reporting completion.
|
||||||
|
|||||||
+2
@@ -7,5 +7,7 @@
|
|||||||
- Score, steps, health, timer, or other core state updates consistently.
|
- Score, steps, health, timer, or other core state updates consistently.
|
||||||
- Restart restores all state and does not duplicate timers, animation loops, or event listeners.
|
- Restart restores all state and does not duplicate timers, animation loops, or event listeners.
|
||||||
- Desktop and mobile layouts keep the core scene visible without accidental document scrolling.
|
- Desktop and mobile layouts keep the core scene visible without accidental document scrolling.
|
||||||
|
- 画布的缩放与居中由 Phaser 或 CSS 中的一方独立负责。`FIT + CENTER_BOTH` 不与同一 canvas 父容器的 Grid/Flex 居中、自动外边距或居中 transform 叠加;使用 CSS 居中时关闭 Phaser 自动居中(`NO_CENTER`)。
|
||||||
|
- 在构建后的实际页面检查桌面、移动和 resize:比较 canvas 与游戏父容器的中心,预期居中时水平/垂直误差不超过 1 CSS px,并检查画面没有溢出或意外滚动条。偏移先修游戏 CSS/scale 配置,不用修改 AGC 预览位置掩盖。
|
||||||
- HUD and overlays reserve space and do not cover essential interactive content.
|
- HUD and overlays reserve space and do not cover essential interactive content.
|
||||||
- Requested Taonier art is visibly integrated into the core experience when available.
|
- Requested Taonier art is visibly integrated into the core experience when available.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"schemaVersion": "agc-skill-pack.v1",
|
"schemaVersion": "agc-skill-pack.v1",
|
||||||
"version": "2026-08-26.24",
|
"version": "2026-08-26.25",
|
||||||
"skills": [
|
"skills": [
|
||||||
{
|
{
|
||||||
"name": "agc-game-production-workflow",
|
"name": "agc-game-production-workflow",
|
||||||
@@ -80,7 +80,7 @@
|
|||||||
"agents/openai.yaml",
|
"agents/openai.yaml",
|
||||||
"references/game-quality-checklist.md"
|
"references/game-quality-checklist.md"
|
||||||
],
|
],
|
||||||
"sha256": "05b5cfbf7a40fd303717491f5cea84ff339a73359c9678b283fd54d2b5c45efd"
|
"sha256": "e122d8f3a6d986b594b95c971754d68197bf7896912fa8267d44a7aa129a57ba"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "agc-browser-playtest",
|
"name": "agc-browser-playtest",
|
||||||
|
|||||||
@@ -797,6 +797,16 @@ fn direct_thread_visible_item(
|
|||||||
direct_thread_event_item(root, item)
|
direct_thread_event_item(root, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// AGC 预写的 canonical 用户条目 id:`direct-codex:{clientTurnId}:user`。
|
||||||
|
///
|
||||||
|
/// 与 `direct_project_history::is_direct_project_codex_user_item` 的判据同一份口径(前缀 +
|
||||||
|
/// `:user` 后缀)。回合生命周期事件的 `userItemId` 只能来自这里或已落盘条目自身的 id;
|
||||||
|
/// clientTurnId 缺失时不猜身份,返回 `None` 让前端按"未知归属"处理。
|
||||||
|
fn direct_codex_user_item_id_for_client_turn_id(client_turn_id: &str) -> Option<String> {
|
||||||
|
let client_turn_id = client_turn_id.trim();
|
||||||
|
(!client_turn_id.is_empty()).then(|| format!("direct-codex:{client_turn_id}:user"))
|
||||||
|
}
|
||||||
|
|
||||||
fn direct_codex_command_is_game_verification(command: &str) -> bool {
|
fn direct_codex_command_is_game_verification(command: &str) -> bool {
|
||||||
let command = command.to_ascii_lowercase();
|
let command = command.to_ascii_lowercase();
|
||||||
command.contains("game.static_smoke")
|
command.contains("game.static_smoke")
|
||||||
@@ -2927,7 +2937,7 @@ impl CodexAppServerConnection {
|
|||||||
None => direct_project_local_message_item(
|
None => direct_project_local_message_item(
|
||||||
"user",
|
"user",
|
||||||
current_prompt,
|
current_prompt,
|
||||||
Some(&format!("direct-codex:{client_turn_id}:user")),
|
direct_codex_user_item_id_for_client_turn_id(client_turn_id).as_deref(),
|
||||||
)
|
)
|
||||||
.map_err(platform_llm::LlmError::InvalidRequest)?,
|
.map_err(platform_llm::LlmError::InvalidRequest)?,
|
||||||
};
|
};
|
||||||
@@ -3046,13 +3056,30 @@ impl CodexAppServerConnection {
|
|||||||
};
|
};
|
||||||
turn_start_guard.armed = false;
|
turn_start_guard.armed = false;
|
||||||
let direct_thread_id = direct_thread_id_for_project(history_root);
|
let direct_thread_id = direct_thread_id_for_project(history_root);
|
||||||
|
// 回合边界的阶段时间:Turn 上游只有**秒**级 `startedAt` / `completedAt`,秒级截断
|
||||||
|
// 撑不起前端 0.1 秒粒度的展示,也可能让完成时刻落进该轮用户消息的同一秒、落在真实
|
||||||
|
// 发送时间之前,被判成无效边界后整轮新回合被吞掉。因此这里只在宿主处理对应阶段时取
|
||||||
|
// 毫秒钟(与条目侧"没有原生阶段时间就用宿主钟"同一口径),不再读上游秒字段。
|
||||||
|
let direct_turn_started_at_ms = direct_tool_call_now_ms();
|
||||||
|
// 本轮开口用户条目的 canonical id:只从已落盘的那条条目上读身份(`id`,工具条目才用
|
||||||
|
// `call_id`),不在事件侧重造一份。拿不到就留空,让前端按"归属不可证明"处理。
|
||||||
|
let direct_turn_user_item_id = direct_persisted_user_item
|
||||||
|
.as_ref()
|
||||||
|
.and_then(direct_thread_item_identity);
|
||||||
if self.inner.workspace_mode == CodexAppServerWorkspaceMode::DirectProject {
|
if self.inner.workspace_mode == CodexAppServerWorkspaceMode::DirectProject {
|
||||||
append_direct_thread_event(&direct_thread_id, DirectThreadEvent::turn_started());
|
append_direct_thread_event(
|
||||||
|
&direct_thread_id,
|
||||||
|
DirectThreadEvent::turn_started(direct_turn_started_at_ms)
|
||||||
|
.with_user_item_id(direct_turn_user_item_id.as_deref()),
|
||||||
|
);
|
||||||
if let Some(user_item) = direct_persisted_user_item.as_ref() {
|
if let Some(user_item) = direct_persisted_user_item.as_ref() {
|
||||||
if let Some(entry_item) = direct_thread_event_item(history_root, user_item) {
|
if let Some(entry_item) = direct_thread_event_item(history_root, user_item) {
|
||||||
|
// 这里的条目时间可能是启动应答后的观测时间;前端按同一用户条目身份
|
||||||
|
// 保留更早的真实发送时间,不用此事件时间覆盖它。
|
||||||
|
let user_item_at = entry_item.at();
|
||||||
append_direct_thread_event(
|
append_direct_thread_event(
|
||||||
&direct_thread_id,
|
&direct_thread_id,
|
||||||
DirectThreadEvent::item_completed(entry_item),
|
DirectThreadEvent::item_completed(entry_item, user_item_at),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3191,9 +3218,14 @@ impl CodexAppServerConnection {
|
|||||||
.map_err(platform_llm::LlmError::InvalidRequest)?;
|
.map_err(platform_llm::LlmError::InvalidRequest)?;
|
||||||
direct_project_history.complete_item(&item);
|
direct_project_history.complete_item(&item);
|
||||||
if let Some(entry_item) = entry_item {
|
if let Some(entry_item) = entry_item {
|
||||||
|
// `rawResponseItem/completed` 不带阶段时间,宿主处理到这条
|
||||||
|
// 通知的钟就是该阶段唯一可证明的时间。
|
||||||
append_direct_thread_event(
|
append_direct_thread_event(
|
||||||
&direct_thread_id,
|
&direct_thread_id,
|
||||||
DirectThreadEvent::item_completed(entry_item),
|
DirectThreadEvent::item_completed(
|
||||||
|
entry_item,
|
||||||
|
direct_tool_call_now_ms(),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3322,9 +3354,19 @@ impl CodexAppServerConnection {
|
|||||||
if let Some(entry_item) =
|
if let Some(entry_item) =
|
||||||
direct_thread_visible_item(history_root, item)
|
direct_thread_visible_item(history_root, item)
|
||||||
{
|
{
|
||||||
|
// `item/started` 的通知层带 `startedAtMs`:这是工具真正
|
||||||
|
// 开始的阶段时间,优先于条目展示时间与宿主钟。
|
||||||
append_direct_thread_event(
|
append_direct_thread_event(
|
||||||
&direct_thread_id,
|
&direct_thread_id,
|
||||||
DirectThreadEvent::item_started(entry_item),
|
DirectThreadEvent::item_started(
|
||||||
|
entry_item,
|
||||||
|
direct_thread_item_event_at_ms(
|
||||||
|
¶ms,
|
||||||
|
item,
|
||||||
|
false,
|
||||||
|
direct_tool_call_now_ms(),
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3367,9 +3409,19 @@ impl CodexAppServerConnection {
|
|||||||
&& matches!(status, "completed" | "interrupted" | "failed")
|
&& matches!(status, "completed" | "interrupted" | "failed")
|
||||||
{
|
{
|
||||||
terminal_recorded = true;
|
terminal_recorded = true;
|
||||||
|
// 终态时间:`durationMs` 与宿主记下的毫秒起点都可靠时才派生,
|
||||||
|
// 否则取宿主处理这条终态的钟;上游秒级 `completedAt` 一律不用。
|
||||||
append_direct_thread_event(
|
append_direct_thread_event(
|
||||||
&direct_thread_id,
|
&direct_thread_id,
|
||||||
DirectThreadEvent::turn_completed(status.to_string()),
|
DirectThreadEvent::turn_completed(
|
||||||
|
status.to_string(),
|
||||||
|
direct_thread_turn_completed_at_ms(
|
||||||
|
turn,
|
||||||
|
Some(direct_turn_started_at_ms),
|
||||||
|
direct_tool_call_now_ms(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.with_user_item_id(direct_turn_user_item_id.as_deref()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
match status {
|
match status {
|
||||||
@@ -3426,7 +3478,11 @@ impl CodexAppServerConnection {
|
|||||||
"failed"
|
"failed"
|
||||||
}
|
}
|
||||||
.to_string(),
|
.to_string(),
|
||||||
),
|
// 这条兜底终态没有对应的 app-server 终态载荷,只能取宿主处理它的钟,
|
||||||
|
// 不能拿最后一次正文或工具更新时间当回合终点。
|
||||||
|
direct_tool_call_now_ms(),
|
||||||
|
)
|
||||||
|
.with_user_item_id(direct_turn_user_item_id.as_deref()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
let text = match collect_result {
|
let text = match collect_result {
|
||||||
@@ -3624,6 +3680,15 @@ enum DirectCodexTurnCancelTarget {
|
|||||||
/// 这时显式释放这条守卫并把可读原因返回给界面。释放条件见
|
/// 这时显式释放这条守卫并把可读原因返回给界面。释放条件见
|
||||||
/// [`release_stale_direct_taonier_active_invocation`] 的注释;"正在跑的是另一轮"仍然
|
/// [`release_stale_direct_taonier_active_invocation`] 的注释;"正在跑的是另一轮"仍然
|
||||||
/// 保持原拒绝语义,什么都不释放。
|
/// 保持原拒绝语义,什么都不释放。
|
||||||
|
///
|
||||||
|
/// 兜底终态带 `userItemId`:身份取 `release_stale_direct_taonier_active_invocation` 返回的
|
||||||
|
/// clientTurnId(客户端回合身份的唯一来源),与正常路径的开口条目 id 同一份 canonical 口径。
|
||||||
|
/// 拿不到 clientTurnId 就留空——这一轮不会再有原生终态,猜一个身份会让前端把边界盖到别人身上。
|
||||||
|
fn direct_stale_cancel_turn_completed_event(client_turn_id: &str) -> DirectThreadEvent {
|
||||||
|
DirectThreadEvent::turn_completed("aborted".to_string(), direct_tool_call_now_ms())
|
||||||
|
.with_user_item_id(direct_codex_user_item_id_for_client_turn_id(client_turn_id).as_deref())
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn cancel_direct_codex_turn_at(
|
pub(crate) fn cancel_direct_codex_turn_at(
|
||||||
root: &Path,
|
root: &Path,
|
||||||
client_turn_id: Option<&str>,
|
client_turn_id: Option<&str>,
|
||||||
@@ -3680,7 +3745,7 @@ pub(crate) fn cancel_direct_codex_turn_at(
|
|||||||
// 兜底补一条,否则前端的"最新回合是否在跑"会永远停在运行中。
|
// 兜底补一条,否则前端的"最新回合是否在跑"会永远停在运行中。
|
||||||
append_direct_thread_event(
|
append_direct_thread_event(
|
||||||
&direct_thread_id_for_project(root),
|
&direct_thread_id_for_project(root),
|
||||||
DirectThreadEvent::turn_completed("aborted".to_string()),
|
direct_stale_cancel_turn_completed_event(&released),
|
||||||
);
|
);
|
||||||
Ok(DirectTurnCancelView {
|
Ok(DirectTurnCancelView {
|
||||||
outcome: DIRECT_TURN_CANCEL_OUTCOME_RELEASED.to_string(),
|
outcome: DIRECT_TURN_CANCEL_OUTCOME_RELEASED.to_string(),
|
||||||
@@ -5006,6 +5071,109 @@ mod tests {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 阶段时间取自**通知层**字段,形状照抄 codex-cli 0.147 / 0.155 的 v2 协议 schema:
|
||||||
|
/// `item/started` 带 `startedAtMs`、`item/completed` 带 `completedAtMs`(毫秒),
|
||||||
|
/// `turn/completed` 带 `turn.startedAt` / `turn.completedAt`(秒)与 `turn.durationMs`(毫秒)。
|
||||||
|
/// 分类函数把 params 原样交给事件级 `at` 的投影函数,所以字段位置必须在这里钉住;
|
||||||
|
/// 回合边界的秒字段按"不用"锁在这里,避免以后有人再把秒级截断当 0.1 秒精度。
|
||||||
|
#[test]
|
||||||
|
fn direct_lifecycle_stage_times_come_from_notification_params() {
|
||||||
|
let started = serde_json::json!({
|
||||||
|
"threadId": "thread-1",
|
||||||
|
"turnId": "turn-1",
|
||||||
|
"startedAtMs": 1_700_000_000_123u64,
|
||||||
|
"item": {"id": "call-1", "type": "commandExecution", "command": "ls"},
|
||||||
|
});
|
||||||
|
let completed = serde_json::json!({
|
||||||
|
"threadId": "thread-1",
|
||||||
|
"turnId": "turn-1",
|
||||||
|
"completedAtMs": 1_700_000_001_500u64,
|
||||||
|
"item": {"id": "call-1", "type": "commandExecution", "command": "ls"},
|
||||||
|
});
|
||||||
|
for (method, params, expected_at_ms) in [
|
||||||
|
("item/started", &started, 1_700_000_000_123u64),
|
||||||
|
("item/completed", &completed, 1_700_000_001_500u64),
|
||||||
|
] {
|
||||||
|
let Some(CodexTurnEvent::Item {
|
||||||
|
completed,
|
||||||
|
params: event_params,
|
||||||
|
}) = direct_codex_notification_event(method, params, None, None, "turn-1")
|
||||||
|
else {
|
||||||
|
panic!("{method} 必须分类成条目生命周期事件");
|
||||||
|
};
|
||||||
|
let item = event_params.get("item").expect("item payload");
|
||||||
|
assert_eq!(
|
||||||
|
direct_thread_item_event_at_ms(&event_params, item, completed, 9_999),
|
||||||
|
expected_at_ms,
|
||||||
|
"{method} 必须用通知层的阶段时间,而不是宿主钟"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let terminal = serde_json::json!({
|
||||||
|
"threadId": "thread-1",
|
||||||
|
"turn": {
|
||||||
|
"id": "turn-1",
|
||||||
|
"items": [],
|
||||||
|
"status": "completed",
|
||||||
|
"startedAt": 1_700_000_000i64,
|
||||||
|
"completedAt": 1_700_000_042i64,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
let Some(CodexTurnEvent::Terminal(params)) =
|
||||||
|
direct_codex_notification_event("turn/completed", &terminal, None, None, "turn-1")
|
||||||
|
else {
|
||||||
|
panic!("turn/completed 必须分类成终态事件");
|
||||||
|
};
|
||||||
|
let turn = params.get("turn").unwrap_or(¶ms);
|
||||||
|
assert_eq!(
|
||||||
|
direct_thread_turn_completed_at_ms(turn, Some(1_700_000_000_500), 9_999),
|
||||||
|
9_999,
|
||||||
|
"上游只有秒级 completedAt:不采用,取宿主处理终态的毫秒钟"
|
||||||
|
);
|
||||||
|
let with_duration = serde_json::json!({
|
||||||
|
"id": "turn-1",
|
||||||
|
"items": [],
|
||||||
|
"status": "completed",
|
||||||
|
"startedAt": 1_700_000_000i64,
|
||||||
|
"completedAt": 1_700_000_042i64,
|
||||||
|
"durationMs": 42_500u64,
|
||||||
|
});
|
||||||
|
assert_eq!(
|
||||||
|
direct_thread_turn_completed_at_ms(&with_duration, Some(1_700_000_000_500), 9_999),
|
||||||
|
1_700_000_043_000,
|
||||||
|
"durationMs + 宿主高精度起点才派生结束"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 取消兜底终态也要带开口用户条目身份,且身份只有一个来源:release 返回的 clientTurnId
|
||||||
|
/// 走与正常路径同一份 canonical 口径;拿不到(空 / 空白)就留空,不猜。
|
||||||
|
#[test]
|
||||||
|
fn stale_cancel_terminal_event_keeps_opener_user_item_id_from_client_turn_id() {
|
||||||
|
let event = direct_stale_cancel_turn_completed_event("turn-0001");
|
||||||
|
assert_eq!(event.user_item_id(), Some("direct-codex:turn-0001:user"));
|
||||||
|
assert!(event.at().is_some(), "兜底终态仍要带宿主观测时间");
|
||||||
|
assert!(matches!(
|
||||||
|
event,
|
||||||
|
DirectThreadEvent::TurnCompleted { ref status, .. } if status == "aborted"
|
||||||
|
));
|
||||||
|
|
||||||
|
for missing in ["", " "] {
|
||||||
|
let event = direct_stale_cancel_turn_completed_event(missing);
|
||||||
|
assert_eq!(
|
||||||
|
event.user_item_id(),
|
||||||
|
None,
|
||||||
|
"拿不到 clientTurnId 时不得编造开口条目身份"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// canonical 口径与落盘侧同一份:`direct-codex:{clientTurnId}:user`。
|
||||||
|
assert_eq!(
|
||||||
|
direct_codex_user_item_id_for_client_turn_id(" turn-0001 ").as_deref(),
|
||||||
|
Some("direct-codex:turn-0001:user")
|
||||||
|
);
|
||||||
|
assert_eq!(direct_codex_user_item_id_for_client_turn_id(""), None);
|
||||||
|
}
|
||||||
|
|
||||||
fn test_llm() -> GameCreatorLlmConfig {
|
fn test_llm() -> GameCreatorLlmConfig {
|
||||||
GameCreatorLlmConfig {
|
GameCreatorLlmConfig {
|
||||||
custom_enabled: false,
|
custom_enabled: false,
|
||||||
@@ -6740,12 +6908,33 @@ done
|
|||||||
|
|
||||||
let consumed = crate::agent::consume_direct_thread(&bootstrap.subscription_id)
|
let consumed = crate::agent::consume_direct_thread(&bootstrap.subscription_id)
|
||||||
.expect("consume events");
|
.expect("consume events");
|
||||||
|
// 回合起止必须与开口用户条目同源:前端在「只有锚点 + 历史、运行态为空」的回合里靠这个
|
||||||
|
// 身份把边界认领给同一条用户条目,缺了它就只能隐藏未知用时。
|
||||||
|
let lifecycle_user_item_ids = consumed
|
||||||
|
.events
|
||||||
|
.iter()
|
||||||
|
.filter(|event| {
|
||||||
|
matches!(
|
||||||
|
event,
|
||||||
|
DirectThreadEvent::TurnStarted { .. } | DirectThreadEvent::TurnCompleted { .. }
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.map(DirectThreadEvent::user_item_id)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
assert_eq!(
|
||||||
|
lifecycle_user_item_ids,
|
||||||
|
vec![
|
||||||
|
Some("direct-codex:turn-0001:user"),
|
||||||
|
Some("direct-codex:turn-0001:user"),
|
||||||
|
],
|
||||||
|
"turn.started / turn.completed 都要带本轮开口用户条目的 canonical itemId"
|
||||||
|
);
|
||||||
let mut user_items = Vec::new();
|
let mut user_items = Vec::new();
|
||||||
let mut assistant_items = Vec::new();
|
let mut assistant_items = Vec::new();
|
||||||
for event in &consumed.events {
|
for event in &consumed.events {
|
||||||
let item = match event {
|
let item = match event {
|
||||||
DirectThreadEvent::ItemStarted { item }
|
DirectThreadEvent::ItemStarted { item, .. }
|
||||||
| DirectThreadEvent::ItemCompleted { item } => item,
|
| DirectThreadEvent::ItemCompleted { item, .. } => item,
|
||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
match item {
|
match item {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -427,12 +427,16 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 事件级阶段时间只在重放稳定性用例里逐个指定;其余用例用一个固定值即可,
|
||||||
|
/// 它们断言的是队列 / 游标语义,不是时间本身。
|
||||||
|
const FIXED_AT_MS: u64 = 1_000;
|
||||||
|
|
||||||
fn item_started(item_id: &str) -> DirectThreadEvent {
|
fn item_started(item_id: &str) -> DirectThreadEvent {
|
||||||
DirectThreadEvent::item_started(message(item_id))
|
DirectThreadEvent::item_started(message(item_id), FIXED_AT_MS)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn item_completed(item_id: &str) -> DirectThreadEvent {
|
fn item_completed(item_id: &str) -> DirectThreadEvent {
|
||||||
DirectThreadEvent::item_completed(message(item_id))
|
DirectThreadEvent::item_completed(message(item_id), FIXED_AT_MS)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn item_delta(item_id: &str) -> DirectThreadEvent {
|
fn item_delta(item_id: &str) -> DirectThreadEvent {
|
||||||
@@ -450,7 +454,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn subscribers_have_independent_cursors_on_one_global_queue() {
|
fn subscribers_have_independent_cursors_on_one_global_queue() {
|
||||||
let mut manager = DirectThreadManager::with_limits(100, 100_000);
|
let mut manager = DirectThreadManager::with_limits(100, 100_000);
|
||||||
manager.append("thread-1", DirectThreadEvent::turn_started());
|
manager.append("thread-1", DirectThreadEvent::turn_started(FIXED_AT_MS));
|
||||||
let first = manager.subscribe("thread-1");
|
let first = manager.subscribe("thread-1");
|
||||||
let second = manager.subscribe("thread-1");
|
let second = manager.subscribe("thread-1");
|
||||||
manager.append("thread-1", item_started("item-1"));
|
manager.append("thread-1", item_started("item-1"));
|
||||||
@@ -474,7 +478,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn bootstrap_contains_lifecycle_anchor_and_unfinished_events_only() {
|
fn bootstrap_contains_lifecycle_anchor_and_unfinished_events_only() {
|
||||||
let mut manager = DirectThreadManager::with_limits(100, 100_000);
|
let mut manager = DirectThreadManager::with_limits(100, 100_000);
|
||||||
manager.append("thread-1", DirectThreadEvent::turn_started());
|
manager.append("thread-1", DirectThreadEvent::turn_started(FIXED_AT_MS));
|
||||||
manager.append("thread-1", item_started("item-1"));
|
manager.append("thread-1", item_started("item-1"));
|
||||||
manager.append("thread-1", item_delta("item-1"));
|
manager.append("thread-1", item_delta("item-1"));
|
||||||
manager.append("thread-1", item_completed("item-1"));
|
manager.append("thread-1", item_completed("item-1"));
|
||||||
@@ -484,7 +488,7 @@ mod tests {
|
|||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
bootstrap.events.as_slice(),
|
bootstrap.events.as_slice(),
|
||||||
[
|
[
|
||||||
DirectThreadEvent::TurnStarted {},
|
DirectThreadEvent::TurnStarted { .. },
|
||||||
DirectThreadEvent::ItemStarted { item, .. },
|
DirectThreadEvent::ItemStarted { item, .. },
|
||||||
] if item.item_id() == "item-2"
|
] if item.item_id() == "item-2"
|
||||||
));
|
));
|
||||||
@@ -589,15 +593,118 @@ mod tests {
|
|||||||
let mut manager = DirectThreadManager::with_limits(100, 100_000);
|
let mut manager = DirectThreadManager::with_limits(100, 100_000);
|
||||||
manager.append(
|
manager.append(
|
||||||
"thread-1",
|
"thread-1",
|
||||||
DirectThreadEvent::turn_completed("completed".to_string()),
|
DirectThreadEvent::turn_completed("completed".to_string(), FIXED_AT_MS),
|
||||||
);
|
);
|
||||||
let bootstrap = manager.subscribe("thread-1");
|
let bootstrap = manager.subscribe("thread-1");
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
bootstrap.events.as_slice(),
|
bootstrap.events.as_slice(),
|
||||||
[DirectThreadEvent::TurnCompleted { status }] if status == "completed"
|
[DirectThreadEvent::TurnCompleted { status, at, .. }]
|
||||||
|
if status == "completed" && *at == Some(FIXED_AT_MS)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 阶段时间必须随事件一起进队列:bootstrap 与重复订阅都拿到**原值**,
|
||||||
|
/// 重放不得重新取钟(否则每次重连都会把已固定的起止时间改掉)。
|
||||||
|
#[test]
|
||||||
|
fn replayed_events_keep_their_original_stage_time() {
|
||||||
|
let mut manager = DirectThreadManager::with_limits(100, 100_000);
|
||||||
|
manager.append("thread-1", DirectThreadEvent::turn_started(1_000));
|
||||||
|
manager.append(
|
||||||
|
"thread-1",
|
||||||
|
DirectThreadEvent::item_started(message("item-1"), 2_000),
|
||||||
|
);
|
||||||
|
|
||||||
|
let first = manager.subscribe("thread-1");
|
||||||
|
assert_eq!(
|
||||||
|
first
|
||||||
|
.events
|
||||||
|
.iter()
|
||||||
|
.map(DirectThreadEvent::at)
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
vec![Some(1_000), Some(2_000)]
|
||||||
|
);
|
||||||
|
|
||||||
|
// 第二个订阅看到的是同一份事件,时间不因"又取了一次当前时间"而漂移。
|
||||||
|
let second = manager.subscribe("thread-1");
|
||||||
|
assert_eq!(second.events, first.events);
|
||||||
|
|
||||||
|
manager.append(
|
||||||
|
"thread-1",
|
||||||
|
DirectThreadEvent::item_completed(message("item-1"), 3_000),
|
||||||
|
);
|
||||||
|
let completion = manager
|
||||||
|
.consume(&first.subscription_id)
|
||||||
|
.expect("consume completion")
|
||||||
|
.events;
|
||||||
|
assert_eq!(
|
||||||
|
completion
|
||||||
|
.iter()
|
||||||
|
.map(DirectThreadEvent::at)
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
vec![Some(3_000)]
|
||||||
|
);
|
||||||
|
// 重复消费不产生新事件,也不改写已下发过的时间。
|
||||||
|
assert!(manager
|
||||||
|
.consume(&first.subscription_id)
|
||||||
|
.expect("empty consume")
|
||||||
|
.events
|
||||||
|
.is_empty());
|
||||||
|
assert_eq!(
|
||||||
|
completion
|
||||||
|
.iter()
|
||||||
|
.map(DirectThreadEvent::at)
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
vec![Some(3_000)]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 生命周期锚点重放时必须带上开口用户条目身份:前端在「只有锚点 + 历史切片、运行态一直空」
|
||||||
|
/// 的回合里也要能把边界认领给同一条用户条目,而不是按时间戳猜。
|
||||||
|
#[test]
|
||||||
|
fn bootstrap_replays_opener_user_item_id() {
|
||||||
|
let mut manager = DirectThreadManager::with_limits(100, 100_000);
|
||||||
|
manager.append(
|
||||||
|
"thread-1",
|
||||||
|
DirectThreadEvent::turn_started(1_000)
|
||||||
|
.with_user_item_id(Some("direct-codex:turn-1:user")),
|
||||||
|
);
|
||||||
|
let bootstrap = manager.subscribe("thread-1");
|
||||||
|
assert_eq!(
|
||||||
|
bootstrap
|
||||||
|
.events
|
||||||
|
.iter()
|
||||||
|
.map(DirectThreadEvent::user_item_id)
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
vec![Some("direct-codex:turn-1:user")]
|
||||||
|
);
|
||||||
|
assert_eq!(bootstrap.events[0].at(), Some(1_000));
|
||||||
|
|
||||||
|
// 锚点是独立保存的副本:队列里那条事件被回收之后,新订阅仍拿到同一个身份。
|
||||||
|
manager
|
||||||
|
.consume(&bootstrap.subscription_id)
|
||||||
|
.expect("consume anchor");
|
||||||
|
manager.append(
|
||||||
|
"thread-1",
|
||||||
|
DirectThreadEvent::item_completed(message("item-1"), 2_000),
|
||||||
|
);
|
||||||
|
manager.append(
|
||||||
|
"thread-1",
|
||||||
|
DirectThreadEvent::turn_completed("completed".to_string(), 3_000)
|
||||||
|
.with_user_item_id(Some("direct-codex:turn-1:user")),
|
||||||
|
);
|
||||||
|
let second = manager.subscribe("thread-1");
|
||||||
|
assert_eq!(
|
||||||
|
second
|
||||||
|
.events
|
||||||
|
.iter()
|
||||||
|
.map(DirectThreadEvent::user_item_id)
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
vec![Some("direct-codex:turn-1:user")],
|
||||||
|
"起止同源:终态锚点也带同一个开口用户条目身份"
|
||||||
|
);
|
||||||
|
assert_eq!(second.events[0].at(), Some(3_000));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn queue_cleanup_only_removes_a_cleanable_prefix() {
|
fn queue_cleanup_only_removes_a_cleanable_prefix() {
|
||||||
let mut manager = DirectThreadManager::with_limits(100, 100_000);
|
let mut manager = DirectThreadManager::with_limits(100, 100_000);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -2391,6 +2391,8 @@ async fn bridge_generate_image(state: &DirectToolBridgeState, arguments: &Value)
|
|||||||
slice_mode,
|
slice_mode,
|
||||||
grid_x,
|
grid_x,
|
||||||
grid_y,
|
grid_y,
|
||||||
|
reference_asset_ids: Vec::new(),
|
||||||
|
target_category: None,
|
||||||
screen_color,
|
screen_color,
|
||||||
};
|
};
|
||||||
let _generation_guard = state.image_generation_gate.lock().await;
|
let _generation_guard = state.image_generation_gate.lock().await;
|
||||||
|
|||||||
@@ -67,10 +67,11 @@ pub(crate) use canvas_generation::{
|
|||||||
generate_platform_art_asset_with_options_at,
|
generate_platform_art_asset_with_options_at,
|
||||||
generate_platform_art_asset_with_required_slices_at, maybe_generate_platform_art_asset_step,
|
generate_platform_art_asset_with_required_slices_at, maybe_generate_platform_art_asset_step,
|
||||||
needs_platform_art_asset_generation, normalize_platform_art_asset_generation_kind,
|
needs_platform_art_asset_generation, normalize_platform_art_asset_generation_kind,
|
||||||
|
normalize_platform_art_reference_asset_ids, normalize_platform_art_target_category,
|
||||||
platform_art_asset_art_spec, platform_art_asset_output_extension_matches,
|
platform_art_asset_art_spec, platform_art_asset_output_extension_matches,
|
||||||
prepare_platform_art_asset_output_path, project_canvas_asset_media_types,
|
platform_art_runtime_references_match_request_contract, prepare_platform_art_asset_output_path,
|
||||||
role_has_canvas_assets, suggested_canvas_tool_call, PlatformArtAssetGenerationOptions,
|
project_canvas_asset_media_types, role_has_canvas_assets, suggested_canvas_tool_call,
|
||||||
PLATFORM_ART_ASSET_GENERATION_KINDS,
|
PlatformArtAssetGenerationOptions, PLATFORM_ART_ASSET_GENERATION_KINDS,
|
||||||
};
|
};
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
pub(crate) use draft_validation::{
|
pub(crate) use draft_validation::{
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -577,6 +577,8 @@ pub(in crate::agent) async fn observe_agent_runtime_platform_art_asset_generatio
|
|||||||
slice_mode: (!slice_mode.trim().is_empty()).then_some(slice_mode.clone()),
|
slice_mode: (!slice_mode.trim().is_empty()).then_some(slice_mode.clone()),
|
||||||
grid_x,
|
grid_x,
|
||||||
grid_y,
|
grid_y,
|
||||||
|
reference_asset_ids: Vec::new(),
|
||||||
|
target_category: None,
|
||||||
screen_color: None,
|
screen_color: None,
|
||||||
};
|
};
|
||||||
if let Some(pending) = pending_action {
|
if let Some(pending) = pending_action {
|
||||||
@@ -629,6 +631,9 @@ pub(in crate::agent) async fn observe_agent_runtime_platform_art_asset_generatio
|
|||||||
.or_else(|| (!slice_mode.trim().is_empty()).then_some(slice_mode)),
|
.or_else(|| (!slice_mode.trim().is_empty()).then_some(slice_mode)),
|
||||||
grid_x,
|
grid_x,
|
||||||
grid_y,
|
grid_y,
|
||||||
|
reference_asset_ids: requested_options.reference_asset_ids,
|
||||||
|
// Agent 运行时不会指定完成登记的目标栏目,保持调用方给的值(默认 `None`)。
|
||||||
|
target_category: requested_options.target_category,
|
||||||
screen_color: requested_options.screen_color,
|
screen_color: requested_options.screen_color,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -390,6 +390,12 @@ pub(crate) async fn start_local_project_asset_generation(
|
|||||||
image_size: Option<String>,
|
image_size: Option<String>,
|
||||||
asset_name: Option<String>,
|
asset_name: Option<String>,
|
||||||
output_path: Option<String>,
|
output_path: Option<String>,
|
||||||
|
// 前端 IPC 字段 `referenceAssetIds`:当前项目 manifest 里的图片素材 id,只做参考输入,
|
||||||
|
// 不进任务账本(重试由调用方继续用同一份引用提交,账本本身不新增字段)。
|
||||||
|
reference_asset_ids: Option<Vec<String>>,
|
||||||
|
// 前端 IPC 字段 `targetCategory`:完成登记时要落盘的正式栏目分类。同样不进任务账本:
|
||||||
|
// 它与引用一样属于「同一次提交的本地落点」,重试由调用方继续用同一个栏目提交。
|
||||||
|
target_category: Option<String>,
|
||||||
) -> Result<AssetGenerationTaskRecord, String> {
|
) -> Result<AssetGenerationTaskRecord, String> {
|
||||||
let task_id = asset_generation_task_id(&task_id)?;
|
let task_id = asset_generation_task_id(&task_id)?;
|
||||||
let request = prepare_local_project_asset_generation(
|
let request = prepare_local_project_asset_generation(
|
||||||
@@ -400,6 +406,8 @@ pub(crate) async fn start_local_project_asset_generation(
|
|||||||
image_size.as_deref(),
|
image_size.as_deref(),
|
||||||
asset_name.as_deref(),
|
asset_name.as_deref(),
|
||||||
output_path.as_deref(),
|
output_path.as_deref(),
|
||||||
|
reference_asset_ids.as_deref().unwrap_or_default(),
|
||||||
|
target_category.as_deref(),
|
||||||
)?;
|
)?;
|
||||||
enforce_project_permission_policy(&request.root, "canvas.asset_generate")?;
|
enforce_project_permission_policy(&request.root, "canvas.asset_generate")?;
|
||||||
enforce_project_permission_policy(&request.root, "asset.register")?;
|
enforce_project_permission_policy(&request.root, "asset.register")?;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
use sha2::{Digest as _, Sha256};
|
use sha2::{Digest as _, Sha256};
|
||||||
|
use shared_contracts::game_creation_app::GameCreationAppAssetCategory;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
|
||||||
const PRIVATE_EXTERNAL_EDITOR_API_KEY_FILE_PREFIX: &str = "external-editor-api-";
|
const PRIVATE_EXTERNAL_EDITOR_API_KEY_FILE_PREFIX: &str = "external-editor-api-";
|
||||||
@@ -662,6 +663,7 @@ pub(crate) fn register_design_artifacts_at(root: &Path) -> Result<bool, String>
|
|||||||
generation_kind: None,
|
generation_kind: None,
|
||||||
reference_resource_ids: Vec::new(),
|
reference_resource_ids: Vec::new(),
|
||||||
},
|
},
|
||||||
|
None,
|
||||||
)?;
|
)?;
|
||||||
changed |= asset_changed;
|
changed |= asset_changed;
|
||||||
}
|
}
|
||||||
@@ -1876,8 +1878,56 @@ pub(crate) fn register_local_asset_entry(
|
|||||||
id_prefix: &str,
|
id_prefix: &str,
|
||||||
source: GameCreationAppAssetSource,
|
source: GameCreationAppAssetSource,
|
||||||
) -> Result<UploadLocalAssetResult, String> {
|
) -> Result<UploadLocalAssetResult, String> {
|
||||||
register_local_asset_entry_with_change(root, local_path, kind, media_type, id_prefix, source)
|
register_local_asset_entry_with_change(
|
||||||
.map(|(result, _)| result)
|
root, local_path, kind, media_type, id_prefix, source, None,
|
||||||
|
)
|
||||||
|
.map(|(result, _)| result)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 带**显式目标分类**的登记入口:只给 GUI 生成完成路径用(前端 `targetCategory`)。
|
||||||
|
///
|
||||||
|
/// 入口栏目与生成 kind 不是同一套词汇(栏目 `character` / `scene` / `ui-interaction`,
|
||||||
|
/// 生成 kind 的派生分类会把图片落到 `unclassified`、规范图落到 `document`),所以要落回
|
||||||
|
/// 入口栏目只能由调用方把目标分类显式交进来。取值必须先过
|
||||||
|
/// [`shared_contracts::game_creation_app::game_creation_app_asset_category_from_str`],
|
||||||
|
/// 非法值失败关闭,绝不回退到 kind 派生;其它调用方继续走
|
||||||
|
/// [`register_local_asset_entry`],行为不变。
|
||||||
|
pub(crate) fn register_local_asset_entry_with_category(
|
||||||
|
root: &Path,
|
||||||
|
local_path: &str,
|
||||||
|
kind: &str,
|
||||||
|
media_type: &str,
|
||||||
|
id_prefix: &str,
|
||||||
|
source: GameCreationAppAssetSource,
|
||||||
|
target_category: Option<&str>,
|
||||||
|
) -> Result<UploadLocalAssetResult, String> {
|
||||||
|
let target_category = normalize_asset_category_override(target_category)?;
|
||||||
|
register_local_asset_entry_with_change(
|
||||||
|
root,
|
||||||
|
local_path,
|
||||||
|
kind,
|
||||||
|
media_type,
|
||||||
|
id_prefix,
|
||||||
|
source,
|
||||||
|
target_category,
|
||||||
|
)
|
||||||
|
.map(|(result, _)| result)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 归一显式目标分类:只接受合法枚举值,返回落盘字符串。
|
||||||
|
fn normalize_asset_category_override(
|
||||||
|
target_category: Option<&str>,
|
||||||
|
) -> Result<Option<GameCreationAppAssetCategory>, String> {
|
||||||
|
let Some(target_category) = target_category else {
|
||||||
|
return Ok(None);
|
||||||
|
};
|
||||||
|
let target_category = target_category.trim();
|
||||||
|
if target_category.is_empty() {
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
game_creation_app_asset_category_from_str(target_category)
|
||||||
|
.map(Some)
|
||||||
|
.ok_or_else(|| format!("非法资源分类:{target_category}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register_local_asset_entry_with_change(
|
fn register_local_asset_entry_with_change(
|
||||||
@@ -1887,6 +1937,7 @@ fn register_local_asset_entry_with_change(
|
|||||||
media_type: &str,
|
media_type: &str,
|
||||||
id_prefix: &str,
|
id_prefix: &str,
|
||||||
source: GameCreationAppAssetSource,
|
source: GameCreationAppAssetSource,
|
||||||
|
target_category: Option<GameCreationAppAssetCategory>,
|
||||||
) -> Result<(UploadLocalAssetResult, bool), String> {
|
) -> Result<(UploadLocalAssetResult, bool), String> {
|
||||||
let normalized_path = normalize_relative_path(local_path)?;
|
let normalized_path = normalize_relative_path(local_path)?;
|
||||||
let absolute_path = resolve_local_project_path(root, &normalized_path)?;
|
let absolute_path = resolve_local_project_path(root, &normalized_path)?;
|
||||||
@@ -1912,11 +1963,17 @@ fn register_local_asset_entry_with_change(
|
|||||||
// kind 没变时刻意不动 category——落盘分类是权威值,同 kind 重登记不得抹掉它。
|
// kind 没变时刻意不动 category——落盘分类是权威值,同 kind 重登记不得抹掉它。
|
||||||
let changed = existing.kind != kind
|
let changed = existing.kind != kind
|
||||||
|| existing.media_type != media_type
|
|| existing.media_type != media_type
|
||||||
|| existing.source != source;
|
|| existing.source != source
|
||||||
|
|| target_category.is_some_and(|category| existing.category != category);
|
||||||
if existing.kind != kind {
|
if existing.kind != kind {
|
||||||
existing.kind = kind.to_string();
|
existing.kind = kind.to_string();
|
||||||
existing.category = game_creation_app_asset_category_for_kind(kind);
|
existing.category = game_creation_app_asset_category_for_kind(kind);
|
||||||
}
|
}
|
||||||
|
// 调用方显式给出目标分类时它就是权威值:GUI 完成登记必须能落回入口栏目,
|
||||||
|
// 这也是同路径重新生成时把资产从旧栏目(或 unclassified)原位接管过来的唯一入口。
|
||||||
|
if let Some(category) = target_category {
|
||||||
|
existing.category = category;
|
||||||
|
}
|
||||||
existing.media_type = media_type.to_string();
|
existing.media_type = media_type.to_string();
|
||||||
existing.source = source;
|
existing.source = source;
|
||||||
Ok((existing.id.clone(), "asset.update", changed))
|
Ok((existing.id.clone(), "asset.update", changed))
|
||||||
@@ -1933,7 +1990,8 @@ fn register_local_asset_entry_with_change(
|
|||||||
local_path: normalized_path.clone(),
|
local_path: normalized_path.clone(),
|
||||||
image_sequence_frames: None,
|
image_sequence_frames: None,
|
||||||
image_sequence_duration_ms: None,
|
image_sequence_duration_ms: None,
|
||||||
category: game_creation_app_asset_category_for_kind(kind),
|
category: target_category
|
||||||
|
.unwrap_or_else(|| game_creation_app_asset_category_for_kind(kind)),
|
||||||
tags: Vec::new(),
|
tags: Vec::new(),
|
||||||
source,
|
source,
|
||||||
});
|
});
|
||||||
@@ -2153,6 +2211,7 @@ pub(crate) fn delete_manifest_asset_at(
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use shared_contracts::game_creation_app::GameCreationAppAssetCategory;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -2176,6 +2235,121 @@ mod tests {
|
|||||||
assert!(!register_design_artifacts_at(root).expect("register idempotently"));
|
assert!(!register_design_artifacts_at(root).expect("register idempotently"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// GUI 完成登记可以显式指定目标栏目:新建条目与已登记条目都按显式值落盘。
|
||||||
|
///
|
||||||
|
/// 入口栏目(character / scene / ui-interaction)与生成 kind 不是同一套词汇,按 kind 派生
|
||||||
|
/// 会把图片落到 unclassified,占位拿不回原位;非法值必须失败关闭,不传时保持 kind 派生。
|
||||||
|
#[test]
|
||||||
|
fn explicit_target_category_overrides_the_kind_derived_category() {
|
||||||
|
fn canvas_source() -> GameCreationAppAssetSource {
|
||||||
|
GameCreationAppAssetSource {
|
||||||
|
kind: GameCreationAppAssetSourceKind::Canvas,
|
||||||
|
canvas_project_id: None,
|
||||||
|
resource_id: None,
|
||||||
|
asset_object_id: None,
|
||||||
|
task_id: None,
|
||||||
|
prompt: None,
|
||||||
|
model: None,
|
||||||
|
generation_route: None,
|
||||||
|
generation_kind: None,
|
||||||
|
reference_resource_ids: Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn category_of(root: &Path, asset_id: &str) -> GameCreationAppAssetCategory {
|
||||||
|
read_existing_manifest_for_project(root)
|
||||||
|
.expect("read manifest")
|
||||||
|
.assets
|
||||||
|
.into_iter()
|
||||||
|
.find(|asset| asset.id == asset_id)
|
||||||
|
.expect("registered asset is present")
|
||||||
|
.category
|
||||||
|
}
|
||||||
|
|
||||||
|
let temporary = tempfile::tempdir().expect("tempdir");
|
||||||
|
let root = temporary.path();
|
||||||
|
crate::project::init_local_game_project_at(root, "target-category-test", "目标栏目登记")
|
||||||
|
.expect("init project");
|
||||||
|
fs::create_dir_all(root.join("assets")).expect("create assets dir");
|
||||||
|
fs::write(root.join("assets/hero.png"), b"png-bytes").expect("write asset");
|
||||||
|
|
||||||
|
let registered = register_local_asset_entry_with_category(
|
||||||
|
root,
|
||||||
|
"assets/hero.png",
|
||||||
|
"image",
|
||||||
|
"image/png",
|
||||||
|
"platform-art",
|
||||||
|
canvas_source(),
|
||||||
|
Some("character"),
|
||||||
|
)
|
||||||
|
.expect("register with a target category");
|
||||||
|
assert_eq!(
|
||||||
|
category_of(root, ®istered.id),
|
||||||
|
GameCreationAppAssetCategory::Character
|
||||||
|
);
|
||||||
|
|
||||||
|
// 同 kind 重新生成时显式目标分类仍是权威值:资产要能换栏目原位接管。
|
||||||
|
register_local_asset_entry_with_category(
|
||||||
|
root,
|
||||||
|
"assets/hero.png",
|
||||||
|
"image",
|
||||||
|
"image/png",
|
||||||
|
"platform-art",
|
||||||
|
canvas_source(),
|
||||||
|
Some("ui-interaction"),
|
||||||
|
)
|
||||||
|
.expect("re-register with another target category");
|
||||||
|
assert_eq!(
|
||||||
|
category_of(root, ®istered.id),
|
||||||
|
GameCreationAppAssetCategory::UiInteraction
|
||||||
|
);
|
||||||
|
|
||||||
|
// 非法值失败关闭,且不动已落盘的分类。
|
||||||
|
assert!(register_local_asset_entry_with_category(
|
||||||
|
root,
|
||||||
|
"assets/hero.png",
|
||||||
|
"image",
|
||||||
|
"image/png",
|
||||||
|
"platform-art",
|
||||||
|
canvas_source(),
|
||||||
|
Some("version"),
|
||||||
|
)
|
||||||
|
.is_err());
|
||||||
|
assert_eq!(
|
||||||
|
category_of(root, ®istered.id),
|
||||||
|
GameCreationAppAssetCategory::UiInteraction
|
||||||
|
);
|
||||||
|
|
||||||
|
// 不传目标分类时保持原有行为:新条目按 kind 派生(image → unclassified)。
|
||||||
|
fs::write(root.join("assets/plain.png"), b"png-bytes").expect("write plain asset");
|
||||||
|
let plain = register_local_asset_entry(
|
||||||
|
root,
|
||||||
|
"assets/plain.png",
|
||||||
|
"image",
|
||||||
|
"image/png",
|
||||||
|
"platform-art",
|
||||||
|
canvas_source(),
|
||||||
|
)
|
||||||
|
.expect("register without a target category");
|
||||||
|
assert_eq!(
|
||||||
|
category_of(root, &plain.id),
|
||||||
|
GameCreationAppAssetCategory::Unclassified
|
||||||
|
);
|
||||||
|
// 已落盘的显式分类在 kind 未变时仍然是权威值:同 kind 重登记不得把它抹掉。
|
||||||
|
register_local_asset_entry(
|
||||||
|
root,
|
||||||
|
"assets/hero.png",
|
||||||
|
"image",
|
||||||
|
"image/png",
|
||||||
|
"platform-art",
|
||||||
|
canvas_source(),
|
||||||
|
)
|
||||||
|
.expect("re-register without a target category");
|
||||||
|
assert_eq!(
|
||||||
|
category_of(root, ®istered.id),
|
||||||
|
GameCreationAppAssetCategory::UiInteraction
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// 画板导出推断出的 kind 必须已经是 canonical 值。
|
/// 画板导出推断出的 kind 必须已经是 canonical 值。
|
||||||
///
|
///
|
||||||
/// 这个值会被原样写进 manifest 并据以派生落盘 `category`;一旦写出非 canonical 值
|
/// 这个值会被原样写进 manifest 并据以派生落盘 `category`;一旦写出非 canonical 值
|
||||||
|
|||||||
@@ -482,6 +482,43 @@ fn automatic_local_game_projects_root(app: &tauri::AppHandle) -> Result<PathBuf,
|
|||||||
.map_err(|error| format!("无法读取 AGC 应用数据目录:{error}"))
|
.map_err(|error| format!("无法读取 AGC 应用数据目录:{error}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 校验用户选择的项目创建目录。
|
||||||
|
///
|
||||||
|
/// 目录必须已经存在(原生目录选择器返回的结果),并且先过 AGC 私有路径门禁:门禁失败时
|
||||||
|
/// 这里就拒绝,避免项目被建到 AGC 无法加固、后续无法打开的位置。
|
||||||
|
pub(crate) fn validate_requested_game_project_creation_root(
|
||||||
|
requested: &str,
|
||||||
|
) -> Result<PathBuf, String> {
|
||||||
|
let requested = requested.trim();
|
||||||
|
let root = Path::new(requested);
|
||||||
|
if requested.is_empty() || !root.is_absolute() {
|
||||||
|
return Err("项目创建目录必须是绝对路径".to_string());
|
||||||
|
}
|
||||||
|
if project_path_has_control_chars(root) {
|
||||||
|
return Err("项目创建目录不能包含控制字符".to_string());
|
||||||
|
}
|
||||||
|
let metadata = fs::symlink_metadata(root)
|
||||||
|
.map_err(|error| format!("读取项目创建目录失败:{}: {error}", root.display()))?;
|
||||||
|
if metadata.file_type().is_symlink() || !metadata.is_dir() {
|
||||||
|
return Err("项目创建目录必须是普通文件夹".to_string());
|
||||||
|
}
|
||||||
|
// 用户选择的外部目录仍走显式的项目根准备:保留 user-selected 范围的一次性修复,
|
||||||
|
// 同时不放弃 reparse point / 非普通目录的失败关闭。
|
||||||
|
prepare_game_creator_project_root_for_read(root, true, "项目创建目录")?;
|
||||||
|
Ok(root.to_path_buf())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 解析本次建项要使用的根目录:没选就用 AGC 管理的默认目录,选了就用用户指定的目录。
|
||||||
|
pub(crate) fn resolve_game_project_creation_root(
|
||||||
|
app: &tauri::AppHandle,
|
||||||
|
requested: Option<&str>,
|
||||||
|
) -> Result<PathBuf, String> {
|
||||||
|
match requested.map(str::trim).filter(|value| !value.is_empty()) {
|
||||||
|
Some(requested) => validate_requested_game_project_creation_root(requested),
|
||||||
|
None => automatic_local_game_projects_root(app),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn create_automatic_local_game_project_at(
|
pub(crate) fn create_automatic_local_game_project_at(
|
||||||
projects_root: &Path,
|
projects_root: &Path,
|
||||||
requested_name: Option<&str>,
|
requested_name: Option<&str>,
|
||||||
@@ -551,9 +588,10 @@ pub(crate) fn create_automatic_local_game_project(
|
|||||||
app: tauri::AppHandle,
|
app: tauri::AppHandle,
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
planning: Option<bool>,
|
planning: Option<bool>,
|
||||||
|
projects_root: Option<String>,
|
||||||
) -> Result<InitLocalProjectResult, String> {
|
) -> Result<InitLocalProjectResult, String> {
|
||||||
create_automatic_local_game_project_at(
|
create_automatic_local_game_project_at(
|
||||||
&automatic_local_game_projects_root(&app)?,
|
&resolve_game_project_creation_root(&app, projects_root.as_deref())?,
|
||||||
name.as_deref(),
|
name.as_deref(),
|
||||||
planning.unwrap_or(false),
|
planning.unwrap_or(false),
|
||||||
)
|
)
|
||||||
@@ -764,13 +802,30 @@ pub(crate) fn recent_game_creator_run_trace(root: &Path) -> Option<GameCreationA
|
|||||||
serde_json::from_str::<GameCreationAgentRunTrace>(&content).ok()
|
serde_json::from_str::<GameCreationAgentRunTrace>(&content).ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 目录选择器标题:调用方只能给短标题,其余(超长、含控制字符、空白)一律回退默认文案。
|
||||||
|
fn pick_project_directory_title(title: Option<&str>) -> &str {
|
||||||
|
const MAX_TITLE_CHARS: usize = 24;
|
||||||
|
title
|
||||||
|
.map(str::trim)
|
||||||
|
.filter(|value| {
|
||||||
|
!value.is_empty()
|
||||||
|
&& value.chars().count() <= MAX_TITLE_CHARS
|
||||||
|
&& !value.chars().any(char::is_control)
|
||||||
|
})
|
||||||
|
.unwrap_or("选择游戏项目目录")
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub(crate) async fn pick_local_project_directory(
|
pub(crate) async fn pick_local_project_directory(
|
||||||
app: tauri::AppHandle,
|
app: tauri::AppHandle,
|
||||||
initial_path: Option<String>,
|
initial_path: Option<String>,
|
||||||
|
title: Option<String>,
|
||||||
) -> Result<Option<String>, String> {
|
) -> Result<Option<String>, String> {
|
||||||
let (sender, receiver) = tokio::sync::oneshot::channel();
|
let (sender, receiver) = tokio::sync::oneshot::channel();
|
||||||
let mut dialog = app.dialog().file().set_title("选择游戏项目目录");
|
let mut dialog = app
|
||||||
|
.dialog()
|
||||||
|
.file()
|
||||||
|
.set_title(pick_project_directory_title(title.as_deref()));
|
||||||
if let Some(initial_path) = initial_path
|
if let Some(initial_path) = initial_path
|
||||||
.as_deref()
|
.as_deref()
|
||||||
.map(str::trim)
|
.map(str::trim)
|
||||||
@@ -2320,6 +2375,27 @@ pub(crate) fn update_local_project_resource_classification(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 为一批已登记素材追加标签:整批一次校验、一次 manifest 写入、一次 revision 推进。
|
||||||
|
///
|
||||||
|
/// 权限位与单素材分类更新同口径取 `asset.register`(命令包装层只做权限门面,
|
||||||
|
/// 身份 / 写锁 / CAS / 原子写与审计都在 `project/manifest.rs` 内完成)。
|
||||||
|
/// 这里刻意**不**循环调用单素材命令:逐项调用会写出多份 manifest、推进多次 revision,
|
||||||
|
/// 中途失败还会留下"前几个素材改了、后面的没改"的部分写入。
|
||||||
|
#[tauri::command]
|
||||||
|
pub(crate) fn add_local_project_resource_tags(
|
||||||
|
input: AddLocalProjectResourceTagsInput,
|
||||||
|
) -> Result<AddLocalProjectResourceTagsResult, String> {
|
||||||
|
let root = Path::new(input.project_path.trim());
|
||||||
|
enforce_project_permission_policy(root, "asset.register")?;
|
||||||
|
add_manifest_asset_tags_at(
|
||||||
|
root,
|
||||||
|
&input.expected_project_id,
|
||||||
|
input.expected_project_revision,
|
||||||
|
input.asset_ids,
|
||||||
|
input.tags,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub(crate) async fn derive_local_project_resource(
|
pub(crate) async fn derive_local_project_resource(
|
||||||
input: DeriveLocalProjectResourceInput,
|
input: DeriveLocalProjectResourceInput,
|
||||||
@@ -4871,6 +4947,8 @@ pub(crate) fn prepare_local_project_asset_generation(
|
|||||||
image_size: Option<&str>,
|
image_size: Option<&str>,
|
||||||
asset_name: Option<&str>,
|
asset_name: Option<&str>,
|
||||||
output_path: Option<&str>,
|
output_path: Option<&str>,
|
||||||
|
reference_asset_ids: &[String],
|
||||||
|
target_category: Option<&str>,
|
||||||
) -> Result<LocalProjectAssetGenerationRequest, String> {
|
) -> Result<LocalProjectAssetGenerationRequest, String> {
|
||||||
let project_path = project_path.trim();
|
let project_path = project_path.trim();
|
||||||
if project_path.is_empty() {
|
if project_path.is_empty() {
|
||||||
@@ -4878,6 +4956,13 @@ pub(crate) fn prepare_local_project_asset_generation(
|
|||||||
}
|
}
|
||||||
let asset_kind = normalize_platform_art_asset_generation_kind(kind)
|
let asset_kind = normalize_platform_art_asset_generation_kind(kind)
|
||||||
.ok_or_else(|| format!("素材类型不受支持:{}", kind.trim()))?;
|
.ok_or_else(|| format!("素材类型不受支持:{}", kind.trim()))?;
|
||||||
|
// 参考入参只接受当前项目 manifest 素材 id:路径、远端 resourceId 与超限在这里就被拒绝,
|
||||||
|
// 不把校验推迟到远端(远端只该收到当前账号绑定下的 resource ID)。
|
||||||
|
let reference_asset_ids =
|
||||||
|
normalize_platform_art_reference_asset_ids(asset_kind, reference_asset_ids)?;
|
||||||
|
// GUI 完成登记层参数:入口栏目与生成 kind 不是同一套词汇,只有调用方显式给出目标分类
|
||||||
|
// 才能把产物原位落回入口栏目。非法值(含 `version` / `all` 这类栏目伪值)直接失败关闭。
|
||||||
|
let target_category = normalize_platform_art_target_category(target_category)?;
|
||||||
Ok(LocalProjectAssetGenerationRequest {
|
Ok(LocalProjectAssetGenerationRequest {
|
||||||
root: PathBuf::from(project_path),
|
root: PathBuf::from(project_path),
|
||||||
prompt: local_project_asset_prompt(prompt)?,
|
prompt: local_project_asset_prompt(prompt)?,
|
||||||
@@ -4914,6 +4999,8 @@ pub(crate) fn prepare_local_project_asset_generation(
|
|||||||
.then(|| "connected-components".to_string()),
|
.then(|| "connected-components".to_string()),
|
||||||
grid_x: None,
|
grid_x: None,
|
||||||
grid_y: None,
|
grid_y: None,
|
||||||
|
reference_asset_ids,
|
||||||
|
target_category,
|
||||||
screen_color: None,
|
screen_color: None,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -4936,6 +5023,10 @@ pub(crate) async fn generate_local_project_asset(
|
|||||||
image_size: Option<String>,
|
image_size: Option<String>,
|
||||||
asset_name: Option<String>,
|
asset_name: Option<String>,
|
||||||
output_path: Option<String>,
|
output_path: Option<String>,
|
||||||
|
reference_asset_ids: Option<Vec<String>>,
|
||||||
|
// 前端 IPC 字段 `targetCategory`:本次生成完成登记时要落盘的正式栏目分类,
|
||||||
|
// 只走 GUI 命令,取值必须是合法素材分类,Agent / Direct 路径不传。
|
||||||
|
target_category: Option<String>,
|
||||||
) -> Result<UploadLocalAssetResult, String> {
|
) -> Result<UploadLocalAssetResult, String> {
|
||||||
let request = prepare_local_project_asset_generation(
|
let request = prepare_local_project_asset_generation(
|
||||||
&project_path,
|
&project_path,
|
||||||
@@ -4945,6 +5036,8 @@ pub(crate) async fn generate_local_project_asset(
|
|||||||
image_size.as_deref(),
|
image_size.as_deref(),
|
||||||
asset_name.as_deref(),
|
asset_name.as_deref(),
|
||||||
output_path.as_deref(),
|
output_path.as_deref(),
|
||||||
|
reference_asset_ids.as_deref().unwrap_or_default(),
|
||||||
|
target_category.as_deref(),
|
||||||
)?;
|
)?;
|
||||||
enforce_project_permission_policy(&request.root, "canvas.asset_generate")?;
|
enforce_project_permission_policy(&request.root, "canvas.asset_generate")?;
|
||||||
enforce_project_permission_policy(&request.root, "asset.register")?;
|
enforce_project_permission_policy(&request.root, "asset.register")?;
|
||||||
@@ -4963,7 +5056,17 @@ mod local_project_asset_generation_tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
fn prepare(kind: &str, prompt: &str) -> Result<LocalProjectAssetGenerationRequest, String> {
|
fn prepare(kind: &str, prompt: &str) -> Result<LocalProjectAssetGenerationRequest, String> {
|
||||||
prepare_local_project_asset_generation("/tmp/project", kind, prompt, None, None, None, None)
|
prepare_local_project_asset_generation(
|
||||||
|
"/tmp/project",
|
||||||
|
kind,
|
||||||
|
prompt,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
&[],
|
||||||
|
None,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -5003,6 +5106,8 @@ mod local_project_asset_generation_tests {
|
|||||||
Some("2K"),
|
Some("2K"),
|
||||||
Some(" 主角图集 "),
|
Some(" 主角图集 "),
|
||||||
Some(" assets/hero.png "),
|
Some(" assets/hero.png "),
|
||||||
|
&[],
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
.expect("explicit options");
|
.expect("explicit options");
|
||||||
assert_eq!(explicit.root, PathBuf::from("/tmp/project"));
|
assert_eq!(explicit.root, PathBuf::from("/tmp/project"));
|
||||||
@@ -5030,8 +5135,18 @@ mod local_project_asset_generation_tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn invalid_toolbar_arguments_are_rejected_before_any_generation() {
|
fn invalid_toolbar_arguments_are_rejected_before_any_generation() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
prepare_local_project_asset_generation("", "image", "要求", None, None, None, None)
|
prepare_local_project_asset_generation(
|
||||||
.expect_err("empty project path"),
|
"",
|
||||||
|
"image",
|
||||||
|
"要求",
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
&[],
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.expect_err("empty project path"),
|
||||||
"项目路径不能为空"
|
"项目路径不能为空"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@@ -5042,6 +5157,60 @@ mod local_project_asset_generation_tests {
|
|||||||
prepare("game-art", "要求").expect_err("unverified kind"),
|
prepare("game-art", "要求").expect_err("unverified kind"),
|
||||||
"素材类型不受支持:game-art"
|
"素材类型不受支持:game-art"
|
||||||
);
|
);
|
||||||
|
// 目标分类只接受合法素材分类枚举:栏目侧伪值 `version` / `all` 与任意其它值都失败关闭。
|
||||||
|
for rejected in ["version", "all", "bogus", "UI"] {
|
||||||
|
assert_eq!(
|
||||||
|
prepare_local_project_asset_generation(
|
||||||
|
"/tmp/project",
|
||||||
|
"image",
|
||||||
|
"要求",
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
&[],
|
||||||
|
Some(rejected),
|
||||||
|
)
|
||||||
|
.expect_err("illegal target category"),
|
||||||
|
format!("目标分类不是合法素材分类:{rejected}")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// 合法值归一成落盘字符串(trim + kebab-case),供 manifest `category` 直接使用。
|
||||||
|
assert_eq!(
|
||||||
|
prepare_local_project_asset_generation(
|
||||||
|
"/tmp/project",
|
||||||
|
"image",
|
||||||
|
"要求",
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
&[],
|
||||||
|
Some(" ui-interaction "),
|
||||||
|
)
|
||||||
|
.expect("legal target category")
|
||||||
|
.options
|
||||||
|
.target_category
|
||||||
|
.as_deref(),
|
||||||
|
Some("ui-interaction")
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
prepare_local_project_asset_generation(
|
||||||
|
"/tmp/project",
|
||||||
|
"image",
|
||||||
|
"要求",
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
&[],
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.expect("omitted target category")
|
||||||
|
.options
|
||||||
|
.target_category,
|
||||||
|
None
|
||||||
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
prepare(
|
prepare(
|
||||||
"spec",
|
"spec",
|
||||||
@@ -5058,7 +5227,9 @@ mod local_project_asset_generation_tests {
|
|||||||
Some("4:3"),
|
Some("4:3"),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None
|
None,
|
||||||
|
&[],
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
.expect_err("unsupported ratio"),
|
.expect_err("unsupported ratio"),
|
||||||
"图片比例不受支持:4:3"
|
"图片比例不受支持:4:3"
|
||||||
@@ -5071,7 +5242,9 @@ mod local_project_asset_generation_tests {
|
|||||||
None,
|
None,
|
||||||
Some("4K"),
|
Some("4K"),
|
||||||
None,
|
None,
|
||||||
None
|
None,
|
||||||
|
&[],
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
.expect_err("unsupported size"),
|
.expect_err("unsupported size"),
|
||||||
"图片尺寸不受支持:4K"
|
"图片尺寸不受支持:4K"
|
||||||
@@ -5084,7 +5257,9 @@ mod local_project_asset_generation_tests {
|
|||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
Some("坏\u{7}名字"),
|
Some("坏\u{7}名字"),
|
||||||
None
|
None,
|
||||||
|
&[],
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
.expect_err("control character in asset name"),
|
.expect_err("control character in asset name"),
|
||||||
"素材名称超出安全边界"
|
"素材名称超出安全边界"
|
||||||
@@ -5097,7 +5272,9 @@ mod local_project_asset_generation_tests {
|
|||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
Some(&"a".repeat(LOCAL_PROJECT_ASSET_MAX_OUTPUT_PATH_CHARS + 1))
|
Some(&"a".repeat(LOCAL_PROJECT_ASSET_MAX_OUTPUT_PATH_CHARS + 1)),
|
||||||
|
&[],
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
.expect_err("oversized output path"),
|
.expect_err("oversized output path"),
|
||||||
"输出路径超出安全边界"
|
"输出路径超出安全边界"
|
||||||
|
|||||||
@@ -2589,6 +2589,7 @@ fn main() {
|
|||||||
register_local_asset,
|
register_local_asset,
|
||||||
create_ui_design_resource,
|
create_ui_design_resource,
|
||||||
update_local_project_resource_classification,
|
update_local_project_resource_classification,
|
||||||
|
add_local_project_resource_tags,
|
||||||
derive_local_project_resource,
|
derive_local_project_resource,
|
||||||
list_pending_local_project_resource_edits,
|
list_pending_local_project_resource_edits,
|
||||||
resume_local_project_resource_edit,
|
resume_local_project_resource_edit,
|
||||||
|
|||||||
@@ -1131,8 +1131,17 @@ pub(crate) fn validate_manifest_required_visual_asset(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if task_id == "art-director" {
|
if task_id == "art-director" {
|
||||||
if !asset.source.reference_resource_ids.is_empty() {
|
// 规范图是视觉来源链的根:它自身不派生任何视觉资产,但 icon-spec 生成允许用户参考
|
||||||
return Err("统一视觉规范图不得声明派生资源引用".to_string());
|
// (没有规范前置,最多总上限),这些参考只是风格输入,不构成派生关系。这里改为验证
|
||||||
|
// 参考集合仍符合 icon-spec 请求合同;route / generation kind / canvasProjectId /
|
||||||
|
// resourceId / PNG 解码等身份判据全部保持不变。
|
||||||
|
if !crate::agent::platform_art_runtime_references_match_request_contract(
|
||||||
|
&asset.source.reference_resource_ids,
|
||||||
|
expected_kind,
|
||||||
|
) {
|
||||||
|
return Err(format!(
|
||||||
|
"统一视觉规范图的参考集合不符合请求合同:{expected_path}"
|
||||||
|
));
|
||||||
}
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@@ -1157,11 +1166,17 @@ pub(crate) fn validate_manifest_required_visual_asset(
|
|||||||
.map(str::trim)
|
.map(str::trim)
|
||||||
.filter(|value| !value.is_empty())
|
.filter(|value| !value.is_empty())
|
||||||
.ok_or_else(|| "统一视觉规范图缺少 resourceId".to_string())?;
|
.ok_or_else(|| "统一视觉规范图缺少 resourceId".to_string())?;
|
||||||
let [reference_resource_id] = asset.source.reference_resource_ids.as_slice() else {
|
// 派生素材的参考合同是「规范图前置在最前,用户参考按顺序追加在后」,图集不接受用户参考:
|
||||||
|
// 规范身份仍只由首项承担,用户参考不能顶替也不能冒充规范引用。
|
||||||
|
if !crate::agent::platform_art_runtime_references_match_request_contract(
|
||||||
|
&asset.source.reference_resource_ids,
|
||||||
|
expected_kind,
|
||||||
|
) {
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
"派生视觉资产未精确引用当前统一视觉规范图:{expected_path}"
|
"派生视觉资产未精确引用当前统一视觉规范图:{expected_path}"
|
||||||
));
|
));
|
||||||
};
|
}
|
||||||
|
let reference_resource_id = asset.source.reference_resource_ids[0].as_str();
|
||||||
let original_provenance_matches =
|
let original_provenance_matches =
|
||||||
canvas_project_id == art_spec_project_id && reference_resource_id == art_spec_resource_id;
|
canvas_project_id == art_spec_project_id && reference_resource_id == art_spec_resource_id;
|
||||||
let rebound_local_source_matches = if original_provenance_matches {
|
let rebound_local_source_matches = if original_provenance_matches {
|
||||||
@@ -1328,6 +1343,240 @@ pub(crate) fn update_manifest_asset_classification_at(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
|
#[serde(deny_unknown_fields, rename_all = "camelCase")]
|
||||||
|
pub(crate) struct AddLocalProjectResourceTagsInput {
|
||||||
|
pub(crate) project_path: String,
|
||||||
|
pub(crate) expected_project_id: String,
|
||||||
|
pub(crate) expected_project_revision: u64,
|
||||||
|
pub(crate) asset_ids: Vec<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub(crate) tags: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub(crate) struct AddLocalProjectResourceTagsResult {
|
||||||
|
pub(crate) assets: Vec<GameCreationAppAssetManifestEntry>,
|
||||||
|
pub(crate) committed_project_revision: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 一次批量追加的素材上限:与主规范「每批最多 200 个不同素材」一致,按**去重后**数量计算。
|
||||||
|
/// 批次越大,锁内要重算的合并结果越多,manifest 也越大;无界批次会把成本摊到之后每一次读写上。
|
||||||
|
pub(crate) const ASSET_BATCH_TAG_MAX_ASSETS: usize = 200;
|
||||||
|
|
||||||
|
/// 批量追加标签的素材 ID 归一化:trim、按**首次出现顺序**去重,再在此处收口批次上下界。
|
||||||
|
///
|
||||||
|
/// 这里是"整句拒绝"的失败关闭口径,不做任何静默容忍:
|
||||||
|
///
|
||||||
|
/// - 空白 `assetId` 直接失败,不 `continue` 跳过。静默跳过会让"请求了 N 个素材"和"实际写了
|
||||||
|
/// N-1 个"分叉,而调用方拿到的仍是成功——这正是本合同要排除的静默部分写;
|
||||||
|
/// - 空批次失败;
|
||||||
|
/// - 去重后超限立即失败(在扫描到第 201 个不同 ID 时就返回,不对剩余 ID 继续做去重扫描),
|
||||||
|
/// 更不做"截断到 200 个":截断会让用户以为 250 个素材都加上了标签。
|
||||||
|
fn normalize_manifest_batch_asset_ids(asset_ids: &[String]) -> Result<Vec<String>, String> {
|
||||||
|
let mut normalized: Vec<String> = Vec::new();
|
||||||
|
for asset_id in asset_ids {
|
||||||
|
let asset_id = asset_id.trim();
|
||||||
|
if asset_id.is_empty() {
|
||||||
|
return Err("批量标签 assetId 不能为空".to_string());
|
||||||
|
}
|
||||||
|
if !normalized.iter().any(|existing| existing == asset_id) {
|
||||||
|
normalized.push(asset_id.to_string());
|
||||||
|
if normalized.len() > ASSET_BATCH_TAG_MAX_ASSETS {
|
||||||
|
return Err(format!(
|
||||||
|
"批量标签最多支持 {ASSET_BATCH_TAG_MAX_ASSETS} 个素材"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if normalized.is_empty() {
|
||||||
|
return Err("批量标签至少需要一个素材".to_string());
|
||||||
|
}
|
||||||
|
Ok(normalized)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 批量追加的标签归一化:沿用主规范的 trim / 去空 / 去重口径(复用
|
||||||
|
/// [`normalize_manifest_asset_tags`],其中已含数量与单标签长度收口)。
|
||||||
|
///
|
||||||
|
/// 只有**归一后为空**才拒绝:请求里全是空白标签时,用户填的东西一个字都不会落盘,
|
||||||
|
/// 此时若当成"成功且无变化"返回,界面会显示保存成功而素材上什么都没有。
|
||||||
|
fn normalize_manifest_batch_tags(tags: &[String]) -> Result<Vec<String>, String> {
|
||||||
|
let normalized = normalize_manifest_asset_tags(tags)?;
|
||||||
|
if normalized.is_empty() {
|
||||||
|
return Err("批量标签不能为空".to_string());
|
||||||
|
}
|
||||||
|
Ok(normalized)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 追加语义:只把请求里**尚不存在**的标签按请求顺序补到原有标签之后。
|
||||||
|
/// 原有标签的顺序、分类、类型、路径与来源都不参与改写——本命令没有删除或替换语义。
|
||||||
|
fn merge_manifest_asset_tags(existing: &[String], incoming: &[String]) -> Vec<String> {
|
||||||
|
let mut merged = existing.to_vec();
|
||||||
|
for tag in incoming {
|
||||||
|
if !merged.iter().any(|current| current == tag) {
|
||||||
|
merged.push(tag.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
merged
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 锁内先算完的整批计划:任何一项缺失或超限都在这里失败,此时 manifest 一个字节都没动。
|
||||||
|
struct ManifestAssetTagAppendPlan {
|
||||||
|
/// 按请求顺序(去重后)返回的素材条目,标签为合并后的完整列表。
|
||||||
|
assets: Vec<GameCreationAppAssetManifestEntry>,
|
||||||
|
/// 真正需要落值的目标:`(assets 下标, 合并后的标签)`。
|
||||||
|
updates: Vec<(usize, Vec<String>)>,
|
||||||
|
/// 确实发生变化的素材 ID,供审计记录使用;空表示整批无变化。
|
||||||
|
changed_asset_ids: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 先校验**全部**目标与**全部**合并结果,再决定是否写值。
|
||||||
|
///
|
||||||
|
/// 顺序是刻意的:第一阶段只读,任一目标不存在、任一合并结果超过标签上界都在写之前返回错误;
|
||||||
|
/// 只有全部通过,第二阶段才逐项落值。这样"缺任一资产 / 超限"都不可能留下部分写入。
|
||||||
|
fn plan_manifest_asset_tag_append(
|
||||||
|
manifest: &GameCreationAppManifest,
|
||||||
|
asset_ids: &[String],
|
||||||
|
tags: &[String],
|
||||||
|
) -> Result<ManifestAssetTagAppendPlan, String> {
|
||||||
|
let mut assets = Vec::with_capacity(asset_ids.len());
|
||||||
|
let mut updates: Vec<(usize, Vec<String>)> = Vec::with_capacity(asset_ids.len());
|
||||||
|
let mut changed_asset_ids = Vec::new();
|
||||||
|
for asset_id in asset_ids {
|
||||||
|
let index = manifest
|
||||||
|
.assets
|
||||||
|
.iter()
|
||||||
|
.position(|asset| &asset.id == asset_id)
|
||||||
|
.ok_or_else(|| format!("项目资源不存在:{asset_id}"))?;
|
||||||
|
let asset = &manifest.assets[index];
|
||||||
|
// 合并结果复用同一个上界函数:已有标签已归一化,这里等价于对整份新列表再收口一次。
|
||||||
|
// 上界函数只报"16 个"这种通用口径,200 个素材的批次里看不出是哪一项超了,所以在**调用点**
|
||||||
|
// 补上目标身份(ID + 可读 localPath)并说明整批未写:用户要能直接定位到那一张素材。
|
||||||
|
let merged = normalize_manifest_asset_tags(&merge_manifest_asset_tags(&asset.tags, tags))
|
||||||
|
.map_err(|error| {
|
||||||
|
format!(
|
||||||
|
"素材 {}({})的标签合并结果不合法:{error};本次未写入任何素材",
|
||||||
|
asset.id, asset.local_path
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
if merged != asset.tags {
|
||||||
|
changed_asset_ids.push(asset.id.clone());
|
||||||
|
}
|
||||||
|
updates.push((index, merged.clone()));
|
||||||
|
assets.push(GameCreationAppAssetManifestEntry {
|
||||||
|
tags: merged,
|
||||||
|
..asset.clone()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Ok(ManifestAssetTagAppendPlan {
|
||||||
|
assets,
|
||||||
|
updates,
|
||||||
|
changed_asset_ids,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 为一批已登记素材追加标签:一次校验、一次 manifest 写入、一次 revision 推进。
|
||||||
|
///
|
||||||
|
/// 语义与 [`update_manifest_asset_classification_at`] 同源(`asset.register` 权限位、项目身份、
|
||||||
|
/// 项目写锁、revision CAS、manifest 原子写、审计在 manifest 落盘之后 / revision 推进之前),
|
||||||
|
/// 但作用域是**整批**:
|
||||||
|
///
|
||||||
|
/// - 项目身份校验两次(进入前与持锁后各一次),锁内按 `expectedProjectRevision` 做一次 CAS;
|
||||||
|
/// - 锁内先算完整批计划,任一目标缺失或任一合并结果超限都**不写任何一项**;
|
||||||
|
/// - 整批无变化时**不写盘、不审计、不推进 revision**,直接返回当前条目与当前 revision;
|
||||||
|
/// - 真正有变化时才写一次 manifest、追加一条审计、推进一次 revision。
|
||||||
|
///
|
||||||
|
/// 已落盘之后的审计或 revision 失败照实报"整批已写入",不回滚、也不谎称回滚:manifest 是权威
|
||||||
|
/// 真相且已经改变,把错误说成"没写"只会让用户拿错状态去重试。
|
||||||
|
pub(crate) fn add_manifest_asset_tags_at(
|
||||||
|
root: &Path,
|
||||||
|
expected_project_id: &str,
|
||||||
|
expected_project_revision: u64,
|
||||||
|
asset_ids: Vec<String>,
|
||||||
|
tags: Vec<String>,
|
||||||
|
) -> Result<AddLocalProjectResourceTagsResult, String> {
|
||||||
|
if expected_project_revision
|
||||||
|
> shared_contracts::game_creation_app::GAME_CREATION_RESOURCE_LAYOUT_MAX_SAFE_REVISION
|
||||||
|
{
|
||||||
|
return Err("expectedProjectRevision 超出 JavaScript 安全整数范围".to_string());
|
||||||
|
}
|
||||||
|
let expected_project_id = expected_project_id.trim();
|
||||||
|
if expected_project_id.is_empty() {
|
||||||
|
return Err("批量标签 expectedProjectId 不能为空".to_string());
|
||||||
|
}
|
||||||
|
let asset_ids = normalize_manifest_batch_asset_ids(&asset_ids)?;
|
||||||
|
let tags = normalize_manifest_batch_tags(&tags)?;
|
||||||
|
|
||||||
|
if read_existing_manifest_for_project(root)?.project_id != expected_project_id {
|
||||||
|
return Err("project-identity-conflict".to_string());
|
||||||
|
}
|
||||||
|
// 锁的 commandId 用本命令自己的动作名(审计/排障时能区分是批量追加还是别的写路径);
|
||||||
|
// 权限门面仍然是 `asset.register`,见 `commands.rs` 的命令包装层。
|
||||||
|
let _lock = acquire_project_write_lock(root, ASSET_BATCH_TAG_AUDIT_RECORD_TYPE)?;
|
||||||
|
if read_existing_manifest_for_project(root)?.project_id != expected_project_id {
|
||||||
|
return Err("project-identity-conflict".to_string());
|
||||||
|
}
|
||||||
|
if read_game_creator_agent_runtime_project_revision(root)?.revision != expected_project_revision
|
||||||
|
{
|
||||||
|
return Err("project-revision-conflict".to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
// no-op 判定发生在锁内、写盘之前:整批标签都已经存在时,连 manifest 都不必重写一次。
|
||||||
|
// 这不是优化洁癖——重写会换掉文件 mtime 与内容字节,让"什么都没做"看起来像一次真实改动。
|
||||||
|
let plan = plan_manifest_asset_tag_append(
|
||||||
|
&read_existing_manifest_for_project(root)?,
|
||||||
|
&asset_ids,
|
||||||
|
&tags,
|
||||||
|
)?;
|
||||||
|
if plan.changed_asset_ids.is_empty() {
|
||||||
|
return Ok(AddLocalProjectResourceTagsResult {
|
||||||
|
assets: plan.assets,
|
||||||
|
committed_project_revision: expected_project_revision,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let plan = mutate_manifest_at(root, |manifest| {
|
||||||
|
// 锁内复核:`mutate_manifest_at` 自己重新读盘,所以这里按同一套规则重算一遍再落值。
|
||||||
|
// 复核失败会在 `write_manifest_locked` 之前返回错误,仍然零写入;重算也保证不会拿
|
||||||
|
// 锁外算出的绝对标签列表去覆盖这份 manifest 上刚出现的新标签。
|
||||||
|
let plan = plan_manifest_asset_tag_append(manifest, &asset_ids, &tags)?;
|
||||||
|
for (index, merged) in &plan.updates {
|
||||||
|
manifest.assets[*index].tags = merged.clone();
|
||||||
|
}
|
||||||
|
Ok(plan)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
// 复核阶段才发现"锁外以为有变化、锁内其实已无变化"的极端竞态:这一次写盘写出的就是原内容,
|
||||||
|
// 不能凭空补一条审计或推进 revision。正常路径不会走到这里——整批目标在此之前已经通过锁内 no-op 判定。
|
||||||
|
if plan.changed_asset_ids.is_empty() {
|
||||||
|
return Ok(AddLocalProjectResourceTagsResult {
|
||||||
|
assets: plan.assets,
|
||||||
|
committed_project_revision: expected_project_revision,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
append_agent_db_record(
|
||||||
|
root,
|
||||||
|
serde_json::json!({
|
||||||
|
"recordType": ASSET_BATCH_TAG_AUDIT_RECORD_TYPE,
|
||||||
|
"assetIds": plan.changed_asset_ids,
|
||||||
|
"expectedProjectRevision": expected_project_revision,
|
||||||
|
"appendedTags": tags,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.map_err(|error| format!("批量标签已写入,但审计记录失败:{error}"))?;
|
||||||
|
let committed_project_revision = advance_agent_runtime_project_revision_locked(root)
|
||||||
|
.map_err(|error| format!("批量标签已写入,但项目 revision 未能推进:{error}"))?;
|
||||||
|
Ok(AddLocalProjectResourceTagsResult {
|
||||||
|
assets: plan.assets,
|
||||||
|
committed_project_revision,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 批量标签写入的审计类型:一次批量追加只留一条记录,装的是"谁被追加了什么"。
|
||||||
|
pub(crate) const ASSET_BATCH_TAG_AUDIT_RECORD_TYPE: &str = "asset.tags.append";
|
||||||
|
|
||||||
pub(crate) fn create_manifest_task_at(
|
pub(crate) fn create_manifest_task_at(
|
||||||
root: &Path,
|
root: &Path,
|
||||||
task_id: &str,
|
task_id: &str,
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -880,12 +880,9 @@ pub(crate) async fn create_automatic_local_game_project_from_template(
|
|||||||
template_version: String,
|
template_version: String,
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
planning: Option<bool>,
|
planning: Option<bool>,
|
||||||
|
projects_root: Option<String>,
|
||||||
) -> Result<InitLocalProjectResult, String> {
|
) -> Result<InitLocalProjectResult, String> {
|
||||||
let projects_root = app
|
let projects_root = crate::resolve_game_project_creation_root(&app, projects_root.as_deref())?;
|
||||||
.path()
|
|
||||||
.app_data_dir()
|
|
||||||
.map(|root| root.join("projects"))
|
|
||||||
.map_err(|error| format!("无法读取 AGC 应用数据目录:{error}"))?;
|
|
||||||
let cache_root = template_cache_root(&app)?;
|
let cache_root = template_cache_root(&app)?;
|
||||||
ensure_game_creator_private_directory_tree(&cache_root, "模板库缓存目录")?;
|
ensure_game_creator_private_directory_tree(&cache_root, "模板库缓存目录")?;
|
||||||
let record =
|
let record =
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -6927,6 +6927,22 @@ fn agent_native_function_catalog_exposes_each_runtime_tool_with_core_schemas() {
|
|||||||
"sliceCount"
|
"sliceCount"
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
let canvas_properties = &canvas_asset.parameters["properties"]["input"]["properties"];
|
||||||
|
assert_eq!(
|
||||||
|
canvas_properties["sliceMode"]["enum"],
|
||||||
|
serde_json::json!(["connected-components", "grid", null])
|
||||||
|
);
|
||||||
|
for field in ["gridX", "gridY", "sliceCount"] {
|
||||||
|
assert_eq!(
|
||||||
|
canvas_properties[field]["type"],
|
||||||
|
serde_json::json!(["integer", "null"])
|
||||||
|
);
|
||||||
|
assert_eq!(canvas_properties[field]["minimum"], 1);
|
||||||
|
assert_eq!(
|
||||||
|
canvas_properties[field]["maximum"],
|
||||||
|
if field == "sliceCount" { 256 } else { 32 }
|
||||||
|
);
|
||||||
|
}
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
canvas_asset.parameters["properties"]["input"]["properties"]["aspectRatio"]["enum"],
|
canvas_asset.parameters["properties"]["input"]["properties"]["aspectRatio"]["enum"],
|
||||||
serde_json::json!(["1:1", "2:3", "3:2", "9:16", "16:9", null])
|
serde_json::json!(["1:1", "2:3", "3:2", "9:16", "16:9", null])
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use crate::config::build_game_creator_llm_client_from_llm_config;
|
|||||||
use crate::config::load_game_creator_app_config;
|
use crate::config::load_game_creator_app_config;
|
||||||
use crate::ui_editor::commands::utils::{
|
use crate::ui_editor::commands::utils::{
|
||||||
parse_limited_llm_tool_arguments, read_ui_reference_image_data_url, request_ui_editor_llm,
|
parse_limited_llm_tool_arguments, read_ui_reference_image_data_url, request_ui_editor_llm,
|
||||||
strict_json_schema,
|
required_tool_call_arguments, strict_json_schema,
|
||||||
};
|
};
|
||||||
use crate::ui_editor::component::text::FontSource;
|
use crate::ui_editor::component::text::FontSource;
|
||||||
use crate::ui_editor::component::{Component, NodeComponent};
|
use crate::ui_editor::component::{Component, NodeComponent};
|
||||||
@@ -406,12 +406,8 @@ pub(crate) async fn bind_components_impl_with_provider(
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
.map_err(|error| format!("组件绑定失败:{error}"))?;
|
.map_err(|error| format!("组件绑定失败:{error}"))?;
|
||||||
let call = response
|
let arguments = required_tool_call_arguments(&response, "bind_ui_components")?;
|
||||||
.tool_calls
|
let parsed = parse_binding_response(arguments, editable_nodes.len())?;
|
||||||
.iter()
|
|
||||||
.find(|call| call.name == "bind_ui_components")
|
|
||||||
.ok_or_else(|| "LLM 未返回 bind_ui_components 工具调用".to_string())?;
|
|
||||||
let parsed = parse_binding_response(&call.arguments, editable_nodes.len())?;
|
|
||||||
let known_sprite_ids = state.sprite_assets.keys().cloned().collect::<HashSet<_>>();
|
let known_sprite_ids = state.sprite_assets.keys().cloned().collect::<HashSet<_>>();
|
||||||
let known_font_ids = state.font_assets.keys().cloned().collect::<HashSet<_>>();
|
let known_font_ids = state.font_assets.keys().cloned().collect::<HashSet<_>>();
|
||||||
let result = validate_and_materialize(
|
let result = validate_and_materialize(
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use crate::config::build_game_creator_llm_client_from_llm_config;
|
use crate::config::build_game_creator_llm_client_from_llm_config;
|
||||||
use crate::config::load_game_creator_app_config;
|
use crate::config::load_game_creator_app_config;
|
||||||
use crate::ui_editor::commands::utils::{
|
use crate::ui_editor::commands::utils::{
|
||||||
parse_limited_llm_tool_arguments, request_ui_editor_llm, strict_json_schema,
|
parse_limited_llm_tool_arguments, request_ui_editor_llm, required_tool_call_arguments,
|
||||||
|
strict_json_schema,
|
||||||
};
|
};
|
||||||
use crate::ui_editor::state::{State, UITree};
|
use crate::ui_editor::state::{State, UITree};
|
||||||
use platform_llm::{LlmFunctionTool, LlmMessage, LlmRunRequest, LlmToolChoice};
|
use platform_llm::{LlmFunctionTool, LlmMessage, LlmRunRequest, LlmToolChoice};
|
||||||
@@ -172,6 +173,7 @@ mod materialize {
|
|||||||
use crate::ui_editor::layout::node::{
|
use crate::ui_editor::layout::node::{
|
||||||
Node as LayoutNode, NodeMetadata, NodeSource, StageStatus,
|
Node as LayoutNode, NodeMetadata, NodeSource, StageStatus,
|
||||||
};
|
};
|
||||||
|
use crate::ui_editor::layout::offset::NodeOffset;
|
||||||
use crate::ui_editor::layout::transform::Transform;
|
use crate::ui_editor::layout::transform::Transform;
|
||||||
use crate::ui_editor::state::{State, UITree};
|
use crate::ui_editor::state::{State, UITree};
|
||||||
use crate::ui_editor::utils::{random_node_id, NodeId, UIDesignImageId};
|
use crate::ui_editor::utils::{random_node_id, NodeId, UIDesignImageId};
|
||||||
@@ -302,6 +304,7 @@ mod materialize {
|
|||||||
component: None,
|
component: None,
|
||||||
children_display_mode: ChildrenDisplayMode::Exclusive,
|
children_display_mode: ChildrenDisplayMode::Exclusive,
|
||||||
children: members.into_iter().map(|member| member.node).collect(),
|
children: members.into_iter().map(|member| member.node).collect(),
|
||||||
|
offset: NodeOffset::default(),
|
||||||
},
|
},
|
||||||
priority,
|
priority,
|
||||||
src_ui_design,
|
src_ui_design,
|
||||||
@@ -485,15 +488,11 @@ pub(crate) async fn merge_ui_impl_with_provider(
|
|||||||
app_log!("ui_merge.error stage=llm_request error={error}");
|
app_log!("ui_merge.error stage=llm_request error={error}");
|
||||||
format!("UI 树合并失败:{error}")
|
format!("UI 树合并失败:{error}")
|
||||||
})?;
|
})?;
|
||||||
let call = response
|
let arguments = required_tool_call_arguments(&response, MERGE_TOOL_NAME).map_err(|error| {
|
||||||
.tool_calls
|
app_log!("ui_merge.error stage=parse_tool_call reason=missing_tool_call error={error}");
|
||||||
.iter()
|
format!("LLM 未返回 {MERGE_TOOL_NAME} 工具调用")
|
||||||
.find(|call| call.name == MERGE_TOOL_NAME)
|
})?;
|
||||||
.ok_or_else(|| {
|
let arguments = parse_limited_llm_tool_arguments(arguments).map_err(|error| {
|
||||||
app_log!("ui_merge.error stage=parse_tool_call reason=missing_tool_call");
|
|
||||||
format!("LLM 未返回 {MERGE_TOOL_NAME} 工具调用")
|
|
||||||
})?;
|
|
||||||
let arguments = parse_limited_llm_tool_arguments(&call.arguments).map_err(|error| {
|
|
||||||
app_log!("ui_merge.error stage=parse_arguments error={error}");
|
app_log!("ui_merge.error stage=parse_arguments error={error}");
|
||||||
format!("UI 合并工具参数无效:{error}")
|
format!("UI 合并工具参数无效:{error}")
|
||||||
})?;
|
})?;
|
||||||
@@ -527,6 +526,7 @@ mod tests {
|
|||||||
use crate::ui_editor::layout::children_display_mode::ChildrenDisplayMode;
|
use crate::ui_editor::layout::children_display_mode::ChildrenDisplayMode;
|
||||||
use crate::ui_editor::layout::control_layout::ControlLayout;
|
use crate::ui_editor::layout::control_layout::ControlLayout;
|
||||||
use crate::ui_editor::layout::node::{Node, NodeMetadata, NodeSource, StageStatus};
|
use crate::ui_editor::layout::node::{Node, NodeMetadata, NodeSource, StageStatus};
|
||||||
|
use crate::ui_editor::layout::offset::NodeOffset;
|
||||||
use crate::ui_editor::layout::transform::Transform;
|
use crate::ui_editor::layout::transform::Transform;
|
||||||
use crate::ui_editor::state::{State, UITree};
|
use crate::ui_editor::state::{State, UITree};
|
||||||
use crate::ui_editor::utils::{NodeId, UIDesignImageId};
|
use crate::ui_editor::utils::{NodeId, UIDesignImageId};
|
||||||
@@ -548,6 +548,7 @@ mod tests {
|
|||||||
component: None,
|
component: None,
|
||||||
children_display_mode: ChildrenDisplayMode::Stack,
|
children_display_mode: ChildrenDisplayMode::Stack,
|
||||||
children,
|
children,
|
||||||
|
offset: NodeOffset::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,17 +2,18 @@ use crate::config::build_game_creator_llm_client_from_llm_config;
|
|||||||
use crate::config::load_game_creator_app_config;
|
use crate::config::load_game_creator_app_config;
|
||||||
use crate::ui_editor::commands::utils::{
|
use crate::ui_editor::commands::utils::{
|
||||||
parse_limited_llm_tool_arguments, read_ui_reference_image_data_url, request_ui_editor_llm,
|
parse_limited_llm_tool_arguments, read_ui_reference_image_data_url, request_ui_editor_llm,
|
||||||
strict_json_schema,
|
required_tool_call_arguments, strict_json_schema,
|
||||||
};
|
};
|
||||||
use crate::ui_editor::component::{Component, NodeComponent};
|
use crate::ui_editor::component::{Component, NodeComponent};
|
||||||
use crate::ui_editor::layout::children_display_mode::ChildrenDisplayMode;
|
use crate::ui_editor::layout::children_display_mode::ChildrenDisplayMode;
|
||||||
use crate::ui_editor::layout::control_layout::ControlLayout;
|
use crate::ui_editor::layout::control_layout::ControlLayout;
|
||||||
use crate::ui_editor::layout::dimension::UIRect;
|
use crate::ui_editor::layout::dimension::UIRect;
|
||||||
use crate::ui_editor::layout::node::{Node as LayoutNode, NodeMetadata, NodeSource, StageStatus};
|
use crate::ui_editor::layout::node::{Node as LayoutNode, NodeMetadata, NodeSource, StageStatus};
|
||||||
|
use crate::ui_editor::layout::offset::NodeOffset;
|
||||||
use crate::ui_editor::layout::transform::Transform;
|
use crate::ui_editor::layout::transform::Transform;
|
||||||
use crate::ui_editor::resource::ui_design_image::UIDesignImage;
|
use crate::ui_editor::resource::ui_design_image::UIDesignImage;
|
||||||
use crate::ui_editor::state::{State, UITree};
|
use crate::ui_editor::state::{State, UITree};
|
||||||
use crate::ui_editor::utils::{random_node_id, NodeId, UIDesignImageId};
|
use crate::ui_editor::utils::{random_node_id, UIDesignImageId};
|
||||||
use nalgebra::{Point2, Vector2};
|
use nalgebra::{Point2, Vector2};
|
||||||
use platform_llm::{
|
use platform_llm::{
|
||||||
LlmFunctionTool, LlmMessage, LlmMessageContentPart, LlmRunRequest, LlmToolChoice,
|
LlmFunctionTool, LlmMessage, LlmMessageContentPart, LlmRunRequest, LlmToolChoice,
|
||||||
@@ -322,6 +323,7 @@ fn convert_node(
|
|||||||
component: source.component.clone().into_option(),
|
component: source.component.clone().into_option(),
|
||||||
children_display_mode: ChildrenDisplayMode::Stack,
|
children_display_mode: ChildrenDisplayMode::Stack,
|
||||||
children,
|
children,
|
||||||
|
offset: NodeOffset::default(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -768,21 +770,18 @@ pub(crate) async fn recognize_ui_impl_with_provider(
|
|||||||
!response.text.trim().is_empty(),
|
!response.text.trim().is_empty(),
|
||||||
response.tool_calls.len()
|
response.tool_calls.len()
|
||||||
);
|
);
|
||||||
let call = response
|
let arguments = required_tool_call_arguments(&response, "recognize_ui_structure")
|
||||||
.tool_calls
|
.map_err(|error| {
|
||||||
.iter()
|
|
||||||
.find(|call| call.name == "recognize_ui_structure")
|
|
||||||
.ok_or_else(|| {
|
|
||||||
app_log!(
|
app_log!(
|
||||||
"ui_recognition.error stage=parse_tool_call root={} reason=missing_tool_call",
|
"ui_recognition.error stage=parse_tool_call reason=missing_tool_call root={} error={error}",
|
||||||
root_id.as_str()
|
root_id.as_str()
|
||||||
);
|
);
|
||||||
format!(
|
format!(
|
||||||
"根界面图 {} 的 LLM 未返回 recognize_ui_structure 工具调用",
|
"LLM 未返回 recognize_ui_structure 工具调用(根界面图 {})",
|
||||||
root_id.as_str()
|
root_id.as_str()
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
let arguments = parse_limited_llm_tool_arguments(&call.arguments).map_err(|error| {
|
let arguments = parse_limited_llm_tool_arguments(arguments).map_err(|error| {
|
||||||
app_log!(
|
app_log!(
|
||||||
"ui_recognition.error stage=parse_arguments root={} error={error}",
|
"ui_recognition.error stage=parse_arguments root={} error={error}",
|
||||||
root_id.as_str()
|
root_id.as_str()
|
||||||
@@ -858,6 +857,7 @@ pub(crate) async fn recognize_ui_impl_with_provider(
|
|||||||
component: recognition_root.component.into_option(),
|
component: recognition_root.component.into_option(),
|
||||||
children_display_mode: ChildrenDisplayMode::Stack,
|
children_display_mode: ChildrenDisplayMode::Stack,
|
||||||
children,
|
children,
|
||||||
|
offset: NodeOffset::default(),
|
||||||
};
|
};
|
||||||
// Tree identity and root identity are assigned by Rust, never chosen by the model.
|
// Tree identity and root identity are assigned by Rust, never chosen by the model.
|
||||||
ui_trees.push(UITree {
|
ui_trees.push(UITree {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ mod tests {
|
|||||||
use crate::ui_editor::layout::control_layout::ControlLayout;
|
use crate::ui_editor::layout::control_layout::ControlLayout;
|
||||||
use crate::ui_editor::layout::node::Node;
|
use crate::ui_editor::layout::node::Node;
|
||||||
use crate::ui_editor::layout::node::{NodeMetadata, NodeSource, StageStatus};
|
use crate::ui_editor::layout::node::{NodeMetadata, NodeSource, StageStatus};
|
||||||
|
use crate::ui_editor::layout::offset::NodeOffset;
|
||||||
use crate::ui_editor::resource::ui_design_image::UIDesignImage;
|
use crate::ui_editor::resource::ui_design_image::UIDesignImage;
|
||||||
use crate::ui_editor::state::{State, UITree};
|
use crate::ui_editor::state::{State, UITree};
|
||||||
use crate::ui_editor::utils::{NodeId, UIDesignImageId};
|
use crate::ui_editor::utils::{NodeId, UIDesignImageId};
|
||||||
@@ -46,6 +47,7 @@ mod tests {
|
|||||||
component,
|
component,
|
||||||
children_display_mode: ChildrenDisplayMode::Stack,
|
children_display_mode: ChildrenDisplayMode::Stack,
|
||||||
children,
|
children,
|
||||||
|
offset: NodeOffset::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn state(root: Node) -> State {
|
fn state(root: Node) -> State {
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user