code: def _insert_action(self, node):
          
          task = self
          if (
              node.end_message and node.start_message and
              (len(node.children) == node.end_message.task_level.level[-1] - 2)):
              # Possibly this action is complete, make sure all sub-actions
              # are complete:
              completed = True
              for child in node.children:
                  if (
                      isinstance(child, WrittenAction)
                      and child.task_level not in self._completed):
                      completed = False
                      break
              if completed:
                  task = task.transform(["_completed"],
                                        lambda s: s.add(node.task_level))
          task = task.transform(["_nodes", node.task_level], node)
          return task._ensure_node_parents(node)
docs: Add a L{WrittenAction} to the tree.
  
          Parent actions will be created as necessary.
  
          @param child: A L{WrittenAction} to add to the tree.
  
          @return: Updated L{Task}.