mcpField
C
cli-anything-sbox

cli-anything-sbox

github.com/hkuds开发57.6k386 次安装5 周前更新
代码仓库

关于 cli-anything-sbox

面向 Agent 的 s&box 游戏项目 CLI,可操作场景、资产和配置文件。它将项目文件编辑、C# 组件生成、验证及资产引用查询整合在一起。

主要功能

  1. 01项目与资产管理
  2. 02场景和预制体编辑
  3. 03生成 C# 组件
  4. 04输入与碰撞配置
  5. 05编辑本地化文件
  6. 06资产验证与引用查询

适用场景

  1. 01创建并验证 s&box 项目
  2. 02通过命令行构建场景和预制体
  3. 03生成游戏组件代码
  4. 04查找资产引用或未使用资产

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/hkuds/cli-anything --skill cli-anything-sbox

安装后在 Claude Code 中输入/cli-anything-sbox确认已加载。

详细介绍

s&box CLI

面向 Agent 的 s&box 游戏引擎(Facepunch Studios,Source 2)命令行工具。涵盖 14 个命令组的 79+ 条命令。可直接操作 .scene、.prefab、.vmat、.sound、Input.config、Collision.config JSON 文件,生成符合惯用法的 C# 组件,并在项目上运行实时资产图。

安装

pip install git+https://github.com/HKUDS/CLI-Anything.git#subdirectory=sbox/agent-harness

环境要求

  • Python 3.10+
  • 通过 Steam 安装的 s&box——可自动检测,也可将 SBOX_PATH 设为自定义安装目录。
  • 大多数命令完全基于项目的 JSON 文件工作——无需运行 s&box。

全局选项

--json          Machine-readable JSON output (always pass for agent use)
--project PATH  Project directory (auto-detects from cwd .sbproj if omitted)

命令组

project - 管理 s&box 项目
cli-anything-sbox project new --name MyGame --output-dir ./MyGame
cli-anything-sbox --json project info
cli-anything-sbox project config --max-players 32 --tick-rate 64
cli-anything-sbox --json --project ./MyGame project add-package facepunch.libsdf
cli-anything-sbox --json --project ./MyGame project remove-package facepunch.libsdf
# Lint: broken asset refs, duplicate GUIDs, malformed Input.config
cli-anything-sbox --json --project ./MyGame project validate
cli-anything-sbox --project ./MyGame project validate --no-inputs --no-guids
scene - 操作 .scene 文件
cli-anything-sbox scene new --name gameplay -o ./Assets/scenes/gameplay.scene
cli-anything-sbox --json scene info ./scene.scene
cli-anything-sbox --json scene list ./scene.scene
cli-anything-sbox scene add-object ./scene.scene Enemy --position "100,0,0" --components "model,box_collider,rigidbody" --tags "enemy"
cli-anything-sbox scene remove-object ./scene.scene --name Enemy
cli-anything-sbox scene add-component ./scene.scene <object-guid> Sandbox.PointLight
cli-anything-sbox scene remove-component ./scene.scene <object-guid> --component-type Sandbox.Rigidbody
cli-anything-sbox --json scene modify-object ./scene.scene --guid <guid> --name NewName --position "200,0,0"
cli-anything-sbox --json scene clone-object ./scene.scene --name Enemy --new-name EnemyCopy --position "300,0,0"
cli-anything-sbox --json scene get-object ./scene.scene --name Sun
cli-anything-sbox scene set-property ./scene.scene --fixed-update-freq 64 --timescale 0.5
cli-anything-sbox scene set-navmesh ./scene.scene --enabled --agent-height 72 --agent-radius 16
cli-anything-sbox --json scene list-presets
cli-anything-sbox --json scene modify-component ./scene.scene <object-guid> <component-guid> --properties '{"Damage":50}'

# Find objects matching one or more filters (AND-combined)
cli-anything-sbox --json scene query ./scene.scene --has-component rigidbody --has-tag tower
cli-anything-sbox --json scene query ./scene.scene --name-regex "^Tower\d$" --in-bounds "0,-500,-50,1000,500,50"

# Extract every asset reference (.vmdl, .vmat, .vsnd, .vtex, .vpcf, .prefab) from a scene
cli-anything-sbox --json scene refs ./scene.scene

# Apply the same modification to every object that matches a query
cli-anything-sbox --json scene bulk-modify ./scene.scene --has-tag tower --position "0,0,100" --enable

# Structural diff between two scenes (added/removed/modified GameObjects + SceneProperties)
cli-anything-sbox --json scene diff ./old.scene ./new.scene

# Insert a prefab as a GameObject in a scene
cli-anything-sbox --json scene instantiate-prefab ./level.scene ./Assets/prefabs/bullet.prefab --position "10,0,0"
prefab - 管理 .prefab 文件
cli-anything-sbox prefab new --name Bullet -o ./Assets/prefabs/bullet.prefab --components "model,sphere_collider,rigidbody"
cli-anything-sbox --json prefab info ./Assets/prefabs/bullet.prefab
cli-anything-sbox prefab from-scene ./scene.scene <object-guid> -o ./Assets/prefabs/extracted.prefab
cli-anything-sbox --json prefab add-component ./prefab.prefab rigidbody
cli-anything-sbox prefab remove-component ./prefab.prefab --component-type Sandbox.Rigidbody
cli-anything-sbox --json prefab list

# Asset references inside a prefab
cli-anything-sbox --json prefab refs ./prefab.prefab

# Modify component properties on a prefab (by component type or component GUID)
cli-anything-sbox --json prefab modify-component ./prefab.prefab --component-type Sandbox.Rigidbody --properties '{"Gravity":false,"MassOverride":50}'

# Structural diff between two prefabs (root + named children)
cli-anything-sbox --json prefab diff ./old.prefab ./new.prefab
codegen - 生成 C# 代码
# Plain Component
cli-anything-sbox codegen component --name PlayerController --methods OnUpdate,OnFixedUpdate -o ./Code/PlayerController.cs

# Component with [Property] fields
cli-anything-sbox --json codegen component --name Tower --properties '[{"name":"Damage","type":"float","default":"25f"},{"name":"Range","type":"float","default":"500f"}]'

# Networked component (partial class) with RPC method stubs
cli-anything-sbox codegen component --name NetPlayer --networked --methods OnUpdate,OnFixedUpdate --rpc-methods "Fire:Broadcast,TakeDamage:Host" -o ./Code/NetPlayer.cs

# GameResource
cli-anything-sbox codegen gameresource --name TowerData --display-name "Tower Data" --extension tower -o ./Code/TowerData.cs

# Editor menu (Editor/ assembly)
cli-anything-sbox codegen editor-menu --name MyTools --menu-path "Editor/My Tools/Open" -o ./Editor/MyTools.cs

# Plain Razor UI component (.razor + .razor.scss)
cli-anything-sbox codegen razor --name HudPanel --properties '[{"name":"Score","type":"int","default":"0"}]' -o ./UI/HudPanel.razor

# Static or base-derived class
cli-anything-sbox codegen class --name Math2 --static -o ./Code/Math2.cs

# PanelComponent + sibling ScreenPanel scaffold (handles the s&box quirk where
# PanelComponent input only works when both are on the same GameObject).
# Emits .razor + .razor.scss + a paste-ready GameObject snippet, or appends
# directly to a scene with --scene.
cli-anything-sbox --json codegen panel-component --name HudBar -o ./UI/HudBar.razor
cli-anything-sbox codegen panel-component --name Crosshair -o ./UI/Crosshair.razor --scene ./Assets/scenes/game.scene
input - 管理 Input.config
cli-anything-sbox --json input list
cli-anything-sbox input add --name PlaceTower --group Gameplay --keyboard mouse1 --gamepad RightTrigger
cli-anything-sbox input remove --name PlaceTower
cli-anything-sbox input set --name Attack1 --keyboard mouse1
collision - 管理 Collision.config
cli-anything-sbox --json collision list
cli-anything-sbox collision add-layer --name projectile --default Collide
cli-anything-sbox collision add-rule --layer-a projectile --layer-b solid --result Collide
cli-anything-sbox collision remove-rule --layer-a projectile --layer-b solid
cli-anything-sbox collision remove-layer --name projectile
material - 管理 .vmat 材质
cli-anything-sbox --json material new --name floor --shader complex --color-texture "textures/floor.tga" --metalness 0.3 -o ./Assets/materials/floor.vmat
cli-anything-sbox --json material info ./Assets/materials/floor.vmat
cli-anything-sbox --json material list
cli-anything-sbox --json material set ./Assets/materials/floor.vmat --metalness 0.8
sound - 管理 .sound 事件
cli-anything-sbox --json sound new --name gunshot --sounds "sounds/gun1.vsnd,sounds/gun2.vsnd" --volume 0.8 -o ./Assets/sounds/gunshot.sound
cli-anything-sbox --json sound info ./Assets/sounds/gunshot.sound
cli-anything-sbox --json sound list
cli-anything-sbox --json sound set ./Assets/sounds/gunshot.sound --volume 0.5
localization - 管理翻译
cli-anything-sbox localization new --lang en -o ./Localization/en.json
cli-anything-sbox localization set ./Localization/en.json --key "game.title" --value "My Game"
cli-anything-sbox --json localization list ./Localization/en.json
cli-anything-sbox localization get ./Localization/en.json --key "game.title"
cli-anything-sbox localization remove ./Localization/en.json --key "game.title"
cli-anything-sbox localization bulk-set ./Localization/en.json --keys '{"ui.start":"Start","ui.quit":"Quit"}'
server - 专用服务器
cli-anything-sbox server info
cli-anything-sbox server start --game my_game --map facepunch.flatgrass
asset - 资产管理 & 反向查找
cli-anything-sbox --json asset list --type scene
cli-anything-sbox --json asset info ./Assets/scenes/minimal.scene
cli-anything-sbox asset compile ./Assets/materials/floor.vmat

# Which scenes/prefabs reference this asset?
cli-anything-sbox --json --project ./MyGame asset find-refs models/myteam/widget.vmdl

# Find unreferenced assets (per type, or across all referenceable types)
cli-anything-sbox --json --project ./MyGame asset find-unused
cli-anything-sbox --json --project ./MyGame asset find-unused --type model --type material

# Rename an asset and update every scene/prefab reference (extension preserved if omitted)
cli-anything-sbox --json --project ./MyGame asset rename models/team/widget.vmdl gizmo
cli-anything-sbox --project ./MyGame asset rename models/team/widget.vmdl gizmo --dry-run

# Move an asset across directories and update every reference
cli-anything-sbox --json --project ./MyGame asset move models/team/widget.vmdl models/shared/widget.vmdl
session - 状态管理
cli-anything-sbox session status
cli-anything-sbox session undo
cli-anything-sbox session redo
test - 自动化地图/场景生成测试框架
cli-anything-sbox test setup
cli-anything-sbox --json test run
launch - 在 s&box 编辑器中打开项目
cli-anything-sbox launch

组件预设

29 个简写名称,可用于 scene add-object、prefab new 等命令的 --components 参数。每个简写名称映射到一个 Sandbox.* 组件类型。

预设组件类型
modelSandbox.ModelRenderer
box_colliderSandbox.BoxCollider
sphere_colliderSandbox.SphereCollider
capsule_colliderSandbox.CapsuleCollider
plane_colliderSandbox.PlaneCollider
model_colliderSandbox.ModelCollider
rigidbodySandbox.Rigidbody
character_controllerSandbox.CharacterController
player_controllerSandbox.PlayerController
cameraSandbox.CameraComponent
light_directionalSandbox.DirectionalLight
light_pointSandbox.PointLight
spot_lightSandbox.SpotLight
ambient_lightSandbox.AmbientLight
sprite_rendererSandbox.SpriteRenderer
skinned_model_rendererSandbox.SkinnedModelRenderer
text_rendererSandbox.TextRenderer
line_rendererSandbox.LineRenderer
decal_rendererSandbox.DecalRenderer
trail_rendererSandbox.TrailRenderer
particle_effectSandbox.ParticleEffect
sound_pointSandbox.SoundPointComponent
nav_mesh_agentSandbox.NavMeshAgent
screen_panelSandbox.ScreenPanel
world_panelSandbox.WorldPanel
fixed_jointSandbox.FixedJoint
hinge_jointSandbox.HingeJoint
spring_jointSandbox.SpringJoint
ball_socket_jointSandbox.BallSocketJoint

scene list-presets 以 JSON 返回实时预设注册表。

Agent 使用模式

每次由 Agent 驱动的调用都传入 --json。通过 jq 进行管道传递,在各命令之间串联 GUID 和路径:

# Bootstrap a project
sbproj=$(cli-anything-sbox --json project new --name MyGame --output-dir /tmp/MyGame | jq -r '.sbproj')
cd /tmp/MyGame

# Add a tower with a specific component layout, capture its GUID
guid=$(cli-anything-sbox --json scene add-object ./Assets/scenes/main.scene Tower \
    --components "model,box_collider,rigidbody" --tags "tower" \
    | jq -r '.guid')

# Generate the corresponding C# component, networked
cli-anything-sbox --json codegen component --name Tower --networked \
    --rpc-methods "Fire:Host" --properties '[{"name":"Damage","type":"float","default":"25f"}]' \
    -o ./Code/Tower.cs

# Bulk-tweak every tower in the scene
cli-anything-sbox --json scene bulk-modify ./Assets/scenes/main.scene \
    --has-tag tower --enable --position-y-add 50

# Validate before committing
cli-anything-sbox --json project validate

REPL 模式

不带参数运行 cli-anything-sbox 会进入带样式提示符的交互式 REPL:

$ cli-anything-sbox
cli-anything-sbox> project info
cli-anything-sbox> scene list ./Assets/scenes/main.scene
cli-anything-sbox> codegen component --name Foo -o ./Code/Foo.cs
cli-anything-sbox> quit

环境变量

变量描述默认值
SBOX_PATHs&box 安装目录从 Steam 库文件夹自动检测
CLI_ANYTHING_SKILL_REPO覆盖 repl_skin 读取 SKILL.md 的仓库HKUDS/CLI-Anything

评论

支持 Markdown