import { existsSync, readFileSync } from 'node:fs'; import { getWorkspaceConfigFile } from './init-command.js'; export const DEFAULT_RUNTIME_CYCLE_INTERVAL_MS = 100; export function readRuntimeCycleIntervalMs(path = getWorkspaceConfigFile()): number { const config = existsSync(path) ? JSON.parse(readFileSync(path, 'utf8')) : {}; if (!config || typeof config !== 'object' || Array.isArray(config) || config.runtime !== undefined && (!config.runtime || typeof config.runtime !== 'object' || Array.isArray(config.runtime))) { throw new TypeError('config.json runtime must be an object.'); } const value = config.runtime?.cycleIntervalMs === undefined ? DEFAULT_RUNTIME_CYCLE_INTERVAL_MS : config.runtime.cycleIntervalMs; if (!Number.isSafeInteger(value) || value < 1 || value > 60_000) { throw new TypeError('config.json runtime.cycleIntervalMs must be an integer from 1 to 60000.'); } return value; }