feat(box): enable real-time agent tool triggers and capabilities expansion
This commit is contained in:
+124
-1
@@ -67,6 +67,7 @@ SIG_MAX_SKEW = 300
|
||||
AGENTS = ('muse', 'pip', '646', 'opm', 'def', 'dev')
|
||||
TARGET_RE = re.compile(r'^[A-Za-z0-9][A-Za-z0-9/_.-]{0,63}$')
|
||||
JOB_RE = re.compile(r'^[a-z0-9][a-z0-9-]{0,63}$')
|
||||
NAME_RE = re.compile(r'^[A-Za-z0-9_.-]{1,64}$')
|
||||
IDENT_RE = re.compile(r'^[a-z0-9-]+$')
|
||||
NONCE_RE = re.compile(r'^[0-9a-fA-F]{16,128}$')
|
||||
HEX_RE = re.compile(r'^[0-9a-f]{8,128}$')
|
||||
@@ -523,6 +524,91 @@ def _pipeline_run_build(a):
|
||||
return [sys.executable, os.path.join(BIN_DIR, 'super-cli.py'), 'deploy', 'pipeline', a['name']]
|
||||
|
||||
|
||||
def _cron_status_validate(raw):
|
||||
if not isinstance(raw, dict):
|
||||
raise OpError('args must be an object')
|
||||
allowed = {'name'}
|
||||
for k in raw:
|
||||
if k not in allowed:
|
||||
raise OpError(f'unknown arg: {k}')
|
||||
return {'name': _job_name(raw.get('name')) if raw.get('name') else 'heartbeat'}
|
||||
|
||||
|
||||
def _cron_status_build(a):
|
||||
return [sys.executable, os.path.join(BIN_DIR, 'box-ctl.py'), 'timer-status', a['name']]
|
||||
|
||||
|
||||
def _cron_view_validate(raw):
|
||||
if not isinstance(raw, dict):
|
||||
raise OpError('args must be an object')
|
||||
allowed = {'name'}
|
||||
for k in raw:
|
||||
if k not in allowed:
|
||||
raise OpError(f'unknown arg: {k}')
|
||||
return {'name': _job_name(raw.get('name'))}
|
||||
|
||||
|
||||
def _cron_view_build(a):
|
||||
return [sys.executable, os.path.join(BIN_DIR, 'box-ctl.py'), 'job-get', a['name']]
|
||||
|
||||
|
||||
def _cron_runs_validate(raw):
|
||||
if raw not in ({}, None):
|
||||
raise OpError('cron.runs takes no required args')
|
||||
return {}
|
||||
|
||||
|
||||
def _cron_runs_build(a):
|
||||
return [sys.executable, os.path.join(BIN_DIR, 'box-ctl.py'), 'job-list']
|
||||
|
||||
|
||||
def _vars_list_validate(raw):
|
||||
if raw not in ({}, None):
|
||||
raise OpError('vars.list takes no required args')
|
||||
return {}
|
||||
|
||||
|
||||
def _vars_list_build(a):
|
||||
return [sys.executable, os.path.join(BIN_DIR, 'box-ctl.py'), 'vars-list']
|
||||
|
||||
|
||||
def _vars_get_validate(raw):
|
||||
if not isinstance(raw, dict):
|
||||
raise OpError('args must be an object')
|
||||
allowed = {'name'}
|
||||
for k in raw:
|
||||
if k not in allowed:
|
||||
raise OpError(f'unknown arg: {k}')
|
||||
name = raw.get('name')
|
||||
if not isinstance(name, str) or not NAME_RE.fullmatch(name):
|
||||
raise OpError('name must match safe identifier')
|
||||
return {'name': name}
|
||||
|
||||
|
||||
def _vars_get_build(a):
|
||||
return [sys.executable, os.path.join(BIN_DIR, 'box-ctl.py'), 'vars-get', a['name']]
|
||||
|
||||
|
||||
def _vars_set_validate(raw):
|
||||
if not isinstance(raw, dict):
|
||||
raise OpError('args must be an object')
|
||||
allowed = {'name', 'value'}
|
||||
for k in raw:
|
||||
if k not in allowed:
|
||||
raise OpError(f'unknown arg: {k}')
|
||||
name = raw.get('name')
|
||||
if not isinstance(name, str) or not NAME_RE.fullmatch(name):
|
||||
raise OpError('name must match safe identifier')
|
||||
val = raw.get('value')
|
||||
if val is None or not isinstance(val, (str, int, float, bool)):
|
||||
raise OpError('value must be a scalar')
|
||||
return {'name': name, 'value': str(val)}
|
||||
|
||||
|
||||
def _vars_set_build(a):
|
||||
return [sys.executable, os.path.join(BIN_DIR, 'box-ctl.py'), 'vars-set', a['name'], a['value']]
|
||||
|
||||
|
||||
# op -> {validate, build, timeout, side_effecting, description}
|
||||
OPS = {
|
||||
'dm.send': {
|
||||
@@ -580,6 +666,41 @@ OPS = {
|
||||
'timeout': 120, 'side_effecting': True,
|
||||
'desc': 'Dispatch a multi-step pipeline across agents',
|
||||
},
|
||||
'cron.status': {
|
||||
'validate': _cron_status_validate, 'build': _cron_status_build,
|
||||
'timeout': 30, 'side_effecting': False,
|
||||
'desc': 'Check systemd timer / scheduled check status',
|
||||
},
|
||||
'cron.view': {
|
||||
'validate': _cron_view_validate, 'build': _cron_view_build,
|
||||
'timeout': 30, 'side_effecting': False,
|
||||
'desc': 'View scheduled job definition and prompt',
|
||||
},
|
||||
'cron.runs': {
|
||||
'validate': _cron_runs_validate, 'build': _cron_runs_build,
|
||||
'timeout': 30, 'side_effecting': False,
|
||||
'desc': 'List all scheduled crons/jobs across the fleet',
|
||||
},
|
||||
'cron.run': {
|
||||
'validate': _job_run_validate, 'build': _job_run_build,
|
||||
'timeout': 300, 'side_effecting': True,
|
||||
'desc': 'Trigger on-demand execution of a scheduled job',
|
||||
},
|
||||
'vars.list': {
|
||||
'validate': _vars_list_validate, 'build': _vars_list_build,
|
||||
'timeout': 30, 'side_effecting': False,
|
||||
'desc': 'List intrinsic loop strategy and timing variables',
|
||||
},
|
||||
'vars.get': {
|
||||
'validate': _vars_get_validate, 'build': _vars_get_build,
|
||||
'timeout': 30, 'side_effecting': False,
|
||||
'desc': 'Get specific intrinsic loop variable',
|
||||
},
|
||||
'vars.set': {
|
||||
'validate': _vars_set_validate, 'build': _vars_set_build,
|
||||
'timeout': 30, 'side_effecting': True,
|
||||
'desc': 'Update intrinsic loop variable',
|
||||
},
|
||||
'exec.ping': {
|
||||
'validate': _health_validate,
|
||||
'build': lambda a: ['/bin/echo', 'PONG'],
|
||||
@@ -757,7 +878,9 @@ class Handler(BaseHTTPRequestHandler):
|
||||
self._send(400, {'error': f'bad args: {e}'})
|
||||
return
|
||||
except Exception as e:
|
||||
self._send(500, {'error': 'internal'})
|
||||
sys.stderr.write(f'Validation/build exception for {op}: {e}\n')
|
||||
import traceback; traceback.print_exc()
|
||||
self._send(500, {'error': f'internal: {e}'})
|
||||
return
|
||||
|
||||
# --- execute (NO shell, argv only)
|
||||
|
||||
Reference in New Issue
Block a user