@turri-dev/cli 0.3.1-next.9b12558 → 0.4.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.
package/dist/chats.d.ts CHANGED
@@ -307,8 +307,10 @@ export interface SentinelLaunches {
307
307
  readyFor(job: Job): Promise<void>;
308
308
  /** Resolves once what runs of the check's module is settled. Throws when nothing of it runs. */
309
309
  readyForCheck(check: SentinelCheck): Promise<void>;
310
- /** Resolves once nothing of the codebase's is launching or waiting to. */
310
+ /** Resolves once nothing of the codebase's is launching or waiting to - nor of a module built on it that took its launches over. */
311
311
  settled(codebase: string): Promise<void>;
312
+ /** The codebases whose launches a launch replaces - what they started stopped: its own, and the modules below it. Default: its own. */
313
+ replacing?(launch: Launch): string[];
312
314
  }
313
315
  /** A chat's session, as stopping what it does reaches it. */
314
316
  export type Stoppable = Pick<AgentSession, "isStreaming" | "isCompacting" | "isRetrying" | "isBashRunning" | "abort" | "abortBash">;
package/dist/chats.js CHANGED
@@ -401,9 +401,13 @@ export function createChats(options) {
401
401
  },
402
402
  launchChanged(launch) {
403
403
  if (launch.status === "running") {
404
- pauseFor(launch);
404
+ pauseFor(launch, options.launches?.replacing?.(launch) ?? [launch.codebase]);
405
405
  return;
406
406
  }
407
+ // Replaced - what it started stopped by a newer launch, of its codebase or another module's that needed what it held:
408
+ // a check in it waits for the launches to settle, then carries on where its code runs - or is told nothing of it runs.
409
+ if (launch.replacedBy !== undefined && launch.status === "launched")
410
+ pauseFor(launch, [launch.codebase]);
407
411
  // One after a pulse, ended, with the sentinel off: its chat is told - the sentinel, on, tests it with the pulse. One a
408
412
  // newer launch replaced as it ended is not: what it started is stopped the next moment, and the newer one is told.
409
413
  if (!("pulse" in launch.cause) || (launch.status !== "launched" && launch.status !== "failed") || launch.replacedBy !== undefined || core.sentinelOn())
@@ -858,21 +862,23 @@ export function createChats(options) {
858
862
  changed();
859
863
  }
860
864
  /**
861
- * A launch of a codebase started while the sentinel checks a pulse or a check of it: its turn stopped - its conversation
862
- * kept - until the codebase's launches are settled, then carried on in the launch that holds it.
865
+ * A launch started that replaces what runs of a codebase the sentinel checks a pulse or a check of - its own, or one
866
+ * below it in its chain - or what a launch started was stopped for another's: its turn stopped - its conversation kept
867
+ * - until the codebase's launches are settled, then carried on in the launch that holds it.
863
868
  */
864
- function pauseFor(launch) {
869
+ function pauseFor(launch, codebases) {
865
870
  const sentinel = sentinelChat();
866
871
  const now = checking;
872
+ const codebase = now !== undefined ? codebaseOf(now.work) : undefined;
867
873
  // Concluded, it is only saying so: nothing to carry on.
868
- if (sentinel === undefined || now === undefined || now.concluded === true || paused !== undefined || codebaseOf(now.work) !== launch.codebase)
874
+ if (sentinel === undefined || now === undefined || now.concluded === true || paused !== undefined || codebase === undefined || !codebases.includes(codebase))
869
875
  return;
870
876
  paused = now;
871
877
  inChat(sentinel.scope, () => record({ kind: "sentinel.paused", module: launch.codebase, launch: launch.id }, { project: cwd, ...("pulse" in now.work ? { job: now.work.pulse.id } : {}) }));
872
878
  void sentinel.session?.abort().catch(() => undefined);
873
879
  changed();
874
880
  void (async () => {
875
- await options.launches?.settled(launch.codebase);
881
+ await options.launches?.settled(codebase);
876
882
  // Let go meanwhile - closed, or given another conversation: nothing to carry on.
877
883
  if (paused !== now || !chats.includes(sentinel) || sentinel.instance === undefined) {
878
884
  if (paused === now)
package/dist/extension.js CHANGED
@@ -29,7 +29,7 @@ import { skillStatus } from "./skill.js";
29
29
  import { runningLaunched, stopLaunched } from "./regenerate/launch.js";
30
30
  import { launchTool } from "./launch-tools.js";
31
31
  import { createSessionLaunches, launchedDir, launchedNote, replacedNote } from "./launch-session.js";
32
- import { describeLaunchLine } from "./launch-track.js";
32
+ import { describeLaunchLine, launchText } from "./launch-track.js";
33
33
  import { checkedSpecs } from "./sentinel-check.js";
34
34
  import { createSteeringStore, EVERY_MODULE, moduleNameOf, queueSectionOf, steeringFor } from "./regenerate/steer.js";
35
35
  import { askedForCommandLine, refusal, selfInvocation, TOOLS_NOT_CLI } from "./self-invocation.js";
@@ -511,7 +511,7 @@ function turriExtension(api, session, link) {
511
511
  specs: checkedSpecs(check),
512
512
  running: runningLaunched(check.module),
513
513
  ...(commit !== undefined ? { commit } : {}),
514
- ...(current?.status === "failed" ? { failed: { id: current.id, ...(current.summary !== undefined ? { summary: current.summary } : {}) } } : {}),
514
+ ...(current?.status === "failed" ? { failed: { id: current.id, ...(launchText(current) !== "" ? { summary: launchText(current) } : {}) } } : {}),
515
515
  ...(current !== undefined ? { dir: launchedDir(current) } : {}),
516
516
  ...(context.focused !== undefined ? { focused: context.focused } : {}),
517
517
  });
package/dist/host.d.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  */
7
7
  export { createTurri, type Turri, type TurriOptions } from "./host-session.ts";
8
8
  export { MAX_CHATS, type ChatInfo, type ChatStatus, type TurriHost } from "./chats.ts";
9
- export type { Launch, LaunchCause, LaunchStatus } from "./launch-track.ts";
9
+ export { launchText, type Launch, type LaunchCause, type LaunchStatus, type LaunchStopped } from "./launch-track.ts";
10
10
  export type { ConfigLine, ConfigLineKind } from "./config.ts";
11
11
  export { SENTINEL, SENTINEL_START, type Conclusion, type Notice, type NoticeAction, type NoticeAnswer, type NoticeSeverity, type NoticeState, type SentinelCheck } from "./notice.ts";
12
12
  export type { CheckRequest } from "./sentinel-check.ts";
package/dist/host.js CHANGED
@@ -7,6 +7,7 @@
7
7
  // The session and its chats.
8
8
  export { createTurri } from "./host-session.js";
9
9
  export { MAX_CHATS } from "./chats.js";
10
+ export { launchText } from "./launch-track.js";
10
11
  // The sentinel's notices: what it puts to the person, and how they answer - and the checks a host asks of it.
11
12
  export { SENTINEL, SENTINEL_START } from "./notice.js";
12
13
  /** pi itself, as turri is built against it: a host's own extensions and UI are made with this one, not another copy. */
@@ -1,5 +1,5 @@
1
1
  import { type ToolDefinition } from "@earendil-works/pi-coding-agent";
2
- import { type ExportedCode } from "./regenerate/launch.ts";
2
+ import { type ExportedCode, type Freed } from "./regenerate/launch.ts";
3
3
  import type { Launch, LaunchOutcome } from "./launch-track.ts";
4
4
  /**
5
5
  * The launch agent: every launch's - the chat's launch tool, a pulse that landed under `launch-after-pulse`, and
@@ -18,17 +18,26 @@ export declare function launchShell(dir: string): AnyTool;
18
18
  * (`.agents/skills`, `.pi/skills`, `.claude/skills`), where turri runs and in the host codebase - once each, whole.
19
19
  */
20
20
  export declare function projectNotes(dirs: string[]): string[];
21
+ /** The launch an agent works for, as its tools need it: its id and commit say whose what it starts is. */
22
+ type ForLaunch = Pick<Launch, "codebase" | "plainFile" | "hostDir"> & Partial<Pick<Launch, "id" | "short">>;
21
23
  /**
22
24
  * activate: start what keeps running - a backend, a frontend's dev server - owned by the harness: in its own process
23
- * group, its output kept, stopped on the codebase's next launch, on /halt and when turri exits.
25
+ * group, its output kept, stopped on the codebase's next launch, on /halt and when turri exits. A port held by what
26
+ * turri's own launches started is taken - what held it stopped, and `freed` told.
24
27
  */
25
- export declare function activateTool(launch: Pick<Launch, "codebase" | "plainFile" | "hostDir">, code: Pick<ExportedCode, "dir">): AnyTool;
28
+ export declare function activateTool(launch: ForLaunch, code: Pick<ExportedCode, "dir">, freed?: (freed: Freed[]) => void): AnyTool;
29
+ /**
30
+ * stop_launched: free what a server turri's own launches started holds that this launch needs - a socket, a lock or pid
31
+ * file, a container name, a port - by any process of it. Stopped only when turri's records say a launch of turri started
32
+ * it - this session's for another module, or a turri that has ended; anything else is refused, saying whose it is.
33
+ */
34
+ export declare function stopLaunchedTool(launch: ForLaunch, freed?: (freed: Freed[]) => void): AnyTool;
26
35
  /**
27
36
  * Why a launch said to be up is not: it says something serves - `serves`, or a URL in its summary - and nothing this
28
37
  * launch started with activate still runs. Something else answering there - an earlier build left running, another
29
38
  * program - is not this launch. Undefined when it holds.
30
39
  */
31
- export declare function notBacked(launch: Pick<Launch, "codebase" | "serversSince">, outcome: {
40
+ export declare function notBacked(launch: Pick<Launch, "codebase" | "serversSince" | "plainFile">, outcome: {
32
41
  launched: boolean;
33
42
  summary: string;
34
43
  serves?: boolean;
@@ -45,6 +54,8 @@ export interface LaunchAgentInput {
45
54
  model?: string;
46
55
  signal?: AbortSignal;
47
56
  onDelta?: (delta: string) => void;
57
+ /** What turri's own launches started and this one stopped, to take what it held: told to the launch track. */
58
+ freed?: (freed: Freed[]) => void;
48
59
  }
49
60
  /** Run the launch agent to its end: how it went, as it submitted it - or, never submitted, its last words as a failure. */
50
61
  export declare function runLaunchAgent(input: LaunchAgentInput): Promise<LaunchOutcome>;
@@ -2,7 +2,7 @@ import { existsSync, readdirSync, readFileSync } from "node:fs";
2
2
  import { isAbsolute, join, relative, resolve, sep } from "node:path";
3
3
  import { createBashToolDefinition, createEditToolDefinition, createFindToolDefinition, createGrepToolDefinition, createLsToolDefinition, createReadToolDefinition, createWriteToolDefinition, defineTool, } from "@earendil-works/pi-coding-agent";
4
4
  import { Type } from "typebox";
5
- import { describeExport, holderOf, launchLogDir, runningLaunched, shortPath, startLaunched } from "./regenerate/launch.js";
5
+ import { describeExport, describeFreed, describeHolder, freeHeld, howToFree, launchLogDir, listenersOf, runningLaunched, shortPath, startLaunched, turriFrees, whoHolds, } from "./regenerate/launch.js";
6
6
  import { machineChange, machineChangeReason } from "./regenerate/command-check.js";
7
7
  import { projectDirOf } from "./regenerate/paths.js";
8
8
  import { ask, BEGIN, createExecutor } from "./pi.js";
@@ -79,17 +79,21 @@ function inside(root, dir) {
79
79
  throw new Error(`${dir} is outside ${shortPath(root)}: what activate starts runs from there, or a folder inside it.`);
80
80
  return target;
81
81
  }
82
+ const launchOf = (launch) => (launch.id !== undefined && launch.short !== undefined ? { launch: { id: launch.id, commit: launch.short } } : {});
82
83
  /**
83
84
  * activate: start what keeps running - a backend, a frontend's dev server - owned by the harness: in its own process
84
- * group, its output kept, stopped on the codebase's next launch, on /halt and when turri exits.
85
+ * group, its output kept, stopped on the codebase's next launch, on /halt and when turri exits. A port held by what
86
+ * turri's own launches started is taken - what held it stopped, and `freed` told.
85
87
  */
86
- export function activateTool(launch, code) {
88
+ export function activateTool(launch, code, freed) {
87
89
  return defineTool({
88
90
  name: "activate",
89
91
  label: "Activate",
90
92
  description: "Start something that keeps running - a backend, a frontend's dev server - on this machine: in the background, its " +
91
93
  "output kept, stopped on the next launch, on /halt and when turri exits. With `url`, waits until something answers " +
92
- "there and says so, or shows the end of its output. A port something else holds is said, and nothing is started.",
94
+ "there and says so, or shows the end of its output. A port held by a server turri's own launches started - another " +
95
+ "module's, an earlier session's - is taken: turri stops that server and says so. A port anything else holds is said - " +
96
+ "what holds it, whose it is, how to free it - and nothing is started.",
93
97
  promptSnippet: "start a server of the launched code, and wait for it to answer",
94
98
  parameters: Type.Object({
95
99
  name: Type.String({ description: "A short name for it: backend, frontend, app" }),
@@ -110,11 +114,61 @@ export function activateTool(launch, code) {
110
114
  moduleName: launch.codebase,
111
115
  logDir: launchLogDir(projectDirOf(launch.plainFile)),
112
116
  ...(params.url !== undefined ? { url: params.url } : {}),
117
+ ...launchOf(launch),
118
+ ...(freed !== undefined ? { freed } : {}),
113
119
  });
114
120
  return text(started.text, { ok: started.ok, ...(started.process !== undefined ? { pid: started.process.pid, log: started.process.log } : {}) });
115
121
  },
116
122
  });
117
123
  }
124
+ /**
125
+ * stop_launched: free what a server turri's own launches started holds that this launch needs - a socket, a lock or pid
126
+ * file, a container name, a port - by any process of it. Stopped only when turri's records say a launch of turri started
127
+ * it - this session's for another module, or a turri that has ended; anything else is refused, saying whose it is.
128
+ */
129
+ export function stopLaunchedTool(launch, freed) {
130
+ return defineTool({
131
+ name: "stop_launched",
132
+ label: "Stop launched",
133
+ description: "Stop a server an earlier launch of turri's started - another module's, an earlier session's - that holds something " +
134
+ "this launch needs: a socket, a lock or pid file, a container name, a database it keeps open. Give any pid of it - " +
135
+ "from the error, lsof, ps - and what it holds. turri stops it only when its records say a launch of turri's " +
136
+ "started it, and says so in the launch's summary itself; a process turri did not start, or another turri's still " +
137
+ "running, is never stopped: you are told whose it is and how the person frees it. A port activate takes itself.",
138
+ promptSnippet: "stop an earlier launch's server that holds what this launch needs",
139
+ parameters: Type.Object({
140
+ pid: Type.Integer({ description: "A process of the server that holds it" }),
141
+ holds: Type.String({ description: "What it holds that this launch needs, in a few words: the socket /tmp/app.sock, the lock on data/app.db" }),
142
+ }),
143
+ async execute(_id, params) {
144
+ const holder = whoHolds(params.pid, launchLogDir(projectDirOf(launch.plainFile)));
145
+ if (holder.kind === "this" && holder.process.launch !== undefined && holder.process.launch === launch.id) {
146
+ throw new Error(`Not stopped: ${describeHolder(holder)} - this launch started it itself. activate it again under the same name to restart it.`);
147
+ }
148
+ if (!turriFrees(holder))
149
+ throw new Error(`Not stopped: ${describeHolder(holder)}. ${howToFree(holder)} Say so in submit_launch.`);
150
+ const stopped = await freeHeld([holder], params.holds.trim() || "what this launch needs");
151
+ freed?.(stopped);
152
+ if (stopped.length === 0)
153
+ return text(`Nothing stopped: ${describeHolder(holder)} has ended already.`);
154
+ return text(`${stopped.map((each) => describeFreed(each, launch.codebase)).join("\n")}\nturri says so in the launch's summary: start what needs it now.`);
155
+ },
156
+ });
157
+ }
158
+ /** What holds each port a summary names, said with whose it is - none for a port nothing listens on. */
159
+ function heldPorts(ports, logDir) {
160
+ const lines = [];
161
+ for (const port of ports) {
162
+ const pids = listenersOf(port);
163
+ if (pids === undefined || pids.length === 0)
164
+ continue;
165
+ for (const pid of pids) {
166
+ const holder = whoHolds(pid, logDir);
167
+ lines.push(`port ${port}: ${describeHolder(holder)}. ${howToFree(holder)}`);
168
+ }
169
+ }
170
+ return lines;
171
+ }
118
172
  /** The ports of the URLs a summary names. */
119
173
  function portsIn(summary) {
120
174
  const ports = new Set();
@@ -143,10 +197,10 @@ export function notBacked(launch, outcome) {
143
197
  const since = launch.serversSince ?? 0;
144
198
  if (runningLaunched(launch.codebase).some((item) => item.startedAt >= since))
145
199
  return undefined;
146
- const holders = ports.map((port) => ({ port, holder: holderOf(port) })).filter((each) => each.holder !== "");
200
+ const held = heldPorts(ports, launchLogDir(projectDirOf(launch.plainFile)));
147
201
  return [
148
- `nothing this launch started with activate is running, so what answers${ports.length > 0 ? ` at port ${ports.join(", ")}` : ""} is not this launch's code${holders.length > 0 ? " - it is held by something else:" : "."}`,
149
- ...holders.map((each) => `port ${each.port}:\n${each.holder}`),
202
+ `nothing this launch started with activate is running, so what answers${ports.length > 0 ? ` at port ${ports.join(", ")}` : ""} is not this launch's code${held.length > 0 ? " - it is held by:" : "."}`,
203
+ ...held,
150
204
  ].join("\n");
151
205
  }
152
206
  /** submit_launch: how the launch went, once, last - the harness reads its arguments, never the agent's prose. */
@@ -167,7 +221,7 @@ function submitLaunchTool(launch, submitted) {
167
221
  async execute(_id, params) {
168
222
  const why = notBacked(launch, params);
169
223
  if (why !== undefined) {
170
- throw new Error(`Not taken: you say it runs, but ${why}\nStart it with activate - stopping nothing turri did not start - or call submit_launch with launched false, saying what holds the port.`);
224
+ throw new Error(`Not taken: you say it runs, but ${why}\nStart it with activate - stopping nothing turri did not start - or call submit_launch with launched false, saying what holds the port and whose it is, as said here.`);
171
225
  }
172
226
  submitted.outcome = { launched: params.launched, summary: params.summary, serves: params.serves };
173
227
  return text("Taken. You are done: end your turn.");
@@ -196,15 +250,31 @@ export function launchGuide(code, hostDir) {
196
250
  "3. Run the project's scripts and install what it needs into the project yourself, in your shell. A toolchain or system tool the machine lacks you never install, nor change a setting of the machine's: say the command the person runs themselves.",
197
251
  "4. Start what keeps running - a start script, a dev server - with activate (from: host when it runs in the host codebase), with the URL it serves at - never in the shell with & or nohup.",
198
252
  "",
199
- `Either way, never change ${built} or ${dist}: they are what was built, and a fix belongs in the ***plain. A config file it needs made from its example (a .env from .env.example) is fine. A port that is taken: say which and by what, and do not move the app to another.`,
253
+ `Either way, never change ${built} or ${dist}: they are what was built, and a fix belongs in the ***plain. A config file it needs made from its example (a .env from .env.example) is fine.`,
254
+ "",
255
+ "Something it needs held already: a port, activate takes itself when a server turri's own launches started holds it, and",
256
+ "says so. Anything else - a socket, a lock or pid file, a container name - held by a server one of turri's launches",
257
+ "started (listed below, when any runs): free it with stop_launched. This launch is the newest: it always takes what",
258
+ "turri's own earlier launches hold - never leave it unstarted to keep one of theirs running, whatever the reason, even",
259
+ "to compare the two; turri tells the person what it stopped. Never decide from lsof yourself: call activate, and it says",
260
+ "what holds the port and whose it is. What turri did not start, or another turri still",
261
+ "running started, is never stopped and the app is never moved to another port: say what holds it, whose it is and how",
262
+ "the person frees it, as the tools said it - never that turri did not start something its tools say it did.",
200
263
  "",
201
264
  "Last, call submit_launch once: launched, whether it serves, and in a line or three where to open it - the frontend's URL,",
202
265
  "and the API's in one line when there is one - or, a CLI or a library, a few commands to paste, run from its folder, with",
203
266
  "what they print; or why it did not come up. Where the guidance does not fit what you find, say so, and do not guess past it.",
204
- "Something answering at the app's port that you did not start with activate - an earlier build left running, another",
205
- "program - is not this launch: it is not launched, and you say what holds the port. Never stop a process you did not start.",
267
+ "Something answering at the app's port that this launch did not start with activate is not this launch: it is not",
268
+ "launched, and you say what holds the port and whose it is. Stop a process only with activate or stop_launched, never in",
269
+ "your shell.",
206
270
  ].join("\n");
207
271
  }
272
+ /** What turri's launches of other modules run now, a line each with its pid - what stop_launched frees. */
273
+ function otherLaunches(codebase) {
274
+ return runningLaunched()
275
+ .filter((item) => item.moduleName !== codebase)
276
+ .map((item) => `- ${item.name}: pid ${item.pid}, ${item.moduleName}'s launch${item.launch !== undefined ? ` ${item.launch}` : ""}${item.commit !== undefined ? ` at ${item.commit}` : ""} - ${item.url ?? item.command}, in ${shortPath(item.dir)}`);
277
+ }
208
278
  /** Run the launch agent to its end: how it went, as it submitted it - or, never submitted, its last words as a failure. */
209
279
  export async function runLaunchAgent(input) {
210
280
  const { launch, code } = input;
@@ -220,7 +290,8 @@ export async function runLaunchAgent(input) {
220
290
  outsideBuiltCode(createWriteToolDefinition(dir), dir),
221
291
  ];
222
292
  const submitted = {};
223
- const tools = [activateTool(launch, code), submitLaunchTool(launch, submitted)];
293
+ const tools = [activateTool(launch, code, input.freed), stopLaunchedTool(launch, input.freed), submitLaunchTool(launch, submitted)];
294
+ const others = otherLaunches(launch.codebase);
224
295
  const executor = await createExecutor({
225
296
  // Its sessions are kept in the project, not in the folder it launches.
226
297
  cwd: projectDirOf(launch.plainFile),
@@ -242,6 +313,7 @@ export async function runLaunchAgent(input) {
242
313
  launchGuide(code, dir),
243
314
  ...(launch.inModule !== undefined ? ["", `It is the codebase of module ${launch.inModule}.`] : []),
244
315
  ...(launch.guidance !== undefined ? ["", "What the person said of how to launch it:", launch.guidance] : []),
316
+ ...(others.length > 0 ? ["", "What turri's launches of other modules run now - each its own module's, left running unless it holds what this launch needs:", ...others] : []),
245
317
  ...(notes.length > 0 ? ["", "The project's notes and skills:", ...notes] : []),
246
318
  ].join("\n"),
247
319
  });
@@ -2,7 +2,7 @@ import { closeSync, openSync, readSync, statSync } from "node:fs";
2
2
  import { refuseTestPlainFile } from "./test-plain-files.js";
3
3
  import { resolve } from "node:path";
4
4
  import { configForSpec, modelSpec, projectModels, readProjectConfig } from "./config.js";
5
- import { createLaunchTrack } from "./launch-track.js";
5
+ import { createLaunchTrack, launchText } from "./launch-track.js";
6
6
  import { runLaunchAgent } from "./launch-agent.js";
7
7
  import { listLaunched, runningLaunched, stopLaunched } from "./regenerate/launch.js";
8
8
  import { c } from "./module-report.js";
@@ -107,11 +107,12 @@ async function main() {
107
107
  let streamed = "";
108
108
  const track = createLaunchTrack({
109
109
  cwd: process.cwd(),
110
- run: (launch, code, signal) => runLaunchAgent({
110
+ run: (launch, code, signal, freed) => runLaunchAgent({
111
111
  launch,
112
112
  code,
113
113
  cwd: process.cwd(),
114
114
  signal,
115
+ freed,
115
116
  ...(model !== undefined ? { model } : {}),
116
117
  onDelta: (delta) => {
117
118
  streamed += delta;
@@ -126,8 +127,10 @@ async function main() {
126
127
  cause: {},
127
128
  });
128
129
  const ended = await track.done(launch.id);
129
- // What the agent said as it went is on the screen already: its summary only when it said nothing.
130
- const said = streamed.trim() === "" ? `\n${ended.summary ?? ""}` : "";
130
+ // What the agent said as it went is on the screen already: its summary only when it said nothing - what turri stopped
131
+ // for it, always.
132
+ const text = launchText(streamed.trim() === "" ? ended : { ...ended, summary: undefined });
133
+ const said = text !== "" ? `\n${text}` : "";
131
134
  console.log(`\n\n${ended.status === "launched" ? c.success(`Launched.${said}`) : c.error(`It did not come up.${said}`)}`);
132
135
  if (ended.status !== "launched")
133
136
  console.log(`\n${c.dim(PROBLEMS)}`);
@@ -1,7 +1,8 @@
1
+ import { dirname, join } from "node:path";
1
2
  import { configForSpec, readProjectConfig } from "./config.js";
2
- import { createLaunchTrack } from "./launch-track.js";
3
+ import { createLaunchTrack, launchText } from "./launch-track.js";
3
4
  import { runLaunchAgent } from "./launch-agent.js";
4
- import { holdsCommit, runningLaunched } from "./regenerate/launch.js";
5
+ import { holdsAcross, runningLaunched } from "./regenerate/launch.js";
5
6
  import { distDirFor, projectDirOf } from "./regenerate/paths.js";
6
7
  import { pulseName } from "./regenerate/jobs.js";
7
8
  /** How long a pulse that landed is waited for to say its commit: the loop says it as the pulse settles. */
@@ -11,9 +12,9 @@ export function createSessionLaunches(options) {
11
12
  const waiters = new Map();
12
13
  const track = createLaunchTrack({
13
14
  cwd: options.cwd,
14
- run: (launch, code, signal) => {
15
+ run: (launch, code, signal, freed) => {
15
16
  const model = options.model(launch.plainFile);
16
- return runLaunchAgent({ launch, code, cwd: options.cwd, signal, ...(model !== undefined ? { model } : {}) });
17
+ return runLaunchAgent({ launch, code, cwd: options.cwd, signal, freed, ...(model !== undefined ? { model } : {}) });
17
18
  },
18
19
  onChange: options.onChange,
19
20
  });
@@ -45,21 +46,25 @@ export function createSessionLaunches(options) {
45
46
  return landedPulses.get(job.id);
46
47
  };
47
48
  const short = (commit) => commit.slice(0, 7);
48
- /** The person stopped the codebase's last launch: nothing of it runs. */
49
- const stoppedLast = (codebase) => {
50
- const last = [...track.list()].reverse().find((launch) => launch.codebase === codebase && launch.status !== "superseded");
51
- return last?.status === "stopped";
52
- };
53
- /** Throws when what runs of the codebase does not hold the pulse's commit. */
49
+ /** The last launch that took the codebase's code on - its own, or one of a module built on it - none superseded. */
50
+ const lastFor = (codebase) => [...track.list()].reverse().find((launch) => launch.status !== "superseded" && track.replacing(launch).includes(codebase));
51
+ /** The person stopped the last launch of the codebase's code: nothing of it runs. */
52
+ const stoppedLast = (codebase) => lastFor(codebase)?.status === "stopped";
53
+ /** Throws when what runs of the codebase's code does not hold the pulse's commit. */
54
54
  const mustHold = (job, landing) => {
55
- const current = track.current(landing.codebase);
56
- if (current === undefined) {
55
+ const runs = track.runs(landing.codebase);
56
+ if (runs === undefined) {
57
+ const last = lastFor(landing.codebase);
58
+ const by = last?.replacedBy !== undefined ? track.list().find((launch) => launch.id === last.replacedBy) : undefined;
59
+ if (last !== undefined && by !== undefined && by.codebase !== last.codebase) {
60
+ throw new Error(`what ${last.codebase}'s launch ${last.id} started was stopped for ${by.codebase}'s launch ${by.id}, which needed what it held - nothing of ${landing.codebase} runs to test pulse ${job.id} in.`);
61
+ }
57
62
  throw new Error(`nothing of ${landing.codebase} runs - no launch holds pulse ${job.id}'s commit ${short(landing.commit)}, and none that would is waiting.`);
58
63
  }
59
64
  if (!track.holds(landing.codebase, landing.commit)) {
60
- throw new Error(`what runs of ${landing.codebase} is its commit ${current.short}, which does not hold pulse ${job.id}'s commit ${short(landing.commit)} - and no launch that would is waiting.`);
65
+ throw new Error(`what runs of ${landing.codebase} is ${runs.codebase === landing.codebase ? "its" : `${runs.codebase}'s`} commit ${runs.short}, which does not hold pulse ${job.id}'s commit ${short(landing.commit)} - and no launch that would is waiting.`);
61
66
  }
62
- return current;
67
+ return runs;
63
68
  };
64
69
  return {
65
70
  track,
@@ -94,34 +99,36 @@ export function createSessionLaunches(options) {
94
99
  },
95
100
  async readyForCheck(check) {
96
101
  await track.settled(check.module);
97
- if (track.current(check.module) === undefined && runningLaunched(check.module).length === 0) {
102
+ if (track.runs(check.module) === undefined && runningLaunched(check.module).length === 0) {
98
103
  throw new Error(`nothing of ${check.module} is launched to test it in - ask the chat to try it first, which launches it.`);
99
104
  }
100
105
  },
101
106
  settled: (codebase) => track.settled(codebase),
107
+ replacing: (launch) => track.replacing(launch),
102
108
  forPulse(job) {
103
109
  const landing = landedPulses.get(job.id);
104
110
  if (landing === undefined)
105
111
  return { later: [], laterSpecs: [], running: [], ...(landedJob(job) && !launchesAfter(job) ? { off: true } : {}) };
106
- const base = { commit: landing.commit, running: runningLaunched(landing.codebase), later: [], laterSpecs: [] };
112
+ const launch = track.runs(landing.codebase);
113
+ const base = { commit: landing.commit, running: runningLaunched(launch?.codebase ?? landing.codebase), later: [], laterSpecs: [] };
107
114
  if (landing.notAsked !== undefined)
108
115
  return { ...base, notAsked: landing.notAsked };
109
116
  if (landing.launch === undefined)
110
117
  return { ...base, off: true };
111
- const launch = track.current(landing.codebase);
112
118
  if (launch === undefined || !track.holds(landing.codebase, landing.commit))
113
119
  return { ...base, stopped: true };
114
- // The pulses that landed after it, which what runs holds too: what they changed is theirs to test.
120
+ // The pulses that landed after it, which what runs holds too - of its codebase, or of one built on it: what they
121
+ // changed is theirs to test.
122
+ const at = (codebase) => join(dirname(launch.moduleDir), codebase);
115
123
  const later = options.jobs
116
124
  .list()
117
125
  .filter((other) => {
118
126
  const theirs = landedPulses.get(other.id);
119
127
  return (other.id !== job.id &&
120
128
  theirs !== undefined &&
121
- theirs.codebase === landing.codebase &&
122
129
  theirs.commit !== landing.commit &&
123
- holdsCommit(launch.moduleDir, landing.commit, theirs.commit) &&
124
- holdsCommit(launch.moduleDir, theirs.commit, launch.commit));
130
+ holdsAcross({ codebase: landing.codebase, commit: landing.commit }, { codebase: theirs.codebase, moduleDir: at(theirs.codebase), commit: theirs.commit }) &&
131
+ holdsAcross({ codebase: theirs.codebase, commit: theirs.commit }, { codebase: launch.codebase, moduleDir: launch.moduleDir, commit: launch.commit }));
125
132
  })
126
133
  .sort((a, b) => a.sequence - b.sequence);
127
134
  const key = (spec) => `${spec.module}:${spec.funcId}`;
@@ -135,20 +142,21 @@ export function createSessionLaunches(options) {
135
142
  throw new Error(`turri has no commit for pulse ${work.job.id}.`);
136
143
  const launch = mustHold(work.job, landing);
137
144
  return [
138
- `What you were testing was launched again: ${launch.codebase} at ${launch.short} (${launch.id}${launch.status === "failed" ? ", which did not come up" : ""}). It still holds pulse ${work.job.id}'s commit, ${short(landing.commit)}.`,
139
- launch.status === "failed" ? `It did not come up: ${launch.summary ?? "the launch agent did not say why"}. That is what you find out about now.` : "What runs now:",
145
+ `What you were testing was launched again: ${launch.codebase} at ${launch.short} (${launch.id}${launch.status === "failed" ? ", which did not come up" : ""}). It still holds pulse ${work.job.id}'s commit, ${short(landing.commit)}${launch.codebase !== landing.codebase ? ` - built on ${landing.codebase}, it holds its code` : ""}.`,
146
+ launch.status === "failed" ? `It did not come up: ${launchText(launch) || "the launch agent did not say why"}. That is what you find out about now.` : "What runs now:",
140
147
  ...(launch.status === "failed" ? [] : whatRuns(runningLaunched(launch.codebase), launchedDir(launch))),
141
148
  "",
142
149
  LAUNCHED_ONLY,
143
150
  "Carry on the check where you were. Do again what you were doing as it restarted: what failed then may have failed for that alone.",
144
151
  ].join("\n");
145
152
  }
146
- const running = runningLaunched(work.check.module);
147
- if (track.current(work.check.module) === undefined && running.length === 0)
153
+ const runs = track.runs(work.check.module);
154
+ const running = runningLaunched(runs?.codebase ?? work.check.module);
155
+ if (runs === undefined && running.length === 0)
148
156
  throw new Error(`nothing of ${work.check.module} runs any more to test check ${work.check.id} in.`);
149
157
  return [
150
- `What you were testing was launched again: ${work.check.module}${track.current(work.check.module) !== undefined ? ` at ${track.current(work.check.module).short}` : ""}. What runs now:`,
151
- ...whatRuns(running, track.current(work.check.module) !== undefined ? launchedDir(track.current(work.check.module)) : undefined),
158
+ `What you were testing was launched again: ${runs !== undefined ? `${runs.codebase} at ${runs.short}${runs.codebase !== work.check.module ? `, built on ${work.check.module} and holding its code` : ""}` : work.check.module}. What runs now:`,
159
+ ...whatRuns(running, runs !== undefined ? launchedDir(runs) : undefined),
152
160
  "",
153
161
  LAUNCHED_ONLY,
154
162
  "Carry on the check where you were. Do again what you were doing as it restarted: what failed then may have failed for that alone.",
@@ -208,7 +216,7 @@ export function launchedNote(launch, job) {
208
216
  return [
209
217
  head,
210
218
  "",
211
- (launch.summary ?? "").trim(),
219
+ launchText(launch),
212
220
  "",
213
221
  launch.status === "launched"
214
222
  ? "Tell the person in a line or two where it runs - what the summary says to open or run - then do what you were told to do once something is launched (opening it where the person can watch it, saying what to test), if anything. Start no other work."
@@ -1,6 +1,6 @@
1
1
  import { type ExtensionContext } from "@earendil-works/pi-coding-agent";
2
2
  import { Type } from "typebox";
3
- import type { Launch, LaunchTrack } from "./launch-track.ts";
3
+ import { type Launch, type LaunchTrack } from "./launch-track.ts";
4
4
  /**
5
5
  * The chat's launch tool (docs/launch.md): it asks the launch track for a launch of a codebase's last commit and returns
6
6
  * at once - the launch agent works in the background, and the chat is told how it went once it ends. The harness does
@@ -2,6 +2,7 @@ import { resolve } from "node:path";
2
2
  import { defineTool } from "@earendil-works/pi-coding-agent";
3
3
  import { Type } from "typebox";
4
4
  import { refuseTestPlainFile } from "./test-plain-files.js";
5
+ import { launchText } from "./launch-track.js";
5
6
  /**
6
7
  * The chat's launch tool (docs/launch.md): it asks the launch track for a launch of a codebase's last commit and returns
7
8
  * at once - the launch agent works in the background, and the chat is told how it went once it ends. The harness does
@@ -17,7 +18,9 @@ export function launchTool(options) {
17
18
  "on this machine - or, with guidance, follows it from the host codebase: an integration a host application loads, " +
18
19
  "say, put in place with the host's scripts. Before you call it, ask yourself whether there is guidance for launching " +
19
20
  "this project - in what the person said, AGENTS.md, a skill - and pass it in full. It returns at once; you are told " +
20
- "where it runs, or why it did not come up, once it ends. When what is launched is that code already, it does nothing " +
21
+ "where it runs, or why it did not come up, once it ends. It replaces what launches of the modules below it started, " +
22
+ "and takes a port or anything else turri's launches of other modules hold that it needs - its summary says what it " +
23
+ "stopped; guidance never tells it to leave one of those running. When what is launched is that code already, it does nothing " +
21
24
  "and says so. Under launch-after-pulse turri launches what each pulse lands itself: never call it for that.",
22
25
  promptSnippet: "launch the regenerated code for the person to try, in the background - as the project's guidance says, or from dist/<module>",
23
26
  parameters: Type.Object({
@@ -43,7 +46,7 @@ export function launchTool(options) {
43
46
  const details = { launch: launch.id, module: launch.codebase, commit: launch.short, already };
44
47
  if (already) {
45
48
  return {
46
- content: [{ type: "text", text: `Out already: what runs of ${launch.codebase} is its code at ${launch.short} - nothing was done, and what runs is left running.${launch.summary !== undefined ? `\n${launch.summary}` : ""}\nSay so in a line.` }],
49
+ content: [{ type: "text", text: `Out already: what runs of ${launch.codebase} is its code at ${launch.short} - nothing was done, and what runs is left running.${launchText(launch) !== "" ? `\n${launchText(launch)}` : ""}\nSay so in a line.` }],
47
50
  details,
48
51
  };
49
52
  }
@@ -52,7 +55,7 @@ export function launchTool(options) {
52
55
  const ended = await options.track.done(launch.id);
53
56
  const where = ended.status === "launched" ? `${ended.codebase} at ${ended.short} is launched` : ended.status === "stopped" ? `The launch of ${ended.codebase} was stopped` : `The launch of ${ended.codebase} at ${ended.short} did not come up`;
54
57
  return {
55
- content: [{ type: "text", text: `${where} (${ended.id}).\n${(ended.summary ?? "").trim()}\nTell the person where it runs, or why it did not come up.` }],
58
+ content: [{ type: "text", text: `${where} (${ended.id}).\n${launchText(ended)}\nTell the person where it runs, or why it did not come up.` }],
56
59
  details: { ...details, status: ended.status },
57
60
  };
58
61
  }