feat(autonomy): autonomous swarm worker orchestration, nudge triggers, and recursive loop
This commit is contained in:
@@ -562,6 +562,34 @@ def _cron_runs_build(a):
|
||||
return [sys.executable, os.path.join(BIN_DIR, 'box-ctl.py'), 'job-list']
|
||||
|
||||
|
||||
def _cron_timer_start_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_timer_start_build(a):
|
||||
return [sys.executable, os.path.join(BIN_DIR, 'box-ctl.py'), 'timer-start', a['name']]
|
||||
|
||||
|
||||
def _cron_timer_create_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_timer_create_build(a):
|
||||
return [sys.executable, os.path.join(BIN_DIR, 'box-ctl.py'), 'timer-create', a['name']]
|
||||
|
||||
|
||||
def _vars_list_validate(raw):
|
||||
if raw not in ({}, None):
|
||||
raise OpError('vars.list takes no required args')
|
||||
@@ -705,6 +733,55 @@ def _service_restart_build(a):
|
||||
return [sys.executable, os.path.join(BIN_DIR, 'box-sys-op.py'), 'service.restart']
|
||||
|
||||
|
||||
def _swarm_spawn_validate(raw):
|
||||
if not isinstance(raw, dict):
|
||||
raise OpError('args must be an object')
|
||||
allowed = {'count', 'task', 'label'}
|
||||
for k in raw:
|
||||
if k not in allowed:
|
||||
raise OpError(f'unknown arg: {k}')
|
||||
count = _opt_int(raw.get('count', 1), 1, 50, 'count') or 1
|
||||
task = _clean_message(raw.get('task'))
|
||||
label = raw.get('label')
|
||||
if label and not TARGET_RE.fullmatch(str(label)):
|
||||
raise OpError('label must match safe identifier')
|
||||
return {'count': count, 'task': task, 'label': str(label) if label else None}
|
||||
|
||||
|
||||
def _swarm_spawn_build(a):
|
||||
cmd = [sys.executable, os.path.join(BIN_DIR, 'box-ctl.py'), 'swarm-spawn', str(a['count']), a['task']]
|
||||
if a.get('label'):
|
||||
cmd.extend(['--label', a['label']])
|
||||
return cmd
|
||||
|
||||
|
||||
def _swarm_status_validate(raw):
|
||||
if not isinstance(raw, dict):
|
||||
raise OpError('args must be an object')
|
||||
allowed = {'swarm_id', 'id'}
|
||||
for k in raw:
|
||||
if k not in allowed:
|
||||
raise OpError(f'unknown arg: {k}')
|
||||
sid = raw.get('swarm_id') or raw.get('id')
|
||||
if not isinstance(sid, str) or not TARGET_RE.fullmatch(sid):
|
||||
raise OpError('swarm_id must match safe identifier')
|
||||
return {'swarm_id': sid}
|
||||
|
||||
|
||||
def _swarm_status_build(a):
|
||||
return [sys.executable, os.path.join(BIN_DIR, 'box-ctl.py'), 'swarm-status', a['swarm_id']]
|
||||
|
||||
|
||||
def _swarm_list_validate(raw):
|
||||
if raw not in ({}, None):
|
||||
raise OpError('swarm.list takes no required args')
|
||||
return {}
|
||||
|
||||
|
||||
def _swarm_list_build(a):
|
||||
return [sys.executable, os.path.join(BIN_DIR, 'box-ctl.py'), 'swarm-list']
|
||||
|
||||
|
||||
# op -> {validate, build, timeout, side_effecting, description}
|
||||
OPS = {
|
||||
'dm.send': {
|
||||
@@ -782,6 +859,16 @@ OPS = {
|
||||
'timeout': 300, 'side_effecting': True,
|
||||
'desc': 'Trigger on-demand execution of a scheduled job',
|
||||
},
|
||||
'cron.timer_create': {
|
||||
'validate': _cron_timer_create_validate, 'build': _cron_timer_create_build,
|
||||
'timeout': 30, 'side_effecting': True,
|
||||
'desc': 'Create systemd user timer unit for a job',
|
||||
},
|
||||
'cron.timer_start': {
|
||||
'validate': _cron_timer_start_validate, 'build': _cron_timer_start_build,
|
||||
'timeout': 30, 'side_effecting': True,
|
||||
'desc': 'Enable and start systemd user timer unit for a job',
|
||||
},
|
||||
'vars.list': {
|
||||
'validate': _vars_list_validate, 'build': _vars_list_build,
|
||||
'timeout': 30, 'side_effecting': False,
|
||||
@@ -822,6 +909,21 @@ OPS = {
|
||||
'timeout': 30, 'side_effecting': True,
|
||||
'desc': 'Restart allowlisted fleet systemd service',
|
||||
},
|
||||
'swarm.spawn': {
|
||||
'validate': _swarm_spawn_validate, 'build': _swarm_spawn_build,
|
||||
'timeout': 30, 'side_effecting': True,
|
||||
'desc': 'Spawn autonomous subagent swarm slots managed by Box',
|
||||
},
|
||||
'swarm.status': {
|
||||
'validate': _swarm_status_validate, 'build': _swarm_status_build,
|
||||
'timeout': 30, 'side_effecting': False,
|
||||
'desc': 'Inspect subagent swarm status and progress',
|
||||
},
|
||||
'swarm.list': {
|
||||
'validate': _swarm_list_validate, 'build': _swarm_list_build,
|
||||
'timeout': 30, 'side_effecting': False,
|
||||
'desc': 'List all subagent swarms and their counts',
|
||||
},
|
||||
'exec.ping': {
|
||||
'validate': _health_validate,
|
||||
'build': lambda a: ['/bin/echo', 'PONG'],
|
||||
|
||||
Reference in New Issue
Block a user