@turri-dev/cli 0.3.0 → 0.3.1-next.f3b1920

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 { type ExportedCode, type LaunchedProcess, type LaunchRecord } from "./regenerate/launch.ts";
1
+ import { type ExportedCode, type Freed, type LaunchedProcess, type LaunchRecord } from "./regenerate/launch.ts";
2
2
  /**
3
3
  * The launch track (docs/launch.md): each codebase's launches, one at a time, the newest commit winning. A pulse that lands
4
4
  * under `launch-after-pulse` asks for one with the commit it landed, and so does the chat's launch tool with the codebase's
@@ -7,6 +7,12 @@ import { type ExportedCode, type LaunchedProcess, type LaunchRecord } from "./re
7
7
  *
8
8
  * What is launched is recorded - the codebase, the commit, what it started, whether it came up - and the sentinel tests a
9
9
  * pulse only in a launch whose commit holds the pulse's (`holds`).
10
+ *
11
+ * Across a project: a launch replaces what launches of the modules below it in its requires chain started - their code
12
+ * is in it - and waits for one of them under way to end first. What turri's own launches of any other module started is
13
+ * left running, unless it holds what this launch needs - a port, which activate takes, or anything else, which the agent
14
+ * frees with stop_launched (`freed`). Either way, the launch that started it is replaced (`replacedBy`), told to the
15
+ * host, and the new launch's `stopped` says what was stopped.
10
16
  */
11
17
  export type LaunchStatus = "waiting" | "running" | "launched" | "failed" | "stopped" | "superseded";
12
18
  /** Why a launch was asked for: a pulse landed, under launch-after-pulse - or a chat, or `turri launch`, asked. */
@@ -36,8 +42,14 @@ export interface Launch {
36
42
  queuedAt: number;
37
43
  startedAt?: number;
38
44
  finishedAt?: number;
39
- /** What the agent said it did - where it runs - or why it did not come up. */
45
+ /**
46
+ * What the agent said it did - where it runs - or why it did not come up; for one that never reached the agent, turri's
47
+ * own line (stopped on request, out already, an error). What turri stopped for it is in `stopped`, never here:
48
+ * `launchText` puts the two together as the person reads them.
49
+ */
40
50
  summary?: string;
51
+ /** What turri stopped for this launch, a process each, as it stopped them - before it started, or as it ran. */
52
+ stopped?: LaunchStopped[];
41
53
  /** Its code, once exported. */
42
54
  code?: ExportedCode;
43
55
  /** When what runs for it was started: a launch that found its code out already keeps the one before it's. */
@@ -47,13 +59,35 @@ export interface Launch {
47
59
  /** Superseded while it waited: the launch that took its place. */
48
60
  supersededBy?: string;
49
61
  /**
50
- * It ended with a newer launch of its codebase waiting, which starts at once and stops what it started: the launch
51
- * that takes its place. Its own status stays what it was - launched, say - for as long as that runs.
62
+ * A newer launch stops what it started, and takes its place: one of its codebase, or of a module built on it, waiting as
63
+ * it ended - which starts at once - or one that needed what it held. Its own status stays what it was - launched, say.
52
64
  */
53
65
  replacedBy?: string;
54
66
  /** Asked for even were its code out already. */
55
67
  again?: true;
56
68
  }
69
+ /**
70
+ * A process turri stopped for a launch, and why: a launch of a module below it in its requires chain (`below`) - its code
71
+ * is in this one; a server of another module's launch that held what this one needs (`held`, with what: "port 5173");
72
+ * one an earlier turri session left running (`left-behind`), stopped before this launch of its codebase.
73
+ */
74
+ export interface LaunchStopped {
75
+ why: "below" | "held" | "left-behind";
76
+ /** The module whose launch started it. */
77
+ module: string;
78
+ /** The launch of this session that started it - none for an earlier session's. */
79
+ launch?: string;
80
+ /** That launch's commit, short, when known. */
81
+ commit?: string;
82
+ /** Its name, as the launch agent started it with activate. */
83
+ name: string;
84
+ pid: number;
85
+ url?: string;
86
+ /** What it held that this launch needs - "port 5173", "the lock on data/app.db" - for `held`. */
87
+ held?: string;
88
+ /** For `held`: an earlier turri session, ended, started it - not this one. */
89
+ earlier?: true;
90
+ }
57
91
  export interface LaunchOutcome {
58
92
  launched: boolean;
59
93
  summary: string;
@@ -82,9 +116,16 @@ export interface LaunchTrack {
82
116
  };
83
117
  /** The codebase's last launch that ended - launched or failed - what runs being its. */
84
118
  current(codebase: string): Launch | undefined;
119
+ /**
120
+ * The launch whose code holds the codebase's now: its own last that ended, or - replaced by a launch of a module built
121
+ * on it - that module's, up the chain.
122
+ */
123
+ runs(codebase: string): Launch | undefined;
124
+ /** The codebases whose launches this one replaces: its own, and the modules below it in its requires chain. */
125
+ replacing(launch: Launch): string[];
85
126
  /** A launch of the codebase running, or waiting. */
86
127
  pending(codebase: string): Launch | undefined;
87
- /** Resolves once nothing of the codebase's is running or waiting. */
128
+ /** Resolves once nothing of the codebase's is running or waiting - nor of a module built on it, that took its launches over. */
88
129
  settled(codebase: string): Promise<void>;
89
130
  /**
90
131
  * Resolves with the launch once it ends - or, superseded as it waited or replaced as it ended, with the one that took
@@ -96,7 +137,7 @@ export interface LaunchTrack {
96
137
  * which stops what it started - as soon as it does. Never resolves for a launch nothing takes the place of.
97
138
  */
98
139
  replaced(id: string): Promise<Launch>;
99
- /** Whether what runs for the codebase holds `commit`: its last launch's commit is it, or one built on it. */
140
+ /** Whether what runs for the codebase (`runs`) holds `commit`: its commit is it, or one built on it - up the chain too. */
100
141
  holds(codebase: string, commit: string): boolean;
101
142
  /** Stop the codebase's launch under way and the one waiting - every codebase's, none named. Returns what was stopped. */
102
143
  stop(codebase?: string): Promise<string[]>;
@@ -117,9 +158,18 @@ export interface LaunchTrack {
117
158
  }
118
159
  export declare function createLaunchTrack(options: {
119
160
  cwd: string;
120
- /** The agent that takes exported code on and starts it. */
121
- run: (launch: Launch, code: ExportedCode, signal: AbortSignal) => Promise<LaunchOutcome>;
161
+ /**
162
+ * The agent that takes exported code on and starts it - telling `freed` what of turri's own launches it stopped to take
163
+ * what they held.
164
+ */
165
+ run: (launch: Launch, code: ExportedCode, signal: AbortSignal, freed: (freed: Freed[]) => void) => Promise<LaunchOutcome>;
122
166
  onChange?: (launch: Launch) => void;
123
167
  }): LaunchTrack;
168
+ /**
169
+ * A launch as the person reads it: what turri stopped for it - what an earlier session left running, then what launches
170
+ * of the modules below it started, then what held what it needed - a line each, then what the launch agent said. The
171
+ * chat, the terminal and the sentinel read this; a host gets the two apart, `stopped` and `summary`.
172
+ */
173
+ export declare function launchText(launch: Pick<Launch, "codebase" | "summary" | "stopped">): string;
124
174
  /** A launch in a line: its codebase, commit, how it stands - for /halt, pulses and the panel. */
125
175
  export declare function describeLaunchLine(launch: Launch): string;
@@ -1,5 +1,5 @@
1
1
  import { dirname, join } from "node:path";
2
- import { codeTreeOf, describeLeftBehind, exportModule, holdsCommit, hostDirOf, launchTarget, listLaunched, runningLaunched, stopLaunched, stopLeftBehind } from "./regenerate/launch.js";
2
+ import { codeTreeOf, describeFreed, describeLeftBehind, exportModule, holdsAcross, holdsCommit, hostDirOf, launchTarget, listLaunched, runningLaunched, stopLaunched, stopLaunchedProcesses, stopLeftBehind, } from "./regenerate/launch.js";
3
3
  import { projectDirOf } from "./regenerate/paths.js";
4
4
  import { record } from "./regenerate/ledger.js";
5
5
  /** How many ended launches are kept to list. */
@@ -13,7 +13,7 @@ export function createLaunchTrack(options) {
13
13
  const stateOf = (codebase, moduleDir) => {
14
14
  let state = codebases.get(codebase);
15
15
  if (state === undefined) {
16
- state = { moduleDir, settledWaiters: [] };
16
+ state = { moduleDir, below: [], settledWaiters: [] };
17
17
  codebases.set(codebase, state);
18
18
  }
19
19
  state.moduleDir = moduleDir;
@@ -35,6 +35,72 @@ export function createLaunchTrack(options) {
35
35
  };
36
36
  const finished = (launch) => record({ kind: "launch.finished", launch: launch.id, commit: launch.short, status: launch.status, ms: (launch.finishedAt ?? Date.now()) - (launch.startedAt ?? launch.queuedAt) }, place(launch));
37
37
  const place = (launch) => ({ project: options.cwd, module: launch.codebase });
38
+ /** The module on top a launch was asked for, with nothing built yet - it took the one below - by launch. */
39
+ const insteadOf = new Map();
40
+ /** What turri stopped for a launch, kept on it as it happens - and the host told. */
41
+ const stoppedFor = (launch, stopped) => {
42
+ if (stopped.length === 0)
43
+ return;
44
+ launch.stopped = [...(launch.stopped ?? []), ...stopped];
45
+ changed(launch);
46
+ };
47
+ /**
48
+ * What a launch of another module started was stopped for `by`: once nothing of it runs, its launch is replaced - not
49
+ * what runs any more - and told to the host. Whoever asked for it heard its end already: the new launch's `stopped` says it.
50
+ */
51
+ const replacedAcross = (codebase, by) => {
52
+ const state = codebases.get(codebase);
53
+ const current = state?.current;
54
+ if (state === undefined || current === undefined || current === by || runningLaunched(codebase).length > 0)
55
+ return;
56
+ state.current = undefined;
57
+ if (current.replacedBy !== undefined)
58
+ return;
59
+ current.replacedBy = by.id;
60
+ record({ kind: "launch.replaced", launch: current.id, by: by.id, byModule: by.codebase }, place(current));
61
+ changed(current);
62
+ };
63
+ /** What `launch` stopped of turri's own launches to take what they held: kept in its `stopped`, their launches replaced. */
64
+ const freedFor = (launch) => (freed) => {
65
+ if (freed.length === 0)
66
+ return;
67
+ record({ kind: "launch.freed", launch: launch.id, held: freed[0].held, stopped: freed.map(ledgerOf) }, place(launch));
68
+ stoppedFor(launch, freed.map((each) => ({
69
+ why: "held",
70
+ module: each.moduleName,
71
+ name: each.name,
72
+ pid: each.pid,
73
+ held: each.held,
74
+ ...(each.launch !== undefined ? { launch: each.launch } : {}),
75
+ ...(each.commit !== undefined ? { commit: each.commit } : {}),
76
+ ...(each.url !== undefined ? { url: each.url } : {}),
77
+ ...(each.earlier === true ? { earlier: true } : {}),
78
+ })));
79
+ for (const each of freed)
80
+ if (each.earlier !== true && each.moduleName !== launch.codebase)
81
+ replacedAcross(each.moduleName, launch);
82
+ };
83
+ const ledgerOf = (each) => ({
84
+ name: each.name,
85
+ pid: each.pid,
86
+ module: each.moduleName,
87
+ ...(each.url !== undefined ? { url: each.url } : {}),
88
+ ...(each.launch !== undefined ? { launch: each.launch } : {}),
89
+ });
90
+ /** Whether a launch of a module below `state`'s in its chain is under way: it waits for that one to end. */
91
+ const belowBusy = (state) => state.below.some((module) => codebases.get(module)?.running !== undefined);
92
+ /** A launch waiting, of a module built on `codebase`: it stops what `codebase`'s launch started as it starts. */
93
+ const aboveWaiting = (codebase) => [...codebases.values()].find((state) => state.waiting !== undefined && state.below.includes(codebase))?.waiting;
94
+ /** The launches of modules built on `codebase` that waited for its launch to end, and can start now. */
95
+ const startAbove = (codebase) => {
96
+ for (const state of codebases.values()) {
97
+ if (state.waiting === undefined || state.running !== undefined || !state.below.includes(codebase) || belowBusy(state))
98
+ continue;
99
+ const next = state.waiting;
100
+ state.waiting = undefined;
101
+ start(state, next);
102
+ }
103
+ };
38
104
  /** What an earlier session left running and was stopped, by codebase, not yet said in a launch's summary. */
39
105
  const leftBehind = new Map();
40
106
  const noteLeftBehind = (stopped) => {
@@ -99,6 +165,10 @@ export function createLaunchTrack(options) {
99
165
  outAlready(state, launch, out);
100
166
  return;
101
167
  }
168
+ // What runs of the modules below it is this one's from now: their code is in it.
169
+ state.movedTo = undefined;
170
+ for (const module of state.below)
171
+ stateOf(module, join(dirname(state.moduleDir), module)).movedTo = launch.codebase;
102
172
  const abort = new AbortController();
103
173
  state.running = { launch, abort };
104
174
  launch.status = "running";
@@ -113,16 +183,34 @@ export function createLaunchTrack(options) {
113
183
  halted.catch(() => undefined);
114
184
  try {
115
185
  // What the last launch started runs from what is about to be replaced - and what an earlier session's left, which
116
- // would hold its ports.
117
- noteLeftBehind(await stopLeftBehind(projectDirOf(launch.plainFile), launch.codebase));
186
+ // would hold its ports. So does what launches of the modules below it started: an older build of the same code.
187
+ noteLeftBehind(await stopLeftBehind(projectDirOf(launch.plainFile), [launch.codebase, ...state.below]));
188
+ // What an earlier session left of these codebases - stopped now, or as the session started - is this launch's to say.
189
+ stoppedFor(launch, [launch.codebase, ...state.below].flatMap((module) => {
190
+ const records = leftBehind.get(module) ?? [];
191
+ leftBehind.delete(module);
192
+ return records.map((record) => ({
193
+ why: "left-behind",
194
+ module: record.moduleName,
195
+ name: record.name,
196
+ pid: record.pid,
197
+ ...(record.commit !== undefined ? { commit: record.commit } : {}),
198
+ ...(record.url !== undefined ? { url: record.url } : {}),
199
+ }));
200
+ }));
118
201
  await stopLaunched({ moduleName: launch.codebase });
119
- const code = exportModule(launch.plainFile, { ...(launch.inModule !== undefined ? { inModule: launch.inModule } : {}), commit: launch.commit });
202
+ const older = state.below.length > 0 ? await stopLaunchedProcesses({ modules: state.below }) : [];
203
+ replacedBelow(launch, older);
204
+ // The codebase it was asked for, whatever has been built on it since.
205
+ const exported = exportModule(launch.plainFile, { inModule: launch.codebase, commit: launch.commit });
206
+ const instead = insteadOf.get(launch.id);
207
+ const code = instead !== undefined ? { ...exported, instead } : exported;
120
208
  launch.code = code;
121
209
  launch.serversSince = Date.now();
122
210
  changed(launch);
123
211
  if (abort.signal.aborted)
124
212
  throw new Error("stopped");
125
- const outcome = await Promise.race([options.run(launch, code, abort.signal), halted]);
213
+ const outcome = await Promise.race([options.run(launch, code, abort.signal, freedFor(launch)), halted]);
126
214
  if (abort.signal.aborted)
127
215
  throw new Error("stopped");
128
216
  launch.status = outcome.launched ? "launched" : "failed";
@@ -132,11 +220,6 @@ export function createLaunchTrack(options) {
132
220
  launch.status = abort.signal.aborted ? "stopped" : "failed";
133
221
  launch.summary = abort.signal.aborted ? "Stopped on request." : error instanceof Error ? error.message : String(error);
134
222
  }
135
- const left = leftBehind.get(launch.codebase);
136
- if (left !== undefined) {
137
- leftBehind.delete(launch.codebase);
138
- launch.summary = `${describeLeftBehind(left)}\n${launch.summary ?? ""}`.trim();
139
- }
140
223
  launch.finishedAt = Date.now();
141
224
  // What runs is this launch's - or, stopped, nothing of it.
142
225
  state.current = launch.status === "stopped" ? undefined : launch;
@@ -152,25 +235,47 @@ export function createLaunchTrack(options) {
152
235
  state.running = undefined;
153
236
  const next = state.waiting;
154
237
  state.waiting = undefined;
155
- const replaces = next !== undefined && launch.status !== "stopped" && (next.again === true || isOut(state, next.commit) === undefined);
156
- if (replaces)
157
- launch.replacedBy = next.id;
238
+ // A launch of a module built on this one, waiting for it to end, stops what it started as it starts.
239
+ const above = next === undefined && launch.status !== "stopped" ? aboveWaiting(launch.codebase) : undefined;
240
+ const by = next !== undefined && launch.status !== "stopped" && (next.again === true || isOut(state, next.commit) === undefined) ? next : above;
241
+ if (by !== undefined)
242
+ launch.replacedBy = by.id;
158
243
  finished(launch);
159
244
  changed(launch);
160
- if (replaces)
161
- handOn(launch, next);
245
+ if (by !== undefined)
246
+ handOn(launch, by);
162
247
  else
163
248
  ended(launch);
164
249
  if (next !== undefined)
165
250
  start(state, next);
166
251
  else
167
252
  settle(state);
253
+ startAbove(launch.codebase);
254
+ };
255
+ /** What `launch` stopped of the launches of the modules below it: kept in its `stopped`, and theirs replaced. */
256
+ const replacedBelow = (launch, stopped) => {
257
+ if (stopped.length > 0)
258
+ record({ kind: "launch.freed", launch: launch.id, held: "below", stopped: stopped.map(ledgerOf) }, place(launch));
259
+ stoppedFor(launch, stopped.map((item) => ({
260
+ why: "below",
261
+ module: item.moduleName,
262
+ name: item.name,
263
+ pid: item.pid,
264
+ ...(item.launch !== undefined ? { launch: item.launch } : {}),
265
+ ...(item.commit !== undefined ? { commit: item.commit } : {}),
266
+ ...(item.url !== undefined ? { url: item.url } : {}),
267
+ })));
268
+ // Theirs - with something stopped or nothing left running - is not what runs any more: this one holds their code.
269
+ for (const module of codebases.get(launch.codebase)?.below ?? [])
270
+ replacedAcross(module, launch);
168
271
  };
169
272
  const track = {
170
273
  request(input) {
171
274
  const target = launchTarget(input.plainFile, { ...(input.inModule !== undefined ? { inModule: input.inModule } : {}), ...(input.commit !== undefined ? { commit: input.commit } : {}) });
172
275
  const codebase = target.entry.moduleName;
173
276
  const state = stateOf(codebase, dirname(target.entry.buildDir));
277
+ state.below = target.below;
278
+ const instead = target.instead;
174
279
  const said = input.guidance?.trim();
175
280
  if (said !== undefined && said !== "")
176
281
  state.guidance = said;
@@ -193,12 +298,28 @@ export function createLaunchTrack(options) {
193
298
  let resolve;
194
299
  const promise = new Promise((done) => (resolve = done));
195
300
  ends.set(launch.id, { promise, resolve });
301
+ if (instead !== undefined)
302
+ insteadOf.set(launch.id, instead);
196
303
  let resolveTaken;
197
304
  const taken = new Promise((done) => (resolveTaken = done));
198
305
  takenOver.set(launch.id, { promise: taken, resolve: resolveTaken });
306
+ // A launch of a module below it waiting is never launched: this one holds its code.
307
+ for (const module of state.below) {
308
+ const below = codebases.get(module);
309
+ const older = below?.waiting;
310
+ if (below === undefined || older === undefined)
311
+ continue;
312
+ below.waiting = undefined;
313
+ older.status = "superseded";
314
+ older.supersededBy = launch.id;
315
+ older.finishedAt = Date.now();
316
+ changed(older);
317
+ handOn(older, launch);
318
+ settle(below);
319
+ }
199
320
  // Nothing under way, and its code out already: nothing to do - but it ends as any launch does, told to the host
200
321
  // (onChange) with its own cause and the commit asked for, and what runs is its own when that commit is newer.
201
- if (input.again !== true && state.running === undefined && state.waiting === undefined) {
322
+ if (input.again !== true && state.running === undefined && state.waiting === undefined && !belowBusy(state)) {
202
323
  const out = isOut(state, launch.commit);
203
324
  if (out !== undefined) {
204
325
  keep(launch);
@@ -207,7 +328,8 @@ export function createLaunchTrack(options) {
207
328
  }
208
329
  }
209
330
  keep(launch);
210
- if (state.running === undefined)
331
+ // A launch of a module below it under way ends first: this one stops what it started.
332
+ if (state.running === undefined && !belowBusy(state))
211
333
  start(state, launch);
212
334
  else {
213
335
  // The newest wins: what waited is never launched - this one holds its code.
@@ -225,15 +347,35 @@ export function createLaunchTrack(options) {
225
347
  return { launch, already: false };
226
348
  },
227
349
  current: (codebase) => codebases.get(codebase)?.current,
350
+ runs(codebase) {
351
+ const seen = new Set();
352
+ let name = codebase;
353
+ while (name !== undefined && !seen.has(name)) {
354
+ seen.add(name);
355
+ const state = codebases.get(name);
356
+ if (state?.current !== undefined)
357
+ return state.current;
358
+ name = state?.movedTo;
359
+ }
360
+ return undefined;
361
+ },
362
+ replacing: (launch) => [launch.codebase, ...(codebases.get(launch.codebase)?.below ?? [])],
228
363
  pending(codebase) {
229
364
  const state = codebases.get(codebase);
230
365
  return state?.running?.launch ?? state?.waiting;
231
366
  },
232
- settled(codebase) {
233
- const state = codebases.get(codebase);
234
- if (state === undefined || (state.running === undefined && state.waiting === undefined))
235
- return Promise.resolve();
236
- return new Promise((resolve) => state.settledWaiters.push(resolve));
367
+ async settled(codebase) {
368
+ const seen = new Set();
369
+ let name = codebase;
370
+ while (name !== undefined && !seen.has(name)) {
371
+ seen.add(name);
372
+ const state = codebases.get(name);
373
+ if (state === undefined)
374
+ return;
375
+ if (state.running !== undefined || state.waiting !== undefined)
376
+ await new Promise((resolve) => state.settledWaiters.push(resolve));
377
+ name = state.movedTo;
378
+ }
237
379
  },
238
380
  done(id) {
239
381
  const end = ends.get(id);
@@ -247,11 +389,10 @@ export function createLaunchTrack(options) {
247
389
  return taken !== undefined ? taken.promise : Promise.reject(new Error(`No launch ${id}.`));
248
390
  },
249
391
  holds(codebase, commit) {
250
- const state = codebases.get(codebase);
251
- const current = state?.current;
252
- if (state === undefined || current === undefined)
392
+ const runs = track.runs(codebase);
393
+ if (runs === undefined)
253
394
  return false;
254
- return holdsCommit(state.moduleDir, commit, current.commit);
395
+ return holdsAcross({ codebase, commit }, { codebase: runs.codebase, moduleDir: runs.moduleDir, commit: runs.commit });
255
396
  },
256
397
  async stop(codebase) {
257
398
  const stopped = [];
@@ -304,6 +445,42 @@ export function createLaunchTrack(options) {
304
445
  };
305
446
  return track;
306
447
  }
448
+ /**
449
+ * A launch as the person reads it: what turri stopped for it - what an earlier session left running, then what launches
450
+ * of the modules below it started, then what held what it needed - a line each, then what the launch agent said. The
451
+ * chat, the terminal and the sentinel read this; a host gets the two apart, `stopped` and `summary`.
452
+ */
453
+ export function launchText(launch) {
454
+ const stopped = launch.stopped ?? [];
455
+ const left = stopped.filter((each) => each.why === "left-behind");
456
+ const lines = [];
457
+ if (left.length > 0)
458
+ lines.push(describeLeftBehind(left.map((each) => ({ name: each.name, pid: each.pid, moduleName: each.module, ...(each.url !== undefined ? { url: each.url } : {}) }))));
459
+ const below = new Map();
460
+ for (const each of stopped.filter((item) => item.why === "below")) {
461
+ const key = `${each.module}\u0000${each.launch ?? ""}`;
462
+ below.set(key, [...(below.get(key) ?? []), each]);
463
+ }
464
+ for (const items of below.values()) {
465
+ const first = items[0];
466
+ const which = first.launch !== undefined ? `${first.module}'s launch ${first.launch}${first.commit !== undefined ? ` at ${first.commit}` : ""}` : `${first.module}'s launch`;
467
+ const what = items.map((item) => `${item.name} (pid ${item.pid}${item.url !== undefined ? `, ${item.url}` : ""})`).join(", ");
468
+ lines.push(`Stopped what ${which} started - ${what}: ${launch.codebase} is built on ${first.module} and holds its code, so this launch takes its place.`);
469
+ }
470
+ for (const each of stopped.filter((item) => item.why === "held")) {
471
+ lines.push(describeFreed({
472
+ name: each.name,
473
+ moduleName: each.module,
474
+ pid: each.pid,
475
+ held: each.held ?? "what this launch needs",
476
+ ...(each.url !== undefined ? { url: each.url } : {}),
477
+ ...(each.launch !== undefined ? { launch: each.launch } : {}),
478
+ ...(each.commit !== undefined ? { commit: each.commit } : {}),
479
+ ...(each.earlier === true ? { earlier: true } : {}),
480
+ }, launch.codebase));
481
+ }
482
+ return [...lines, ...(launch.summary !== undefined && launch.summary.trim() !== "" ? [launch.summary.trim()] : [])].join("\n");
483
+ }
307
484
  /** A launch in a line: its codebase, commit, how it stands - for /halt, pulses and the panel. */
308
485
  export function describeLaunchLine(launch) {
309
486
  const why = "pulse" in launch.cause ? ` after pulse ${launch.cause.pulse}` : "";
@@ -39,6 +39,32 @@ export interface ExportedCode {
39
39
  export declare function codeTreeOf(moduleDir: string, commit: string): string | undefined;
40
40
  /** Whether `commit` holds `ancestor`: the same commit, or one built on it. */
41
41
  export declare function holdsCommit(moduleDir: string, ancestor: string, commit: string): boolean;
42
+ /**
43
+ * Where a codebase's history started: the module below it whose code it started from, and that module's commit - what
44
+ * its first commit says (`start from <module> at <commit>`, copyRequiredCode). None for a codebase that started from
45
+ * nothing.
46
+ */
47
+ export declare function startedFrom(moduleDir: string): {
48
+ module: string;
49
+ commit: string;
50
+ } | undefined;
51
+ /**
52
+ * Whether a codebase's code holds a commit of another module - one below it in its requires chain, whose code it started
53
+ * from: the commit is that module's, or held by the one it started from - down the chain, as far as it goes.
54
+ */
55
+ export declare function heldUpChain(moduleDir: string, module: string, commit: string): boolean;
56
+ /**
57
+ * Whether `to` - a codebase at a commit - holds `from`'s commit: the same codebase, the commit or one built on it; a
58
+ * codebase above `from`'s in its requires chain, built from code that held it.
59
+ */
60
+ export declare function holdsAcross(from: {
61
+ codebase: string;
62
+ commit: string;
63
+ }, to: {
64
+ codebase: string;
65
+ moduleDir: string;
66
+ commit: string;
67
+ }): boolean;
42
68
  /**
43
69
  * Which codebase to launch for a spec, and at which commit: the tip of its codebase - code accumulates up a requires
44
70
  * chain, so the top module holds everything below it - at `commit`, or its last. Before the tip has anything committed,
@@ -51,6 +77,7 @@ export declare function launchTarget(plainFile: string, options?: {
51
77
  entry: ChainEntry;
52
78
  commit: string;
53
79
  instead?: string;
80
+ below: string[];
54
81
  };
55
82
  /**
56
83
  * Export a codebase's code at a commit - its last, unless `commit` names one - into `dist/<module>`, or `into`
@@ -82,6 +109,9 @@ export interface LaunchedProcess {
82
109
  log: string;
83
110
  pid: number;
84
111
  startedAt: number;
112
+ /** The launch that started it, and that launch's commit, short: whose it is, as the person is told. */
113
+ launch?: string;
114
+ commit?: string;
85
115
  /** Set once it has ended. */
86
116
  exited?: {
87
117
  code: number | null;
@@ -102,6 +132,9 @@ export interface LaunchRecord {
102
132
  dir: string;
103
133
  url?: string;
104
134
  startedAt: number;
135
+ /** The launch that started it, and that launch's commit, short. */
136
+ launch?: string;
137
+ commit?: string;
105
138
  /** The turri process that started it. */
106
139
  turri: number;
107
140
  }
@@ -111,9 +144,9 @@ export interface LaunchRecord {
111
144
  * (another turri still running keeps its own), and only when the process is still the one recorded: a process turri did
112
145
  * not start is never stopped. Records of what has ended are taken out. Returns what was stopped.
113
146
  */
114
- export declare function stopLeftBehind(projectDir: string, codebase?: string): Promise<LaunchRecord[]>;
147
+ export declare function stopLeftBehind(projectDir: string, codebase?: string | string[]): Promise<LaunchRecord[]>;
115
148
  /** What was stopped of an earlier session's, in a line - for a launch's summary. */
116
- export declare function describeLeftBehind(stopped: LaunchRecord[]): string;
149
+ export declare function describeLeftBehind(stopped: Array<Pick<LaunchRecord, "name" | "pid" | "url" | "moduleName">>): string;
117
150
  /** Everything a launch started, running or ended, oldest first. */
118
151
  export declare function listLaunched(): LaunchedProcess[];
119
152
  /** The ones still running. */
@@ -122,15 +155,77 @@ export declare function runningLaunched(moduleName?: string): LaunchedProcess[];
122
155
  export declare function launchLogDir(projectDir: string): string;
123
156
  /** The end of a log, for when something did not come up. */
124
157
  export declare function logTail(log: string, lines?: number, chars?: number): string;
125
- /** Stop one launched process, or every one of a module, or every one: politely, then not. Returns the names stopped. */
126
- export declare function stopLaunched(which?: {
158
+ /** Which of this turri's launched processes: by name, by module (or modules), by process group. Each given must match. */
159
+ export interface LaunchedFilter {
127
160
  name?: string;
128
161
  moduleName?: string;
129
- }): Promise<string[]>;
162
+ modules?: string[];
163
+ pid?: number;
164
+ }
165
+ /** Stop launched processes - those the filter names, or every one: politely, then not. Returns what was stopped. */
166
+ export declare function stopLaunchedProcesses(which?: LaunchedFilter): Promise<LaunchedProcess[]>;
167
+ /** Stop one launched process, or every one of a module, or every one: politely, then not. Returns the names stopped. */
168
+ export declare function stopLaunched(which?: LaunchedFilter): Promise<string[]>;
169
+ /**
170
+ * A process, as turri's records say it: started by this turri's launches; by an earlier turri's, which has ended - left
171
+ * behind; by another turri still running, which keeps it; or by nothing turri's records of the project name.
172
+ */
173
+ export type Holder = {
174
+ kind: "this";
175
+ pid: number;
176
+ process: LaunchedProcess;
177
+ } | {
178
+ kind: "left";
179
+ pid: number;
180
+ record: LaunchRecord;
181
+ file: string;
182
+ } | {
183
+ kind: "turri";
184
+ pid: number;
185
+ record: LaunchRecord;
186
+ } | {
187
+ kind: "unknown";
188
+ pid: number;
189
+ command: string;
190
+ };
191
+ /** What a launch of this turri stopped to take what it held, said where the launch's summary says it. */
192
+ export interface Freed {
193
+ name: string;
194
+ moduleName: string;
195
+ pid: number;
196
+ url?: string;
197
+ launch?: string;
198
+ commit?: string;
199
+ /** An earlier turri, ended, started it - not this one. */
200
+ earlier?: true;
201
+ /** What it held that this launch needs, as it is said: "port 5173". */
202
+ held: string;
203
+ }
204
+ /**
205
+ * Whose a process is - any process of the group a launch started: what this turri started, what turri's records of the
206
+ * project (`logDir`, its `.turri/launch`) name, or neither. Only a record whose group is still the one it names counts:
207
+ * a pid given to another process since is not turri's.
208
+ */
209
+ export declare function whoHolds(pid: number, logDir: string): Holder;
210
+ /** The processes listening on a TCP port, as lsof says them - undefined when it cannot say (no lsof). */
211
+ export declare function listenersOf(port: number): number[] | undefined;
212
+ /** A holder in a line: what it is, and whose - the launch and module a turri started it for. */
213
+ export declare function describeHolder(holder: Holder): string;
214
+ /** How the person frees what a holder holds, from the chat - or that turri frees it itself. */
215
+ export declare function howToFree(holder: Holder): string;
216
+ /** Whether turri frees what a holder holds for a launch itself: what its own launches started, this session's or a dead turri's. */
217
+ export declare const turriFrees: (holder: Holder) => holder is Extract<Holder, {
218
+ kind: "this" | "left";
219
+ }>;
220
+ /**
221
+ * Stop what turri's own launches started - this session's, or an ended turri's - for a launch that needs what it holds
222
+ * (`held`, "port 5173"). Returns what was stopped; the rest is never touched.
223
+ */
224
+ export declare function freeHeld(holders: Holder[], held: string): Promise<Freed[]>;
225
+ /** What was freed for a launch, in a line - for its summary. */
226
+ export declare function describeFreed(freed: Freed, forName: string): string;
130
227
  /** Stop everything at once, without waiting: for when turri itself is going. */
131
228
  export declare function stopAllLaunchedNow(): void;
132
- /** What holds a port, as lsof says it - or nothing when it cannot say. */
133
- export declare function holderOf(port: number): string;
134
229
  /** How long a server is given to answer at its URL, and to stay up when it has none. */
135
230
  export declare const READY_TIMEOUT_MS: number;
136
231
  export interface StartResult {
@@ -151,4 +246,11 @@ export declare function startLaunched(input: {
151
246
  logDir: string;
152
247
  url?: string;
153
248
  root?: string;
249
+ /** The launch it is started for, and its commit, short: recorded, to say whose it is. */
250
+ launch?: {
251
+ id: string;
252
+ commit: string;
253
+ };
254
+ /** What turri's own launches started and this one stopped, to take what it held - told to the launch track. */
255
+ freed?: (freed: Freed[]) => void;
154
256
  }): Promise<StartResult>;