Implementation:AIScientists Dev WorldSeed useCommands
| Knowledge Sources | |
|---|---|
| Domains | Frontend, UI |
| Last Updated | 2026-10-26 18:00 GMT |
Overview
Concrete React hook providing GM command actions with a three-layer feedback architecture, provided by the WorldSeed frontend.
Description
The useCommands hook returns command functions for GM interactions: `cmdPause`/`cmdResume`/`cmdStep`/`cmdStop` for tick control, `cmdLoadRun` for resuming past runs, `cmdWhisper` with optimistic inbox injection and rollback, `cmdGmNotify` for waking agents, `cmdGmResolve` with inline feedback, `cmdConnectAgents`/`cmdGatewayRestart` for async admin ops, and `onSpeedChange` for tick interval. Feedback follows three layers: Layer 1 (state is feedback — no toast for pause/stop/navigation), Layer 2 (inline feedback — optimistic updates, transient button states, gmFeedback string), Layer 3 (toast — only errors + rare async admin operations).
Usage
Import this hook in any component that needs GM controls — e.g., the header bar, theater control bar, and GM pill components call these commands on button clicks.
Code Reference
Source Location
- Repository: WorldSeed
- File: frontend/src/hooks/useCommands.ts
Signature
export function useCommands(): {
cmdPause: () => Promise<void>;
cmdResume: () => Promise<void>;
cmdStep: () => Promise<{ ok: boolean }>;
cmdStop: () => Promise<void>;
cmdLoadRun: (runId: string) => Promise<void>;
cmdWhisper: (agentId: string) => Promise<{ ok: boolean; notified: boolean }>;
cmdGmNotify: (agentId: string) => Promise<boolean>;
cmdGmResolve: () => Promise<void>;
cmdConnectAgents: () => Promise<void>;
cmdGatewayRestart: () => Promise<void>;
onSpeedChange: (event: any) => Promise<void>;
};
Import
import { useCommands } from '@/hooks/useCommands';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| agentId | string | Yes (whisper/notify) │ Agent ID to whisper to or wake | |
| runId | string | Yes (loadRun) │ Run ID to resume | |
| event | Event | Yes (speed) │ Change event with speed value |
Outputs
| Name | Type | Description |
|---|---|---|
| cmdWhisper returns | { ok, notified } │ Whisper success + whether agent was notified | |
| cmdGmNotify returns | boolean │ Whether wake succeeded | |
| side effects | None │ Updates Zustand stores, navigates, shows toasts |
Usage Examples
import { useCommands } from '@/hooks/useCommands';
function HeaderBar() {
const { cmdPause, cmdResume, cmdStop } = useCommands();
return (
<div>
<button onClick={cmdPause}>Pause</button>
<button onClick={cmdResume}>Resume</button>
<button onClick={cmdStop}>Stop</button>
</div>
);
}