Cross-cutting runtime utilities used by orchestration, hooks, and plugin I/O.
spawnPane, closePane) used by tmux and zellij adapters.task tool sessions by parent session + agent type, normalizes user labels, assigns stable short aliases, and exposes prompt rendering/eviction behavior.task tool CLI output to recover task_id for resumption.SubagentDepthTracker maps session IDs → depth and is cleaned on session deletion.SessionManager groups tasks by {parentSessionId, agentType} and maintains LRU-ish ordering by last-used counter so active resumable sessions stay in memory.getEnv falls back from Bun.env to process.env and normalizes blank values.extractSessionResult/parseModelReference style helpers are centralized under session.ts.collapseSystemInPlace purposely mutates system array to preserve references held by OpenCode internals.pollUntilStable requires consecutive confirmations before success.subagent-depth.tsregisterChild(parentSessionId, childSessionId) computes childDepth = parentDepth + 1.DEFAULT_MAX_SUBAGENT_DEPTH.cleanup(sessionId) and cleanupAll() remove depth state for terminated sessions.session-manager.tsderiveTaskSessionLabel computes a deterministic prompt hint:
description if provided,prompt,recent {agentType} task.remember creates/reuses entries keyed by {parentSessionId, agentType} and enforces a per-agent max via trimGroup.exp-1, lib-2, etc.).markUsed, resolve, drop, dropTask, clearParent keep the store consistent on reuse and teardown.formatForPrompt returns grouped and ranked prompt text (### Resumable Sessions ...) for use in system transforms.tmux.tsspawnPane flow: validate enabled state → check multiplexer availability → resolve binary → execute attach command with layout handling.closePane flow: send SIGINT-equivalent key sequence → delay → terminate pane → rebalance layout if needed.isServerRunning flow: bounded /health checks with retries and caching.polling.tspollUntilStable(fn, options) repeatedly calls async predicate and tracks consecutive true states.session.tstask.tstask_id from task_id: <id> format.system-collapse.tscollapseSystemInPlace(system: string[]) joins all system entries using \n\n, clears and repopulates the same array reference, and preserves empty-array behavior.Consumers
src/multiplexer/*: SubagentDepthTracker and tmux.ts integration.src/council/council-manager.ts: depth control and session extraction helpers.src/hooks/*: marker detection, polling, and session-aware state helpers.src/hooks/task-session-manager: SessionManager, parseTaskIdFromTaskOutput, and deriveTaskSessionLabel provide resumable-session workflow; the plugin’s system-transform passes the hook output through collapseSystemInPlace after this manager injects prompts.Dependencies
../config (DEFAULT_MAX_SUBAGENT_DEPTH, polling intervals/timeouts).index.ts re-exports utility API (agent-variant, env, polling, logger, session, subagent-depth, etc.).