@nice-code/commander 0.95.0 → 0.96.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { A as effectiveEnv, C as wsAcceptorCarrier, D as RuntimeCoordinate, E as ActionRuntime, F as withDependencies, I as readInstanceRecord, L as recordDaemonAlive, M as overrideFingerprint, N as loadCommanderConfigFile, O as createMemoryStorageAdapter_json, P as orderByDependency, R as removeInstanceRecord, S as httpAcceptorCarrier, T as createDefaultServeLogger, _ as commanderStatePaths, a as createPortInspector, b as createRealmAcceptor, f as COMMANDER_TICKET_PROTOCOL_PREFIX, g as commanderPackageVersion, h as commanderRuntimeError, i as readEnvOverrides, j as envVarViews, k as validateCommanderConfig, m as commanderStatusRealm, n as applyEnvMutation, o as commanderChannel, r as countOverrides, s as commanderControlDomain, t as parseLogsClientMessage, v as ensureStateDir, w as serveChannel, x as createRealmServerEngine, y as resolveCommanderDataDir, z as writeInstanceRecord } from "./cli.mjs";
1
+ import { A as ActionRuntime, B as withDependencies, C as resolveCommanderDataDir, D as wsAcceptorCarrier, E as httpAcceptorCarrier, F as envVarViews, G as writeInstanceRecord, H as readInstanceRecord, I as overrideFingerprint, L as hashCanonical, M as createMemoryStorageAdapter_json, N as validateCommanderConfig, O as serveChannel, P as effectiveEnv, R as loadCommanderConfigFile, S as ensureStateDir, T as createRealmServerEngine, U as recordDaemonAlive, V as savedFilterId, W as removeInstanceRecord, a as parseLogsClientMessage, b as commanderPackageVersion, c as countOverrides, d as commanderControlDomain, g as COMMANDER_TICKET_PROTOCOL_PREFIX, i as runTaskPool, j as RuntimeCoordinate, k as createDefaultServeLogger, l as readEnvOverrides, n as readSavedFilters, o as createPortInspector, r as writeSavedFilters, s as applyEnvMutation, t as mutateSavedFilters, u as commanderChannel, v as commanderStatusRealm, w as createRealmAcceptor, x as commanderStatePaths, y as commanderRuntimeError, z as orderByDependency } from "./cli.mjs";
2
2
  import { readFile, realpath, stat } from "node:fs/promises";
3
3
  import { extname, isAbsolute, join, normalize, relative, resolve, sep } from "node:path";
4
4
  import { createNiceProcess, openProcessLedger, readProcessStartStamp, signalProcessGroup, taskkillTree } from "@nice-code/process";
@@ -364,6 +364,129 @@ function watchCommanderConfig(options) {
364
364
  };
365
365
  }
366
366
  //#endregion
367
+ //#region src/daemon/suiteRuns.ts
368
+ /** Tasks a tag-group run starts at once — a suite declares its own. */
369
+ const TAG_GROUP_PARALLEL = 4;
370
+ function createSuiteRunner(options) {
371
+ const { supervisor, publish, log } = options;
372
+ const runs = /* @__PURE__ */ new Map();
373
+ const live = /* @__PURE__ */ new Map();
374
+ const verdictOf = (report, id) => {
375
+ const outcome = report.results.find((result) => result.id === id)?.outcome;
376
+ if (outcome === "blocked") return "blocked";
377
+ return outcome === "failed" || outcome == null ? "fail" : "pass";
378
+ };
379
+ const evictTagGroupRuns = () => {
380
+ const ended = [...runs.entries()].filter(([, run]) => run.suite == null && run.endedAt != null).sort(([, a], [, b]) => (b.endedAt ?? 0) - (a.endedAt ?? 0));
381
+ for (const [key] of ended.slice(8)) {
382
+ runs.delete(key);
383
+ publish(key, null);
384
+ }
385
+ };
386
+ return {
387
+ idle: async () => {
388
+ await Promise.all(live.values());
389
+ },
390
+ run: (input) => {
391
+ const config = supervisor.config;
392
+ const suite = input.suite == null ? void 0 : config.suites[input.suite];
393
+ if (input.suite != null && suite == null) return {
394
+ accepted: false,
395
+ reason: `unknown suite "${input.suite}"`
396
+ };
397
+ const known = new Set(config.processes.map((proc) => proc.id));
398
+ const direct = (suite?.ids ?? input.ids ?? []).filter((id) => known.has(id));
399
+ if (direct.length === 0) return {
400
+ accepted: false,
401
+ reason: "nothing to run"
402
+ };
403
+ const filterId = input.filter == null ? void 0 : savedFilterId(input.filter);
404
+ const runKey = suite?.name ?? `tg-${hashCanonical(filterId ?? [...direct].sort(), 12)}`;
405
+ if (live.has(runKey)) return {
406
+ accepted: false,
407
+ runKey,
408
+ reason: "already running"
409
+ };
410
+ const ordered = orderByDependency(config.processes, withDependencies(config.processes, direct));
411
+ const byId = new Map(config.processes.map((proc) => [proc.id, proc]));
412
+ const definitions = ordered.flatMap((id) => byId.get(id) ?? []);
413
+ const services = definitions.filter((proc) => proc.kind === "service");
414
+ const tasks = definitions.filter((proc) => proc.kind === "task");
415
+ const previous = runs.get(runKey);
416
+ const run = {
417
+ ...suite != null ? { suite: suite.name } : {},
418
+ ...filterId != null ? { filterId } : {},
419
+ startedAt: Date.now(),
420
+ ...previous?.endedAt != null ? { previousDurationMs: previous.endedAt - previous.startedAt } : {},
421
+ members: Object.fromEntries(ordered.map((id) => [id, "pending"]))
422
+ };
423
+ const announce = () => publish(runKey, {
424
+ ...run,
425
+ members: { ...run.members }
426
+ });
427
+ const mark = (id, verdict) => {
428
+ run.members[id] = verdict;
429
+ announce();
430
+ };
431
+ runs.set(runKey, run);
432
+ announce();
433
+ const execute = async () => {
434
+ const satisfied = /* @__PURE__ */ new Set();
435
+ if (services.length > 0) {
436
+ for (const proc of services) mark(proc.id, "running");
437
+ const report = await supervisor.start(services.map((proc) => proc.id), {
438
+ wait: true,
439
+ staggerMs: suite?.staggerMs ?? 0
440
+ });
441
+ for (const proc of services) mark(proc.id, verdictOf(report, proc.id));
442
+ for (const result of report.results) {
443
+ if (byId.get(result.id)?.kind !== "task") continue;
444
+ mark(result.id, result.outcome === "succeeded" ? "pass" : "fail");
445
+ if (result.outcome === "succeeded") satisfied.add(result.id);
446
+ }
447
+ }
448
+ const pool = await runTaskPool({
449
+ tasks: tasks.filter((task) => run.members[task.id] === "pending"),
450
+ parallel: input.parallel ?? suite?.parallel ?? TAG_GROUP_PARALLEL,
451
+ failFast: input.failFast ?? suite?.failFast ?? false,
452
+ run: async (task) => {
453
+ mark(task.id, "running");
454
+ const verdict = verdictOf(await supervisor.start([task.id], {
455
+ wait: true,
456
+ satisfied
457
+ }), task.id);
458
+ if (verdict === "pass") satisfied.add(task.id);
459
+ mark(task.id, verdict);
460
+ return verdict === "pass";
461
+ },
462
+ onBlocked: (task) => mark(task.id, "blocked"),
463
+ onFailFast: () => {
464
+ const running = tasks.filter((task) => run.members[task.id] === "running").map((task) => task.id);
465
+ if (running.length > 0) supervisor.stop(running);
466
+ }
467
+ });
468
+ for (const task of pool.leftover) mark(task.id, "skipped");
469
+ run.endedAt = Date.now();
470
+ run.outcome = Object.values(run.members).every((verdict) => verdict === "pass") ? "passed" : "failed";
471
+ announce();
472
+ log(`run ${runKey}: ${run.outcome} in ${run.endedAt - run.startedAt} ms`);
473
+ evictTagGroupRuns();
474
+ };
475
+ const settled = execute().catch((error) => {
476
+ run.endedAt = Date.now();
477
+ run.outcome = "failed";
478
+ announce();
479
+ log(`run ${runKey}: aborted — ${error.message}`);
480
+ }).finally(() => live.delete(runKey));
481
+ live.set(runKey, settled);
482
+ return {
483
+ accepted: true,
484
+ runKey
485
+ };
486
+ }
487
+ };
488
+ }
489
+ //#endregion
367
490
  //#region src/daemon/controlPlane.ts
368
491
  const DAEMON_COORD = RuntimeCoordinate.env("commander_daemon");
369
492
  const SLOW_CONSUMER_DROP_BYTES = 256 * 1024;
@@ -407,6 +530,7 @@ function projectProcess(status) {
407
530
  notes: status.capability.notes
408
531
  } } : {},
409
532
  tags: status.tags,
533
+ optIn: status.optIn,
410
534
  detail: {
411
535
  command: status.detail.command,
412
536
  cwd: status.detail.cwd,
@@ -437,8 +561,13 @@ function projectProcess(status) {
437
561
  * Members are projected in DAG order (the same `orderByDependency` `up` spawns with), so the
438
562
  * UI's "members in dependency order" and the CLI's execution order are one rule, not two.
439
563
  */
440
- function projectGroups(config) {
441
- return Object.fromEntries(Object.entries(config.groups).map(([name, group]) => [name, { members: orderByDependency(config.processes, new Set(group.ids)) }]));
564
+ function projectSuites(config) {
565
+ return Object.fromEntries(Object.values(config.suites).map((suite) => [suite.name, {
566
+ ...suite.description != null ? { description: suite.description } : {},
567
+ members: orderByDependency(config.processes, new Set(suite.ids)),
568
+ parallel: suite.parallel,
569
+ failFast: suite.failFast
570
+ }]));
442
571
  }
443
572
  function createControlPlane(options) {
444
573
  const { supervisor, log } = options;
@@ -460,7 +589,9 @@ function createControlPlane(options) {
460
589
  configRevisionHash: supervisor.config.configRevisionHash,
461
590
  configError: [],
462
591
  processes: Object.fromEntries(supervisor.status().map((status) => [status.id, projectProcess(status)])),
463
- groups: projectGroups(supervisor.config)
592
+ suites: projectSuites(supervisor.config),
593
+ runs: {},
594
+ savedFilters: [...options.savedFilters]
464
595
  });
465
596
  const engine = createRealmServerEngine(commanderStatusRealm, { initialState: initialState() });
466
597
  supervisor.subscribe((id) => {
@@ -470,6 +601,22 @@ function createControlPlane(options) {
470
601
  draft.processes[id] = projectProcess(status);
471
602
  });
472
603
  });
604
+ const suiteRunner = createSuiteRunner({
605
+ supervisor,
606
+ log,
607
+ publish: (runKey, run) => {
608
+ engine.update((draft) => {
609
+ if (run == null) delete draft.runs[runKey];
610
+ else draft.runs[runKey] = run;
611
+ });
612
+ }
613
+ });
614
+ const changeSavedFilters = async (change) => {
615
+ const next = await options.changeSavedFilters(change);
616
+ engine.update((draft) => {
617
+ draft.savedFilters = next;
618
+ });
619
+ };
473
620
  const liveSockets = /* @__PURE__ */ new Set();
474
621
  const acceptorAccess = {};
475
622
  const server = serveChannel(runtime, commanderChannel, {
@@ -500,8 +647,33 @@ function createControlPlane(options) {
500
647
  const ordered = orderByDependency(config.processes, withDependencies(config.processes, ids));
501
648
  return supervisor.restart(ordered, {
502
649
  wait: wait ?? true,
503
- staggerMs: staggerMs ?? 0
650
+ staggerMs: staggerMs ?? 0,
651
+ stopIds: ids
652
+ });
653
+ },
654
+ runSuite: async (input) => {
655
+ const report = suiteRunner.run(input);
656
+ if (report.accepted && input.filter != null) await changeSavedFilters({
657
+ kind: "ran",
658
+ query: input.filter,
659
+ at: Date.now()
504
660
  });
661
+ return report;
662
+ },
663
+ saveFilter: async ({ filter, name }) => {
664
+ await changeSavedFilters({
665
+ kind: "pin",
666
+ query: filter,
667
+ name
668
+ });
669
+ return { ok: true };
670
+ },
671
+ removeFilter: async ({ id }) => {
672
+ await changeSavedFilters({
673
+ kind: "remove",
674
+ id
675
+ });
676
+ return { ok: true };
505
677
  },
506
678
  setEnv: async (input) => ({
507
679
  ok: true,
@@ -562,7 +734,7 @@ function createControlPlane(options) {
562
734
  draft.configName = next.name;
563
735
  draft.configRevisionHash = next.configRevisionHash;
564
736
  draft.configError = [];
565
- draft.groups = projectGroups(next);
737
+ draft.suites = projectSuites(next);
566
738
  for (const status of supervisor.status()) draft.processes[status.id] = projectProcess(status);
567
739
  });
568
740
  },
@@ -1363,6 +1535,7 @@ var CommanderSupervisor = class {
1363
1535
  break;
1364
1536
  }
1365
1537
  if (dep.definition.kind === "task") {
1538
+ if (options.satisfied?.has(depId) === true) continue;
1366
1539
  const taskResult = await (taskRuns.get(depId) ?? this._runTaskOnce(dep, taskRuns));
1367
1540
  if (!orderedIds.includes(depId)) results.push({
1368
1541
  ...taskResult,
@@ -1647,8 +1820,13 @@ var CommanderSupervisor = class {
1647
1820
  warnings
1648
1821
  };
1649
1822
  }
1823
+ /**
1824
+ * ⚠ Stops only `stopIds` — the ids the caller NAMED — then starts the whole ordered closure.
1825
+ * Stopping the closure bounced every shared dependency under its other live dependents: a
1826
+ * restart of three frontends took the backend down with it.
1827
+ */
1650
1828
  async restart(orderedIds, options = {}) {
1651
- const stopped = await this.stop(orderedIds);
1829
+ const stopped = await this.stop(options.stopIds ?? orderedIds);
1652
1830
  const started = await this.start(orderedIds, options);
1653
1831
  return {
1654
1832
  results: started.results.map((result) => {
@@ -1734,6 +1912,7 @@ var CommanderSupervisor = class {
1734
1912
  unreadyReason: proc?.unreadyReason ?? null,
1735
1913
  capability: proc?.capability ?? null,
1736
1914
  tags: holder.definition.tags,
1915
+ optIn: holder.definition.optIn,
1737
1916
  detail: describe(holder.definition, envVars)
1738
1917
  };
1739
1918
  });
@@ -1913,11 +2092,24 @@ async function startCommanderDaemon(argv) {
1913
2092
  envWrites = run.catch(() => {});
1914
2093
  return run;
1915
2094
  };
2095
+ let savedFilters = await readSavedFilters(paths.savedFiltersPath);
2096
+ let filterWrites = Promise.resolve();
2097
+ const changeSavedFilters = (change) => {
2098
+ const run = filterWrites.then(async () => {
2099
+ savedFilters = mutateSavedFilters(savedFilters, change);
2100
+ await writeSavedFilters(paths.savedFiltersPath, savedFilters);
2101
+ return savedFilters;
2102
+ });
2103
+ filterWrites = run.catch(() => {});
2104
+ return run;
2105
+ };
1916
2106
  const plane = createControlPlane({
1917
2107
  supervisor,
1918
2108
  generation,
1919
2109
  reloadConfig: () => watcher?.reloadNow() ?? Promise.resolve(),
1920
2110
  setEnvOverrides,
2111
+ savedFilters,
2112
+ changeSavedFilters,
1921
2113
  requestShutdown: () => void shutdown(),
1922
2114
  log
1923
2115
  });
@@ -2068,7 +2260,7 @@ async function startCommanderDaemon(argv) {
2068
2260
  configKey: resolved.configKey,
2069
2261
  configRevisionHash: resolved.configRevisionHash,
2070
2262
  configPath: resolved.configPath,
2071
- protocolVersion: 5,
2263
+ protocolVersion: 6,
2072
2264
  packageVersion: await commanderPackageVersion(),
2073
2265
  realmSchemaHash: commanderStatusRealm.schemaHash
2074
2266
  });
@@ -2153,4 +2345,4 @@ async function runCommanderDaemon(argv) {
2153
2345
  //#endregion
2154
2346
  export { runCommanderDaemon };
2155
2347
 
2156
- //# sourceMappingURL=main-BlAdEbVt.mjs.map
2348
+ //# sourceMappingURL=main-DrNJc_xN.mjs.map