fix: Windows spawn, prefab path, preview API, asset deps, error messages; add execute-context resource, tool descriptions, scene/script/asset tools

Bug fixes (verified against Cocos Creator 3.8.8):
- diagnostics: shell:true for .cmd/.bat on Windows (T125/T126)
- prefabs: duplicatePrefab target resolves under assets/ (T420)
- cocos-project: add preview.open candidate for 3.8.8 (T444)
- assets-advanced: detect directory assets in inspectAssetDependencies (T110)
- scene: improve component-not-found errors with compilation hint (T429)

Documentation improvements:
- tool-registry: add enum and injected vars to execute_javascript, path format examples, asset ref limitation note
- resources: add cocos://mcp/execute-context resource with variables, patterns, pitfalls

New tools (core 37->38, full 101->110):
- scene-management: create_scene, query_scene_state (core), copy_paste_node, rename_node, reparent_node
- scripts: create_script with component/plain templates
- prefabs: create_prefab
- assets-advanced: batch_asset_ops, find_unused_assets
This commit is contained in:
mingyuansi
2026-06-30 21:53:06 +08:00
parent a9b539ca9c
commit b65a4f22c3
21 changed files with 5273 additions and 53 deletions
+27 -1
View File
@@ -169,7 +169,9 @@ async function duplicatePrefab(projectPath, options = {}) {
throw new Error(`Prefab source file was not found: ${source}`);
}
const targetPath = resolveProjectPath(projectPath, target.endsWith('.prefab') ? target : `${target}.prefab`);
const rawTarget = target.endsWith('.prefab') ? target : `${target}.prefab`;
const targetUnderAssets = rawTarget.replace(/^assets[\\/]/, '');
const targetPath = resolveProjectPath(projectPath, path.join('assets', targetUnderAssets));
const assetsRoot = path.join(projectPath, 'assets');
const relativeToAssets = path.relative(assetsRoot, targetPath);
if (relativeToAssets.startsWith('..') || path.isAbsolute(relativeToAssets)) {
@@ -259,8 +261,32 @@ async function revertPrefabInstance(nodeUuid) {
throw lastError || new Error('No prefab revert editor message was available.');
}
async function createPrefab(options = {}) {
const nodeUuid = String(options.nodeUuid || '').trim();
const savePath = String(options.savePath || '').trim();
if (!nodeUuid) {
throw new Error('nodeUuid is required.');
}
if (!savePath) {
throw new Error('savePath is required.');
}
if (!savePath.endsWith('.prefab')) {
throw new Error('savePath must end with .prefab');
}
// Note: 'create-prefab' is not a public message in Cocos Creator 3.8.8
// (Public: No in editor-messages-3.8.8.md). It works but may change in future versions.
const result = await requestEditorMessage('scene', 'create-prefab', nodeUuid, savePath);
return {
created: true,
nodeUuid,
savePath,
result,
};
}
module.exports = {
applyPrefabInstance,
createPrefab,
duplicatePrefab,
editPrefabJson,
inspectPrefab,