{"version":3,"file":"types-B3WIUo4S.mjs","names":[],"sources":["../src/config/types.ts"],"sourcesContent":["// Commander config model — the user-facing `commander.config.ts` shape plus the resolved,\n// fully-defaulted model the daemon/CLI operate on. House conventions: interfaces I*, aliases T*.\n// The public `./config` export carries ONLY these types + `defineCommanderConfig` — no loader,\n// no validation deps.\n\nimport type {\n  INiceProcessRestartOptions,\n  INiceProcessStopOptions,\n  TNiceProcessKind,\n  TNiceProcessReady,\n  TNiceProcessRun,\n  TNiceProcessShell,\n} from \"@nice-code/process\";\n\n/** Ids appear in CLI selectors, URLs and ledger filenames — never option-shaped (edge 31). */\nexport const COMMANDER_ID_PATTERN = /^[a-z0-9][a-z0-9_-]{0,63}$/;\n\n/** The built-in selection word a config may never redefine. */\nexport const RESERVED_SELECTOR_NAME = \"all\";\n\n/** The literal ids a config declared, or `never` once they widened to `string` (built at runtime). */\ntype TKnownIds<TId extends string> = string extends TId ? never : TId;\n\nexport type TCommanderEndpointProtocol = \"tcp\" | \"http\";\nexport type TCommanderEndpointOwnership = \"exclusive\" | \"shared\" | \"observed\";\n\nexport interface ICommanderEndpointHealth {\n  /** HTTP path probed for readiness sugar / health badges. Default \"/\". */\n  path?: string;\n  /** Bounded body read must contain this marker. */\n  match?: string;\n}\n\nexport interface ICommanderEndpoint<TEndpointName extends string = string> {\n  /** Unique per process; referenced by `ready: { kind: \"endpoint\" }` and UI badges. */\n  name: TEndpointName;\n  protocol: TCommanderEndpointProtocol;\n  host?: string;\n  port: number;\n  /**\n   * `exclusive` must resolve to this owned tree; `shared` must match a compatible explicit\n   * sharing declaration; `observed` may be external and is never killed or claimed.\n   */\n  ownership: TCommanderEndpointOwnership;\n  url?: string;\n  health?: ICommanderEndpointHealth;\n}\n\n/**\n * Readiness sugar: `ready: { kind: \"endpoint\", endpoint: \"web\" }` expands against the named\n * endpoint — tcp → `port` readiness, http → `httpOk` against `health.path` (+ `health.match`).\n */\nexport type TCommanderReady<TEndpointName extends string = string> =\n  | TNiceProcessReady\n  | { kind: \"endpoint\"; endpoint: TEndpointName; timeoutMs?: number; healthProbeMs?: number };\n\n/**\n * A variable this process reads, declared so the UI and CLI can offer it. Declaring a knob is what\n * makes it settable at all: `nice-commander env` and the web UI can only touch names that appear\n * here, so no viewer can inject arbitrary environment into an arbitrary process.\n */\nexport interface ICommanderEnvVar {\n  /** The variable as the process reads it. */\n  name: string;\n  /** One line — shown beside the value in `env` and in the UI. */\n  description?: string;\n  /** Used when nothing overrides it. Declaring it here replaces writing it in `env`. */\n  default?: string;\n  /** Closed set: the UI renders a picker, and a value outside it is refused. */\n  values?: readonly string[];\n  /**\n   * Never leaves the daemon — not on the realm, not in CLI output, not in logs.\n   * ⚠ Defaults to TRUE for names that look like credentials (see `looksSecret`); pass `false`\n   * explicitly to publish one. The unsafe direction is the one you have to type.\n   */\n  secret?: boolean;\n  /** A start refuses unless a value is in hand (default, override, or inherited). */\n  required?: boolean;\n}\n\n/**\n * A switch a start may turn on to append arguments to `run` — one definition, several ways to run\n * it. Like `envVars`, declaring it is what makes it passable at all: the daemon appends only\n * declared flags, so a viewer can pick a variant but never inject an argument.\n */\nexport interface ICommanderFlag {\n  /** What a start names it by — `run dev-reset --with clean`, the UI's toggle. Same charset as ids. */\n  name: string;\n  /** Appended to `run`, in declaration order, when the flag is on. Default `[\"--<name>\"]`. */\n  args?: readonly string[];\n  /** One line — shown beside the toggle and in `explain`. */\n  description?: string;\n}\n\n/**\n * The type parameters are what `defineCommanderConfig` infers from the whole config: every\n * declared process id and endpoint name, so a reference to one that does not exist is a type error.\n */\nexport interface ICommanderProcessDefinition<\n  TProcessId extends string = string,\n  TEndpointName extends string = string,\n> {\n  id: TProcessId;\n  /** Default from `defaults.kind`, else \"service\". */\n  kind?: TNiceProcessKind;\n  /** Relative cwd resolves against the config file's realpath directory, never the shell's. */\n  cwd?: string;\n  run: TNiceProcessRun;\n  shell?: TNiceProcessShell;\n  /**\n   * Merged over the daemon's base env; `null` unsets. Values the operator is not meant to tune —\n   * a knob goes in `envVars`, and a name may not appear in both.\n   */\n  env?: Record<string, string | null>;\n  /** Variables this process reads, offered for setting in the UI/CLI. */\n  envVars?: readonly ICommanderEnvVar[];\n  /**\n   * Switches a start may turn on (`--with <name>`, or the UI's toggles). A plain start runs `run`\n   * as written. ⚠ With a shell-string `run`, each arg must be shell-plain — it is appended unquoted.\n   */\n  flags?: readonly ICommanderFlag[];\n  /** Default \"pipe\" (held open until stop); \"ignore\" is an instant EOF. */\n  stdin?: \"pipe\" | \"ignore\";\n  /**\n   * Free-form; `role` and `project` are the house convention. A key may carry several values —\n   * `project: [\"api\", \"billing\"]` matches both `project=api` and `project=billing`.\n   */\n  tags?: Record<string, string | readonly string[]>;\n  /**\n   * Never swept up in bulk: a tag selection, a suite's `where` and `all` all skip it. It starts\n   * only by exact id, by a suite's explicit `include`, or as a declared dependency.\n   */\n  optIn?: boolean;\n  /**\n   * Transitive: starting this starts each dependency first and waits for it — service\n   * dependencies until ready, task dependencies until succeeded. Acyclic, validated at load.\n   */\n  dependsOn?: readonly NoInfer<TProcessId>[];\n  endpoints?: ICommanderEndpoint<TEndpointName>[];\n  /**\n   * A start that finds an `exclusive` endpoint held by a STRAY — this same command (argv + cwd)\n   * running outside the daemon, typically started by hand in a terminal that has since gone —\n   * stops that tree and takes the port, instead of refusing. A stranger on the port still\n   * refuses. Default false; `up --replace-same` does the same for one invocation.\n   */\n  replaceSame?: boolean;\n  /** Primary \"open\" link when no endpoint owns it. */\n  url?: string;\n  /** An `endpoint` readiness names an endpoint of this same process (checked at load). */\n  ready?: TCommanderReady<NoInfer<TEndpointName>>;\n  stop?: INiceProcessStopOptions;\n  /** Automatic restart is service-only in v1; a task is explicitly rerun. */\n  restart?: INiceProcessRestartOptions;\n  /** Ring tuning only — the on-disk sink is daemon-anchored (D6), not config-addressable. */\n  log?: { ringLines?: number; ringBytes?: number; lineBytes?: number };\n  /** Tasks only: hard cap on run time so a hung check can't hang a suite run forever. */\n  timeoutMs?: number;\n}\n\n/** Tag query: every entry must match (AND). An array of queries is OR'd. */\nexport type TCommanderTagQuery = Record<string, string>;\nexport type TCommanderTagQueryOr = TCommanderTagQuery | readonly TCommanderTagQuery[];\n\n/**\n * A named run-unit: several processes you mean to run as ONE thing (`verify`, `dev`). A label is\n * a tag — a suite must resolve to at least two members.\n */\nexport interface ICommanderSuiteDefinition<\n  TProcessId extends string = string,\n  TSuiteName extends string = string,\n> {\n  /** One line — shown on the suite's card and in `list`. */\n  description?: string;\n  /** Tag-equality selection: OR of AND-maps. Skips `optIn` processes. */\n  where?: TCommanderTagQueryOr;\n  /** Process ids and/or other suite names. Suite references must be acyclic. */\n  include?: readonly NoInfer<TProcessId | TSuiteName>[];\n  /** Excluded ids and/or tag queries, applied last. */\n  exclude?: readonly (NoInfer<TProcessId> | TCommanderTagQuery)[] | TCommanderTagQuery;\n  /** How many tasks run at once. Default 4. */\n  parallel?: number;\n  /** Stop scheduling tasks after the first failure. Default false. */\n  failFast?: boolean;\n  /** Delay between service spawns (no thundering herd of 17 tsc watchers). Default 100. */\n  staggerMs?: number;\n}\n\nexport interface ICommanderDefaults {\n  kind?: TNiceProcessKind;\n  /** See `ICommanderProcessDefinition.replaceSame`. */\n  replaceSame?: boolean;\n  stop?: INiceProcessStopOptions;\n  restart?: INiceProcessRestartOptions;\n  log?: { ringLines?: number; ringBytes?: number; lineBytes?: number };\n  tags?: Record<string, string | readonly string[]>;\n}\n\n/** One `key=value` selection term. */\nexport type TCommanderTagTerm = `${string}=${string}`;\n\nexport interface ICommanderConfig<\n  TProcessId extends string = string,\n  TSuiteName extends string = string,\n  TEndpointName extends string = string,\n> {\n  /** Config name — also the data-dir slug seed (D6). Same charset as ids. */\n  name: string;\n  defaults?: ICommanderDefaults;\n  processes: ICommanderProcessDefinition<TProcessId, TEndpointName>[];\n  /** Keyed by suite name — never `all` (the built-in selector) and never a process id. */\n  suites?: {\n    [TName in TSuiteName]: TName extends typeof RESERVED_SELECTOR_NAME\n      ? `'${TName}' is the built-in selector: pick another suite name`\n      : TName extends TKnownIds<TProcessId>\n        ? `'${TName}' is already a process id: pick another suite name`\n        : ICommanderSuiteDefinition<TProcessId, TSuiteName>;\n  };\n  /**\n   * Selection used by a bare `up` — a suite name, a process id, or one `tag=value` term. Without\n   * it, bare `up` prints the available suites and exits without mutating anything.\n   */\n  defaultSelection?: NoInfer<TProcessId | TSuiteName> | TCommanderTagTerm;\n  /** @deprecated Removed: organise processes with `tags`, and declare a run-unit under `suites`. */\n  groups?: \"`groups` was removed: organise processes with `tags`, and declare run-units under `suites`\";\n  /** Local config helpers the D2 loader cannot discover automatically (repo-relative). */\n  watchFiles?: readonly string[];\n  daemon?: {\n    /** Base port for the bounded scan-up on collision. Default 4900. */\n    port?: number;\n  };\n}\n\n// ---------------------------------------------------------------------------\n// Resolved model — validated, fully defaulted, config-dir-anchored. Produced by\n// `validateCommanderConfig`; consumed by the daemon, CLI and hash module.\n\nexport interface IResolvedCommanderEndpoint {\n  name: string;\n  protocol: TCommanderEndpointProtocol;\n  host: string;\n  port: number;\n  ownership: TCommanderEndpointOwnership;\n  url?: string;\n  health?: ICommanderEndpointHealth;\n}\n\n/** A declaration with every default filled in — `secret`/`required` are booleans by here. */\nexport interface IResolvedCommanderEnvVar {\n  name: string;\n  description?: string;\n  default?: string;\n  values?: string[];\n  secret: boolean;\n  required: boolean;\n}\n\nexport interface IResolvedCommanderFlag {\n  name: string;\n  args: string[];\n  description?: string;\n}\n\nexport interface IResolvedCommanderProcess {\n  id: string;\n  kind: TNiceProcessKind;\n  /** Absolute, anchored at the config's realpath directory. */\n  cwd: string;\n  run: TNiceProcessRun;\n  shell?: TNiceProcessShell;\n  /** `env` with every declared `default` folded in — what a spawn uses before overrides. */\n  env: Record<string, string | null>;\n  envVars: IResolvedCommanderEnvVar[];\n  flags: IResolvedCommanderFlag[];\n  stdin: \"pipe\" | \"ignore\";\n  /** Every value a list by here — a single-valued tag is a list of one. */\n  tags: Record<string, string[]>;\n  optIn: boolean;\n  dependsOn: string[];\n  endpoints: IResolvedCommanderEndpoint[];\n  /** A stray on an exclusive endpoint is replaced on start (see the definition's doc). */\n  replaceSame: boolean;\n  url?: string;\n  /** Endpoint sugar already expanded to a concrete nice-process readiness. */\n  ready?: TNiceProcessReady;\n  stop: INiceProcessStopOptions;\n  restart?: INiceProcessRestartOptions;\n  log: { ringLines?: number; ringBytes?: number; lineBytes?: number };\n  timeoutMs?: number;\n  /** Hash of this fully-defaulted definition — stale detection + task-result validity (D6). */\n  definitionHash: string;\n}\n\nexport interface IResolvedCommanderSuite {\n  name: string;\n  description?: string;\n  /** Fully expanded (includes, tag queries, nested suites, excludes applied), deduped,\n   *  in config order. */\n  ids: string[];\n  parallel: number;\n  failFast: boolean;\n  staggerMs: number;\n}\n\nexport interface IResolvedCommanderConfig {\n  name: string;\n  /** Realpath of the loaded config file. */\n  configPath: string;\n  /** Realpath directory — the anchor for every relative cwd (edge 32). */\n  configDir: string;\n  /** D6 identity: slug + hash8 of the config realpath — stable across edits, moves state. */\n  configKey: string;\n  /** Hash of the canonical resolved model — a comment-only edit never bumps it. */\n  configRevisionHash: string;\n  processes: IResolvedCommanderProcess[];\n  suites: Record<string, IResolvedCommanderSuite>;\n  defaultSelection?: string;\n  /** Absolute paths (config file + declared watchFiles). */\n  watchFiles: string[];\n  daemon: { port: number };\n  /** Non-fatal findings (duplicate exclusive endpoints, empty suites, …). */\n  warnings: string[];\n}\n"],"mappings":";;AAeA,MAAa,uBAAuB"}