Super Multica — Parent-child agent spawning, lifecycle management, and result announcement
sessions_spawn tool.
Receives announcement messages when child agents complete.
createSubagent(),
getAgent(), closeAgent(). Calls registry init on startup, shutdown on exit.
isSubagent: true. Restricted tools (no sessions_spawn).
Custom system prompt: stay focused, no user messaging, no nested spawning.
parentAgent.write().
~/.super-multica/subagents/runs.json.
Schema: { version: 1, runs: {...} }. Survives process restarts.
sessions_spawn tool{ task, label?, model?, cleanup?, timeoutSeconds? }.
Guard rejects if isSubagent === true.
runId = UUIDv7, childSessionId = UUIDv7.
buildSubagentSystemPrompt() creates prompt with task context, rules (no nested spawn, stay focused).
hub.createSubagent(childSessionId, { systemPrompt, model })
creates an AsyncAgent with isSubagent: true. Not persisted to agent store (ephemeral).
childAgent.write(task) enqueues the task to the serial queue.
This happens before registration so waitForIdle() observes queued work.
registerSubagentRun() saves record to in-memory Map + JSON file.
Sets createdAt, starts archive sweeper.
watchChildAgent() sets startedAt.
Attaches childAgent.waitForIdle() (promise resolves when task queue drained)
and childAgent.onClose() callback. Optionally sets timeout timer.
Tool returns { status: "accepted", childSessionId, runId } immediately.
exec, glob, web_fetch etc. but NOT sessions_spawn.
waitForIdle() resolvesendedAt, outcome: { status: "ok" }.
Persists updated record to JSON.
readLatestAssistantReply(childSessionId) reads session JSONL, extracts last assistant text.
formatAnnouncementMessage() builds summary with task, status, findings, runtime.
parentAgent.write(message) delivers to parent.
cleanup === "delete": removes child session directory + closes agent in Hub.
Schedules archive at now + 60min. Sweeper removes from registry after TTL.
ok — Task completed normally (waitForIdle resolved)
error — Child agent threw an error
timeout — Exceeded timeoutSeconds limit
unknown — Process crash or Hub shutdown
Hub.consumeAgent() already reads the stream for forwarding events.
Registry uses waitForIdle() (promise on internal task queue) to detect completion without competing for the stream.
setHub/getHub) bridges this gap, with isHubInitialized() guard for test safety.
initSubagentRegistry()
loads persisted runs: completed-but-unannounced runs trigger announce flow; unfinished runs are marked as
status: "unknown".
isSubagent: true which applies tool deny-list (blocks sessions_spawn).
System prompt explicitly forbids nested spawning, direct user communication, and off-topic work.
Sessions are ephemeral — deleted after announce unless cleanup: "keep".