<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:nano="https://nanobpm.io/schema/shapes/1.0" id="Definitions_nano_workforce_implement_cell" targetNamespace="http://nanobpm.io/nano-workforce">
  <bpmn:process id="implement-cell" name="Implement cell" isExecutable="true">
    <bpmn:extensionElements>
      <nano:shapes>
        <nano:shape id="RecordEscalationIn" name="Record cell escalation — input">
          <nano:extend name="subjectKey" type="string" />
          <nano:extend name="status" type="string" optional="true" />
          <nano:extend name="question" type="string" optional="true" />
        </nano:shape>
      </nano:shapes>
    </bpmn:extensionElements>
    <bpmn:startEvent id="Start" name="Task">
      <bpmn:outgoing>ic_toImplement</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:serviceTask id="implement-task" name="Implement (agent)">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="senior:feature" />
        <zeebe:agentDefinition agentType="external" />
        <zeebe:linkedResources>
          <zeebe:linkedResource resourceId="prompts/feature.md" bindingType="latest" resourceType="GenericScript" linkName="prompt" />
        </zeebe:linkedResources>
        <zeebe:ioMapping>
          <zeebe:input source="=&#34;&#10;&#10;---&#10;&#10;&#34; + task.prompt + (if (is defined(baseBranchBrief) and baseBranchBrief != null) then baseBranchBrief else &#34;&#34;) + (if (is defined(blackboardBrief) and blackboardBrief != null) then blackboardBrief else &#34;&#34;) + (if (is defined(resolvedDepsBrief) and resolvedDepsBrief != null) then resolvedDepsBrief else &#34;&#34;) + (if (is defined(resolvedArtifacts) = false or resolvedArtifacts = null or count(resolvedArtifacts[item != null]) = 0) then &#34;&#34; else (&#34;&#10;&#10;---&#10;&#10;**Bound upstream readiness.** Build/install/clone against EXACTLY these resolved published versions (the ones first carrying the awaited capability), and bump the consumer dependency to them — never merely the newest:&#10;&#10;&#34; + string join(resolvedArtifacts[item != null], &#34;&#10;&#34;))) + (if (is defined(customInstructions) = false or customInstructions = null) then &#34;&#34; else &#34;&#10;&#10;---&#10;&#10;## Operator custom instructions&#10;&#10;The operator supplied these instructions for this run — follow them:&#10;&#10;&#34; + customInstructions)" target="appendPrompt" />
          <zeebe:input source="=if (is defined(transcriptUrlBase)) then transcriptUrlBase else null" target="transcriptUrlBase" />
          <zeebe:output source="=status" target="status" />
          <zeebe:output source="=question" target="question" />
          <zeebe:output source="=if (is defined(transcriptUrl)) then transcriptUrl else null" target="transcriptUrl" />
        </zeebe:ioMapping>
      </bpmn:extensionElements>
      <bpmn:incoming>ic_toImplement</bpmn:incoming>
      <bpmn:incoming>ic_answerLoop</bpmn:incoming>
      <bpmn:outgoing>ic_toGw</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:exclusiveGateway id="ic_gw" name="clean terminal?" default="ic_escalate">
      <bpmn:incoming>ic_toGw</bpmn:incoming>
      <bpmn:outgoing>ic_escalate</bpmn:outgoing>
      <bpmn:outgoing>ic_done</bpmn:outgoing>
    </bpmn:exclusiveGateway>
    <bpmn:serviceTask id="reconcile-implement" name="Reconcile from GitHub">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="pr.reconcile-implement" />
        <zeebe:ioMapping>
          <zeebe:output source="=reconciled" target="reconciled" />
          <zeebe:output source="=status" target="status" />
          <zeebe:output source="=pr" target="pr" />
        </zeebe:ioMapping>
      </bpmn:extensionElements>
      <bpmn:incoming>ic_escalate</bpmn:incoming>
      <bpmn:outgoing>ic_toReconcileGw</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:exclusiveGateway id="ic_reconcile_gw" name="reconciled?" default="ic_toRecordEscalation">
      <bpmn:incoming>ic_toReconcileGw</bpmn:incoming>
      <bpmn:outgoing>ic_reconciled</bpmn:outgoing>
      <bpmn:outgoing>ic_toRecordEscalation</bpmn:outgoing>
    </bpmn:exclusiveGateway>
    <bpmn:callActivity id="escalate" name="Human escalation">
      <bpmn:extensionElements>
        <zeebe:calledElement processId="human-escalation" />
        <zeebe:ioMapping>
          <zeebe:input source="=question" target="question" />
          <zeebe:input source="=if (is defined(escalationAssignee)) then escalationAssignee else null" target="escalationAssignee" />
          <zeebe:input source="=escalationSlaTimeout" target="escalationSlaTimeout" />
          <zeebe:output source="=resolution" target="resolution" />
          <zeebe:output source="=if (is defined(answer)) then answer else null" target="answer" />
        </zeebe:ioMapping>
      </bpmn:extensionElements>
      <bpmn:incoming>ic_toEscalate</bpmn:incoming>
      <bpmn:outgoing>ic_toAnswerGw</bpmn:outgoing>
    </bpmn:callActivity>
    <bpmn:serviceTask id="record-escalation" name="Record escalation">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="pr.record-feature-escalation" />
        <zeebe:properties>
          <zeebe:property name="io.nanobpm.dataEnvelope.in" value="RecordEscalationIn" />
        </zeebe:properties>
        <zeebe:ioMapping>
          <zeebe:output source="=question" target="question" />
        </zeebe:ioMapping>
      </bpmn:extensionElements>
      <bpmn:incoming>ic_toRecordEscalation</bpmn:incoming>
      <bpmn:outgoing>ic_toEscalate</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:exclusiveGateway id="ic_gw_answer" name="answer?" default="ic_abandon">
      <bpmn:incoming>ic_toAnswerGw</bpmn:incoming>
      <bpmn:outgoing>ic_answerLoop</bpmn:outgoing>
      <bpmn:outgoing>ic_abandon</bpmn:outgoing>
    </bpmn:exclusiveGateway>
    <bpmn:serviceTask id="record-implementing" name="Record implementing (reset)">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="pr.record-feature-implementing" />
        <zeebe:properties>
          <zeebe:property name="io.nanobpm.dataEnvelope.in" value="RecordFeatureImplementingIn" />
        </zeebe:properties>
      </bpmn:extensionElements>
      <bpmn:incoming>ic_answerLoop</bpmn:incoming>
      <bpmn:outgoing>ic_reImplement</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:endEvent id="ic_end" name="Task done">
      <bpmn:incoming>ic_done</bpmn:incoming>
      <bpmn:incoming>ic_reconciled</bpmn:incoming>
      <bpmn:incoming>ic_abandon</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="ic_toImplement" sourceRef="Start" targetRef="implement-task" />
    <bpmn:sequenceFlow id="ic_toGw" sourceRef="implement-task" targetRef="ic_gw" />
    <bpmn:sequenceFlow id="ic_done" name="done" sourceRef="ic_gw" targetRef="ic_end">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">=status = "opened" or status = "blocked" or status = "skipped"</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="ic_escalate" name="reconcile" sourceRef="ic_gw" targetRef="reconcile-implement" />
    <bpmn:sequenceFlow id="ic_toReconcileGw" sourceRef="reconcile-implement" targetRef="ic_reconcile_gw" />
    <bpmn:sequenceFlow id="ic_reconciled" name="adopted" sourceRef="ic_reconcile_gw" targetRef="ic_end">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">=reconciled = true</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="ic_toRecordEscalation" name="escalated" sourceRef="ic_reconcile_gw" targetRef="record-escalation" />
    <bpmn:sequenceFlow id="ic_toEscalate" sourceRef="record-escalation" targetRef="escalate" />
    <bpmn:sequenceFlow id="ic_toAnswerGw" sourceRef="escalate" targetRef="ic_gw_answer" />
    <bpmn:sequenceFlow id="ic_answerLoop" name="answer" sourceRef="ic_gw_answer" targetRef="record-implementing">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">=resolution = "answer"</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="ic_reImplement" sourceRef="record-implementing" targetRef="implement-task" />
    <bpmn:sequenceFlow id="ic_abandon" name="abandon" sourceRef="ic_gw_answer" targetRef="ic_end" />
  </bpmn:process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_implement-cell">
    <bpmndi:BPMNPlane id="BPMNPlane_implement-cell" bpmnElement="implement-cell">
      <bpmndi:BPMNShape id="BPMNShape_Start" bpmnElement="Start">
        <dc:Bounds x="80" y="102" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="81" y="143" width="34" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="BPMNShape_implement-task" bpmnElement="implement-task">
        <dc:Bounds x="216" y="80" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="BPMNShape_ic_gw" bpmnElement="ic_gw" isMarkerVisible="true">
        <dc:Bounds x="416" y="95" width="50" height="50" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="406" y="62" width="70" height="28" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="BPMNShape_reconcile-implement" bpmnElement="reconcile-implement">
        <dc:Bounds x="566" y="80" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="BPMNShape_ic_reconcile_gw" bpmnElement="ic_reconcile_gw" isMarkerVisible="true">
        <dc:Bounds x="766" y="95" width="50" height="50" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="751" y="76" width="81" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="BPMNShape_escalate" bpmnElement="escalate">
        <dc:Bounds x="1116" y="80" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="BPMNShape_record-escalation" bpmnElement="record-escalation">
        <dc:Bounds x="916" y="80" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="BPMNShape_ic_gw_answer" bpmnElement="ic_gw_answer" isMarkerVisible="true">
        <dc:Bounds x="1316" y="95" width="50" height="50" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="1313" y="76" width="56" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="BPMNShape_record-implementing" bpmnElement="record-implementing">
        <dc:Bounds x="1466" y="240" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="BPMNShape_ic_end" bpmnElement="ic_end">
        <dc:Bounds x="1498" y="102" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="1483" y="83" width="66" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="BPMNEdge_ic_toImplement" bpmnElement="ic_toImplement">
        <di:waypoint x="116" y="120" />
        <di:waypoint x="216" y="120" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="BPMNEdge_ic_toGw" bpmnElement="ic_toGw">
        <di:waypoint x="316" y="120" />
        <di:waypoint x="416" y="120" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="BPMNEdge_ic_escalate" bpmnElement="ic_escalate">
        <di:waypoint x="466" y="120" />
        <di:waypoint x="566" y="120" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="483" y="128" width="67" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="BPMNEdge_ic_toReconcileGw" bpmnElement="ic_toReconcileGw">
        <di:waypoint x="666" y="120" />
        <di:waypoint x="766" y="120" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="BPMNEdge_ic_toRecordEscalation" bpmnElement="ic_toRecordEscalation">
        <di:waypoint x="816" y="120" />
        <di:waypoint x="916" y="120" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="833" y="128" width="67" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="BPMNEdge_ic_toEscalate" bpmnElement="ic_toEscalate">
        <di:waypoint x="1016" y="120" />
        <di:waypoint x="1116" y="120" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="BPMNEdge_ic_toAnswerGw" bpmnElement="ic_toAnswerGw">
        <di:waypoint x="1216" y="120" />
        <di:waypoint x="1316" y="120" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="BPMNEdge_ic_abandon" bpmnElement="ic_abandon">
        <di:waypoint x="1366" y="120" />
        <di:waypoint x="1498" y="120" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="1406" y="98" width="53" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="BPMNEdge_ic_answerLoop" bpmnElement="ic_answerLoop">
        <di:waypoint x="1341" y="145" />
        <di:waypoint x="1341" y="280" />
        <di:waypoint x="1466" y="280" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="1346" y="206" width="49" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="BPMNEdge_ic_done" bpmnElement="ic_done">
        <di:waypoint x="441" y="145" />
        <di:waypoint x="441" y="200" />
        <di:waypoint x="1516" y="200" />
        <di:waypoint x="1516" y="138" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="963" y="208" width="32" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="BPMNEdge_ic_reconciled" bpmnElement="ic_reconciled">
        <di:waypoint x="791" y="145" />
        <di:waypoint x="791" y="180" />
        <di:waypoint x="1516" y="180" />
        <di:waypoint x="1516" y="138" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="1047" y="158" width="53" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="BPMNEdge_ic_reImplement" bpmnElement="ic_reImplement">
        <di:waypoint x="1516" y="320" />
        <di:waypoint x="1516" y="340" />
        <di:waypoint x="266" y="340" />
        <di:waypoint x="266" y="160" />
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>
