File size: 2,622 Bytes
d9b105f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | """Keep a received new project while the conversation chooses its workspace."""
import copy
import re
def receive(text, request, native, turn):
if turn.env is not None:
return None
pending = turn.s.get('pending_work')
if pending and re.fullmatch(r'(?i)\s*(?:cancel|never\s*mind|forget that|stop)[.! ]*', text):
turn.s.pop('pending_work', None)
turn.save()
return {'status': 'answered', 'path': 'bench:work:context:cancel',
'response': 'Cancelled the project request waiting for a folder.',
'execution': {'state': 'read', 'started': False, 'changed': False}}
import project_intent
if not project_intent.owns_turn(request['reading'], None, reading=native):
return None
pending = {'text': text, 'request': copy.deepcopy(request), 'reading': copy.deepcopy(native)}
if turn.s.get('pending_work') and turn.s['pending_work']['text'] != text:
turn.s.setdefault('pending_work_history', []).append(turn.s['pending_work'])
turn.s['pending_work'] = pending
turn.s['pending_context_focus'] = 'work'
turn.save()
return {'status': 'offered', 'path': 'bench:work:context',
'response': 'I have kept this project request: ' + text +
'\n\nWhich project folder should hold it? Open the folder with `open <folder path>`; I will continue from this request.',
'execution': {'state': 'waiting', 'started': False, 'changed': False},
'missing_evidence': [{'kind': 'project_folder', 'needed': 'project folder', 'request': text}]}
def resume(sid):
import bench
turn = bench.Turn(sid)
pending = turn.s.get('pending_work')
if not pending or turn.env is None or turn.env.kind != 'folder' or turn.s.get('pending_context_focus') not in (None, 'work'):
return None
result = bench.handle(pending['request']['reading'], sid, reading=pending.get('reading'))
if result is None:
return {'status': 'hole', 'path': 'bench:work:context',
'response': 'The folder is open, but no work part has received the kept request yet: ' + pending['text'],
'execution': {'state': 'missing', 'started': False, 'changed': False},
'missing_evidence': [{'kind': 'project_receiver', 'request': pending['text']}]}
if (result.get('execution') or {}).get('state') != 'refused':
# Reload: the work receiver may have saved its own project and focus.
turn = bench.Turn(sid)
turn.s.pop('pending_work', None)
turn.save()
return dict(result, resumed_project_request=pending['text'])
|