oracle7-slim / workbench /project_context.py
psiloceyeben's picture
Release 12.0 (slim): one browser harness that converses, writes from held sources and builds what you describe, keeping each request through corrections and restarts. No language model. (part 5)
6e2225f verified
Raw History Blame Contribute Delete
2.62 kB
"""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'])