Agent Collaboration
ESP-GSP Studio supports a file-based collaboration protocol that lets an AI agent (or external script) edit native GSP scene files while the editor provides validation, preview and recovery.
The editor coordinates a project-wide handoff: it flushes local drafts, pauses human content editing, lets the external writer modify files, then validates and reloads the complete batch when the writer finishes.
Prerequisites
Section titled “Prerequisites”- ESP-GSP Studio must be running with the target project open.
- Node.js 22 or later.
- The collaboration CLI script
gsp-agent.cjs. It is available from:- Installed application — shipped in the app’s
resources/directory. - Source checkout —
scripts/gsp-agent.cjsin the editor repository. - Standalone download — Download collaboration scripts.
- Installed application — shipped in the app’s
After extracting the standalone archive, use the files under scripts/ and
keep gsp-editor-mcp.cjs beside gsp-agent.cjs.
Quick start
Section titled “Quick start”# 1. Check editor statusnode /path/to/gsp-agent.cjs status /path/to/project
# 2. Begin a collaboration sessionnode /path/to/gsp-agent.cjs begin /path/to/project# The command prints a batch ID on success.
# 3. Edit native JSON and resource files directly.# (The editor pauses human content editing during the session.)
# 4. When all writes are done, mark the batch as ready for reviewnode /path/to/gsp-agent.cjs ready /path/to/project <batch-id>
# 5. Finish: validate and reloadnode /path/to/gsp-agent.cjs finish /path/to/project <batch-id>CLI commands
Section titled “CLI commands”status
Section titled “status”node gsp-agent.cjs status /path/to/projectReports the current project state, selected Bundle/toolchain and whether an active collaboration session exists.
node gsp-agent.cjs begin /path/to/projectStarts a new collaboration session. The editor flushes any pending human drafts and enters read-only mode for content. Returns a batch ID that must be used in subsequent commands.
- Retrying
beginwith the samerequestIdreturns the original result without repeating the snapshot. - An existing active or interrupted batch must be resolved before starting a new one.
node gsp-agent.cjs ready /path/to/project <batch-id>Declares that the external writer has stopped modifying files and captures
the current file state for review. After ready, the editor can display
before/after diffs and previews.
Use resume to continue writing if more changes are needed.
resume
Section titled “resume”node gsp-agent.cjs resume /path/to/project <batch-id>Resumes an unfinished batch after ready, allowing additional file writes
before calling ready or finish again.
finish
Section titled “finish”node gsp-agent.cjs finish /path/to/project <batch-id>Validates the complete project using the selected GSPC and Bundle context, then reloads the editor.
success: truemeans the compiler accepted the batch.- Check
reload.statusseparately — a pending or failed reload does not undo acceptance. Useretry_reloadif needed. - A validation failure keeps the batch and its diagnostics. Fix the source
files and call
finishagain with a newrequestId.
cancel
Section titled “cancel”# Keep modified files on disk:node gsp-agent.cjs cancel /path/to/project <batch-id>
# Restore pre-batch files:node gsp-agent.cjs cancel /path/to/project <batch-id> --restoreWithout --restore, modified files remain on disk. With --restore, the
editor restores the snapshot taken at begin.
restore
Section titled “restore”node gsp-agent.cjs restore /path/to/project <completed-batch-id>Restores files from a previously completed batch. Refuses if any affected files have been modified since the batch.
batch_status
Section titled “batch_status”Query the state of a batch by ID after a timeout or interruption. Terminal
results remain readable even after session.json is removed.
Batch scope and limits
Section titled “Batch scope and limits”- The batch covers regular source files inside the project root.
- Excluded: generated/build/cache directories, symbolic links, external sources and resources.
- Snapshot limit: 128 MiB.
- Shared assets outside the project root can be referenced but must not be edited as part of this project-local batch.
Recovery
Section titled “Recovery”If the editor or the agent process is interrupted:
- Reopening the project in Studio shows the interrupted session in read-only mode.
- Use the editor’s Collaboration History and Recovery (协作记录与恢复…) entry to inspect, finish or restore the batch.
- The CLI
restorecommand can also recover a completed batch, as long as no files have been modified after the batch.
Recovery checks all changed source versions before restoring anything. Progress is journaled so a resumed restore can continue from where it left off.
MCP connection
Section titled “MCP connection”For AI agents that support MCP (Model Context Protocol), Studio also provides an MCP stdio adapter:
{ "mcpServers": { "gsp-editor": { "command": "node", "args": [ "/path/to/gsp-editor-mcp.cjs", "/path/to/project" ] } }}The adapter script is available from:
- Installed application —
resources/gsp-editor-mcp.cjs. - Source checkout —
scripts/gsp-editor-mcp.cjs. - Standalone download — Download collaboration scripts.
MCP tools include:
| Tool | Purpose |
|---|---|
get_editor_state |
Project state, toolchain, active document |
get_diagnostics |
Compiler diagnostics for the current scene |
screenshot_preview |
Capture a rendered preview PNG |
wait_for_preview |
Wait until the preview finishes rendering |
select |
Select a widget by index (requires current document version) |
reveal |
Scroll the canvas to reveal a widget |
begin_batch |
Start a collaboration session |
ready_batch |
Declare writes complete for review |
resume_batch |
Resume writing after ready |
finish_batch |
Validate and accept the batch |
cancel_batch |
Cancel the session |
restore_batch |
Restore files from a completed batch |
The adapter shares the authenticated local editor service with the CLI. The private HTTP bridge is not a public MCP HTTP endpoint.
Collaboration skill
Section titled “Collaboration skill”A distributable collaboration skill is included at
skills/gsp-editor-collaboration/SKILL.md and is shipped in packaged
applications. Install it in your agent’s skill directory to provide the
editor handoff and evidence workflow:
mkdir -p ~/.codex/skillscp -R /path/to/gsp-editor/skills/gsp-editor-collaboration ~/.codex/skills/Editor banner
Section titled “Editor banner”While a collaboration session is active, the editor displays a banner indicating the batch state. The banner provides buttons for:
- Finish — validate and accept.
- Cancel — abort and optionally restore.
- Recovery — inspect history and restore past batches.
Best practices
Section titled “Best practices”- Always call
beginand wait for success before writing files. - Preserve unknown JSON fields and existing resource paths when editing.
- Use
readybeforefinishso the editor can capture review snapshots. - On validation failure, inspect diagnostics, fix files, then
finishwith a newrequestId— do not retry unchanged failures repeatedly. - For large changes, consider a separate worktree with its own build context.
- Do not edit files outside the project root as part of a batch.