mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-12-04 06:21:59 +09:00
fix(hive-mind): refuse a role outside worker/specialist/scout on spawn and join
Co-Authored-By: RuFlo <ruv@ruv.net>
This commit is contained in:
1 parent
08fb7acf88
commit
77ca18dcde
2 files changed
+17
No files matched your search
@@ -116,6 +116,15 @@ describe('#4727 hive capacity and registered membership', () => {
|
||||
expect(read('agents.json').agents[agentId].config).toEqual({ role: 'worker', hiveRole: 'worker' });
|
||||
});
|
||||
|
||||
it('rejects a role outside the schema enum on spawn and join without writing', async () => {
|
||||
await run('hive-mind_init', { maxAgents: 4 });
|
||||
await register('agent-r');
|
||||
const before = snapshot();
|
||||
expect(await run('hive-mind_spawn', { count: 1, role: 'queen' })).toMatchObject({ success: false, error: expect.stringMatching(/role must be one of/) });
|
||||
expect(await run('hive-mind_join', { agentId: 'agent-r', role: 'queen' })).toMatchObject({ success: false, error: expect.stringMatching(/role must be one of/) });
|
||||
expect(snapshot()).toEqual(before);
|
||||
});
|
||||
|
||||
it('rejects unknown agents, including with a valid remote token, without writing', async () => {
|
||||
await run('hive-mind_init', { maxAgents: 2 });
|
||||
const before = snapshot();
|
||||
|
||||
@@ -388,6 +388,8 @@ function findAgent(store: HiveAgentStore, agentId: string): HiveAgentRecord | un
|
||||
return Object.prototype.hasOwnProperty.call(store.agents, agentId) ? store.agents[agentId] : undefined;
|
||||
}
|
||||
|
||||
const HIVE_ROLES = new Set(['worker', 'specialist', 'scout']);
|
||||
|
||||
function capacityError(state: HiveState, additionalWorkers: number): Record<string, unknown> | null {
|
||||
const maxAgents = state.maxAgents ?? 15;
|
||||
if (state.workers.length + additionalWorkers <= maxAgents) return null;
|
||||
@@ -445,6 +447,9 @@ export const hiveMindTools: MCPTool[] = [
|
||||
const full = capacityError(state, count);
|
||||
if (full) return full;
|
||||
const role = (input.role as string) || 'worker';
|
||||
if (!HIVE_ROLES.has(role)) {
|
||||
return { success: false, error: `role must be one of: ${[...HIVE_ROLES].join(', ')}` };
|
||||
}
|
||||
const agentType = (input.agentType as string) || 'worker';
|
||||
const prefix = (input.prefix as string) || 'hive-worker';
|
||||
const agentStore = loadAgentStore();
|
||||
@@ -775,6 +780,9 @@ export const hiveMindTools: MCPTool[] = [
|
||||
return { success: false, agentId, error: 'Agent not found. Register it with agent_spawn or hive-mind_spawn first.' };
|
||||
}
|
||||
const role = (input.role as string) || 'worker';
|
||||
if (!HIVE_ROLES.has(role)) {
|
||||
return { success: false, agentId, error: `role must be one of: ${[...HIVE_ROLES].join(', ')}` };
|
||||
}
|
||||
for (const { path, store, agent } of records) {
|
||||
agent.config = { ...(agent.config as Record<string, unknown>), role, hiveRole: role };
|
||||
saveAgentStore(store, path);
|
||||
|
||||
Reference in new issue
Block a user