<scenario schemaVersion="3" id="project_edit" title="Prepare and test-plan an existing project edit">
  <inputs><input name="name" required="true"/><input name="request" required="true"/></inputs>
  <systemPrompt>Prepare a private copy and scoped source edits. No generated code executes until the user explicitly uses the host project-test command. Do not publish original files.</systemPrompt>
  <tools><allow name="project_edit_prepare_operation"/><allow name="project_edit_apply_operation"/><allow name="project_edit_require_operation"/><allow name="project_draft_read_operation"/><allow name="project_draft_source_operation"/></tools>
  <steps>
    <tool name="project_edit_prepare_operation" result="draft"><input name="name" value="{{name}}"/><input name="request" value="{{request}}"/></tool>
    <foreach items="draft.editAttempts" item="attempt" collect="applied" result="editAttempts" limit="1" attempts="3" successProperty="applied">
      <tool name="project_draft_read_operation" result="current"><input name="id" value="{{draft.id}}"/></tool>
      <tool name="project_draft_source_operation" result="currentSource"><input name="id" value="{{draft.id}}"/></tool>
      <run scenario="project_edit_plan" result="changes"><input name="kind" value="{{draft.kind}}"/><input name="prd" value="{{draft.prd}}"/><input name="request" value="{{request}}"/><input name="source" value="{{currentSource.source}}"/><input name="diagnostics" value="{{current.diagnostics}}"/></run>
      <tool name="project_edit_apply_operation" result="applied"><input name="id" value="{{draft.id}}"/><input name="changes" value="{{changes}}"/></tool>
    </foreach>
    <tool name="project_edit_require_operation" result="edited"><input name="id" value="{{draft.id}}"/></tool>
    <run scenario="project_plan_tests" result="receipt"><input name="id" value="{{draft.id}}"/></run>
  </steps>
  <exit mode="copy">Return private draft details and the separate execution approval command unchanged.</exit>
</scenario>
