<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def stamp_title(kb_app: kb, sphinx_app: Sphinx, doctree: doctree):
 """ Walk the tree and extra RST title into resource.title """


    # First, find out which resource this is. Won't be easy.
    resources = sphinx_app.env.resources
    confdir = sphinx_app.confdir
    source = PurePath(doctree.attributes['source'])

    # Get the relative path inside the docs dir, without .rst, then
    # get the resource
    docname = str(source.relative_to(confdir)).split('.rst')[0]
    resource = resources.get(docname)

    if resource:
        # Stamp the title on the resource
        title = get_rst_title(doctree)
        resource.title = title