Skip to content

Events and errors ​

Event bus (shared/events.ts) ​

Bus is an in-process pub/sub with a bounded recent buffer (daemon uses 2048).

ts
type BusEvent = {
  type: EventType;
  timestamp: string;
  service?: string;
  payload?: Record<string, unknown>;
};

Known types (string constants — extra plugin strings are allowed):

TypeTypical publisher
ServiceStarted / ServiceStopped / ServiceFailedOrchestrator / health monitor
ServiceStateChanged / ServiceHealthChangedSupervisor setState, health monitor
LogReceivedLog store path
TokenRefreshed / TokenRefreshFailedTokenManager
AuthenticationChangedIdentity coordinator
ProxyStarted / ProxyStopped / ProxyRequestProxy coordinator / proxy server
ConfigurationChanged / ConfigurationReloadFailedReload
SessionRecoveredRecover

subscribe(handler, types?) — empty types means all. RPC server uses that after auth.

Do not wait on an event to complete a command. start() returns a Plan after waves finish (or throw). Events exist so other clients repaint.

Errors (shared/errors.ts) ​

DevctlError carries kind, hint, service, optional cause.

KindCLI exit
configuration, configuration_missing, service_not_found, dependency2
authentication, token, iap3
authorization, impersonation4
process_start5
health_check6
proxy7
general1

Success is 0. configuration_missing is distinct so setup can run and loadOrEmpty can swallow only that kind.

Helpers: newError, wrapError, hintError, humanMessage, serializeError (RPC), parseError (client), exitCode, isKind.

RPC errors serialize to { error, kind, hint, service } on the envelope. The client reconstructs DevctlError.

Retry (shared/retry.ts) ​

Network/token operations may retry with backoff. Configuration errors must not. If you add a retry, gate it on kind (or on the callee), never a blanket catch.

Other shared modules ​

FileRole
bearer.tsConstant-time secret compare (secretMatches, bearerMatches)
headers.tsHeader lookup without throwing on malformed requests
redaction.tsDetector used when presentation cannot import the secrets adapter
repo-id.tssha256 → 16 hex
mcp-token.tsMCP/web session token age and optional TTL helpers
warnings.tsMute noisy GCP metadata logs; hold stderr for TUI
sliding-window.tsRate/window helpers
terminal-restore.tsReset terminal modes on TUI exit (including crashes)

types.ts at src/ is only Envelope. Do not dump more shared types there.

Released under the MIT License. Use at your own risk.