---
name: cocos-studio-publish
description: >-
  Full-publishes the Cocos Studio UI project (path from this skill's
  config.json) to local res/, then copies only specified .csb files to the
  PublishDirectory in the solution .cfg. Use when the user asks to publish,
  export, sync, or copy Cocos Studio UI (.csd/.csb), e.g. map.csb, BattleWnd,
  or “发布并同步” / “同步并导出”.
---

# Cocos Studio publish + selective CSB copy

## Setup (once per machine)

UI 工程路径只写在 **`config.json`**，不要改脚本、也不要在命令里传 `-ProjectRoot`。

拉仓库后打开 `.cursor/skills/cocos-studio-publish/config.json`，把 `ProjectUIRoot` 改成本机 Cocos Studio UI 工程目录（该目录下应有 `.ccs`，例如 `slg.ccs`）：

```json
{
  "ProjectUIRoot": "D:\\proj\\ui"
}
```

## When to use

User wants to publish Cocos Studio UI and sync **only named** screens/widgets to the game res path (not a full copy of `res/`).

## Workflow

1. Resolve target names from the user message and/or the focused `.csd` file.
2. Run the script **without** `-ProjectRoot` (it reads `config.json`).
3. Report which `.csb` files were copied and the destination from `.cfg`.

## Command

脚本相对本 skill 目录：`scripts/publish-and-copy.ps1`。从游戏仓库根目录调用时（不要传 `-ProjectRoot`，除非用户当场指定了别的工程）：

```powershell
powershell -NoProfile -ExecutionPolicy Bypass -File ".\.cursor\skills\cocos-studio-publish\scripts\publish-and-copy.ps1" <files...>
```

Examples:

```powershell
powershell -NoProfile -ExecutionPolicy Bypass -File ".\.cursor\skills\cocos-studio-publish\scripts\publish-and-copy.ps1" map.csb
powershell -NoProfile -ExecutionPolicy Bypass -File ".\.cursor\skills\cocos-studio-publish\scripts\publish-and-copy.ps1" BattleWnd.csd
powershell -NoProfile -ExecutionPolicy Bypass -File ".\.cursor\skills\cocos-studio-publish\scripts\publish-and-copy.ps1" -SkipPublish BattleWnd
```

Accepted name forms: `BattleWnd`, `BattleWnd.csd`, `BattleWnd.csb`, `ui/BattleWnd.csd`, full path under `cocosstudio/` or `res/`.

## Behavior (do not reimplement)

- **UI project root** comes from `config.json` → `ProjectUIRoot` (directory containing `.ccs` / `.cfg`)
- **Full publish** via `Cocos.Tool.exe publish -s` into `<project>/res/` (`-a`/`-w` fail on this 3.10 install when update servers are unreachable)
- **Copy destination** read from solution `.cfg` → `PublishDirectory`
- **Serializer** read from `.cfg` → `DefaultSerializer`
- **Only `.csb`** are copied; relative path under `res/` is preserved
- Optional `-SkipPublish` to copy from existing local `res/` only
- Optional `-CocosTool` or env `COCOS_TOOL` if the tool is not auto-found
- Optional `-ProjectRoot` only if the user explicitly names a different UI project this run

## Agent rules

- Prefer running the script; do not invent a second publish pipeline.
- Do not hardcode the UI project path; `config.json` is the single source.
- If the user names files, pass only those names.
- If the user says “发布当前” / has a focused `.csd` and no names, use that file.
- On failure, surface the script error (missing `config.json` / `ProjectUIRoot`, missing `Cocos.Tool`, missing csb, publish exit code).
