@turri-dev/cli 0.2.4-next.bc1fc47 → 0.2.4-next.d779410

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.
Files changed (115) hide show
  1. package/README.md +5 -6
  2. package/dist/bedrock-region.js +3 -3
  3. package/dist/chat-models.d.ts +1 -1
  4. package/dist/chat-models.js +1 -1
  5. package/dist/chat-scope.d.ts +1 -3
  6. package/dist/chat-skills.d.ts +1 -1
  7. package/dist/chat-skills.js +1 -1
  8. package/dist/chats.d.ts +44 -10
  9. package/dist/chats.js +125 -41
  10. package/dist/cli.js +7 -24
  11. package/dist/config-edit.d.ts +20 -8
  12. package/dist/config-edit.js +32 -24
  13. package/dist/config.d.ts +90 -60
  14. package/dist/config.js +224 -117
  15. package/dist/conform-cli.js +1 -1
  16. package/dist/conformance-switch.d.ts +7 -6
  17. package/dist/conformance-switch.js +16 -16
  18. package/dist/extension.d.ts +10 -1
  19. package/dist/extension.js +263 -306
  20. package/dist/genome.js +1 -1
  21. package/dist/host-session.d.ts +8 -7
  22. package/dist/host-session.js +4 -4
  23. package/dist/host.d.ts +3 -1
  24. package/dist/host.js +3 -3
  25. package/dist/identity.js +2 -2
  26. package/dist/init-config.d.ts +1 -1
  27. package/dist/init-config.js +8 -8
  28. package/dist/launch-agent.d.ts +51 -0
  29. package/dist/launch-agent.js +267 -0
  30. package/dist/{release-cli.js → launch-cli.js} +41 -24
  31. package/dist/launch-session.d.ts +68 -0
  32. package/dist/launch-session.js +217 -0
  33. package/dist/launch-tools.d.ts +28 -0
  34. package/dist/launch-tools.js +69 -0
  35. package/dist/launch-track.d.ts +125 -0
  36. package/dist/launch-track.js +320 -0
  37. package/dist/loop-cli.js +4 -4
  38. package/dist/loop-tools.d.ts +17 -16
  39. package/dist/loop-tools.js +69 -69
  40. package/dist/notice.d.ts +7 -6
  41. package/dist/parse-cli.js +2 -2
  42. package/dist/pi-launch.js +3 -0
  43. package/dist/pi-settings.d.ts +4 -0
  44. package/dist/pi-settings.js +39 -0
  45. package/dist/pi.js +3 -3
  46. package/dist/plain/check.d.ts +1 -1
  47. package/dist/plain/check.js +3 -1
  48. package/dist/plain-files.d.ts +2 -2
  49. package/dist/plain-files.js +7 -7
  50. package/dist/regenerate/agent-env.d.ts +1 -1
  51. package/dist/regenerate/agent-env.js +3 -3
  52. package/dist/regenerate/agent-shell.js +2 -2
  53. package/dist/regenerate/base-folder.d.ts +2 -2
  54. package/dist/regenerate/base-folder.js +1 -1
  55. package/dist/regenerate/command-check.d.ts +7 -1
  56. package/dist/regenerate/command-check.js +43 -1
  57. package/dist/regenerate/delivery.d.ts +1 -1
  58. package/dist/regenerate/delivery.js +3 -3
  59. package/dist/regenerate/jobs.d.ts +2 -2
  60. package/dist/regenerate/jobs.js +10 -10
  61. package/dist/regenerate/launch.d.ts +154 -0
  62. package/dist/regenerate/{release.js → launch.js} +195 -51
  63. package/dist/regenerate/ledger.d.ts +33 -2
  64. package/dist/regenerate/lineage.d.ts +2 -0
  65. package/dist/regenerate/lineage.js +8 -0
  66. package/dist/regenerate/loop.d.ts +9 -8
  67. package/dist/regenerate/loop.js +43 -40
  68. package/dist/regenerate/model-names.d.ts +33 -0
  69. package/dist/regenerate/{engine.js → model-names.js} +2 -28
  70. package/dist/regenerate/paths.d.ts +3 -3
  71. package/dist/regenerate/paths.js +4 -4
  72. package/dist/regenerate/scripts-being-written.d.ts +4 -4
  73. package/dist/regenerate/scripts-being-written.js +3 -3
  74. package/dist/regenerate/test-scripts.d.ts +2 -1
  75. package/dist/regenerate/test-scripts.js +33 -23
  76. package/dist/regenerate/testing-steps.d.ts +6 -6
  77. package/dist/regenerate/testing-steps.js +8 -8
  78. package/dist/self-invocation.js +7 -7
  79. package/dist/sentinel-check.d.ts +3 -3
  80. package/dist/sentinel-check.js +3 -3
  81. package/dist/sentinel.d.ts +18 -12
  82. package/dist/sentinel.js +68 -42
  83. package/dist/{config-command.d.ts → settings.d.ts} +13 -8
  84. package/dist/{config-command.js → settings.js} +155 -24
  85. package/dist/setup.d.ts +2 -2
  86. package/dist/setup.js +7 -7
  87. package/docs/README.md +4 -4
  88. package/docs/chats.md +5 -6
  89. package/docs/claude-subscription.md +2 -2
  90. package/docs/config.md +58 -46
  91. package/docs/development.md +2 -2
  92. package/docs/headless.md +2 -3
  93. package/docs/hosting.md +20 -19
  94. package/docs/launch.md +67 -0
  95. package/docs/parser.md +2 -2
  96. package/docs/regenerating.md +12 -12
  97. package/docs/sandbox.md +3 -3
  98. package/docs/sentinel.md +26 -14
  99. package/docs/skills-and-gates.md +4 -5
  100. package/docs/using.md +15 -24
  101. package/genome/rules/project-model.md +2 -1
  102. package/genome/rules/turri-regeneration.md +3 -2
  103. package/genome/skills/implement-conformance-testing-script/SKILL.md +2 -2
  104. package/genome/skills/implement-unit-testing-script/SKILL.md +3 -3
  105. package/package.json +1 -1
  106. package/dist/regenerate/engine.d.ts +0 -52
  107. package/dist/regenerate/release.d.ts +0 -121
  108. package/dist/release-agent.d.ts +0 -43
  109. package/dist/release-agent.js +0 -130
  110. package/dist/release-tools.d.ts +0 -44
  111. package/dist/release-tools.js +0 -170
  112. package/dist/stacks.d.ts +0 -13
  113. package/dist/stacks.js +0 -96
  114. package/docs/deploy.md +0 -48
  115. /package/dist/{release-cli.d.ts → launch-cli.d.ts} +0 -0
@@ -0,0 +1,320 @@
1
+ import { dirname, join } from "node:path";
2
+ import { codeTreeOf, describeLeftBehind, exportModule, holdsCommit, hostDirOf, launchTarget, listLaunched, runningLaunched, stopLaunched, stopLeftBehind } from "./regenerate/launch.js";
3
+ import { projectDirOf } from "./regenerate/paths.js";
4
+ import { record } from "./regenerate/ledger.js";
5
+ /** How many ended launches are kept to list. */
6
+ const KEPT = 50;
7
+ export function createLaunchTrack(options) {
8
+ const codebases = new Map();
9
+ const launches = [];
10
+ const ends = new Map();
11
+ const takenOver = new Map();
12
+ let count = 0;
13
+ const stateOf = (codebase, moduleDir) => {
14
+ let state = codebases.get(codebase);
15
+ if (state === undefined) {
16
+ state = { moduleDir, settledWaiters: [] };
17
+ codebases.set(codebase, state);
18
+ }
19
+ state.moduleDir = moduleDir;
20
+ return state;
21
+ };
22
+ const changed = (launch) => {
23
+ try {
24
+ options.onChange?.(launch);
25
+ }
26
+ catch {
27
+ /* one that listens and fails is left out of this change */
28
+ }
29
+ };
30
+ const ended = (launch) => ends.get(launch.id)?.resolve(launch);
31
+ /** `next` takes `launch`'s place: whoever waits on `launch` hears `next`'s end, and that it took over, now. */
32
+ const handOn = (launch, next) => {
33
+ takenOver.get(launch.id)?.resolve(next);
34
+ void track.done(next.id).then((last) => ends.get(launch.id)?.resolve(last));
35
+ };
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
+ const place = (launch) => ({ project: options.cwd, module: launch.codebase });
38
+ /** What an earlier session left running and was stopped, by codebase, not yet said in a launch's summary. */
39
+ const leftBehind = new Map();
40
+ const noteLeftBehind = (stopped) => {
41
+ if (stopped.length === 0)
42
+ return;
43
+ record({ kind: "launch.left-behind", stopped: stopped.map((each) => ({ name: each.name, pid: each.pid, module: each.moduleName, ...(each.url !== undefined ? { url: each.url } : {}) })) }, { project: options.cwd });
44
+ for (const each of stopped)
45
+ leftBehind.set(each.moduleName, [...(leftBehind.get(each.moduleName) ?? []), each]);
46
+ };
47
+ /**
48
+ * What runs for the codebase is the commit's code: the same code, nothing it started has ended. Guidance is not
49
+ * compared: the agent finds the project's itself, and the chat passing it on says nothing new - `again` launches anew.
50
+ */
51
+ const isOut = (state, commit) => {
52
+ const current = state.current;
53
+ if (current === undefined || current.status !== "launched")
54
+ return undefined;
55
+ if (!holdsCommit(state.moduleDir, current.commit, commit) && !holdsCommit(state.moduleDir, commit, current.commit))
56
+ return undefined;
57
+ const tree = codeTreeOf(state.moduleDir, commit);
58
+ if (tree === undefined || tree !== codeTreeOf(state.moduleDir, current.commit))
59
+ return undefined;
60
+ const since = current.serversSince ?? current.startedAt ?? 0;
61
+ const started = listLaunched().filter((item) => item.moduleName === current.codebase && item.startedAt >= since);
62
+ return started.some((item) => item.exited !== undefined) ? undefined : current;
63
+ };
64
+ const settle = (state) => {
65
+ if (state.running !== undefined || state.waiting !== undefined)
66
+ return;
67
+ for (const resolve of state.settledWaiters.splice(0))
68
+ resolve();
69
+ };
70
+ const keep = (launch) => {
71
+ launches.push(launch);
72
+ while (launches.length > KEPT) {
73
+ const first = launches.findIndex((each) => each.status !== "waiting" && each.status !== "running");
74
+ if (first === -1)
75
+ break;
76
+ launches.splice(first, 1);
77
+ }
78
+ };
79
+ /**
80
+ * A launch whose commit's code is what runs already - a pulse that landed only tests, say, or the chat asking for what
81
+ * runs: ended as launched at once, `already`, nothing stopped or started - nor anyone told it is launching. What runs
82
+ * is its own from then on, when its commit is built on what ran: it holds both. Told as any launch's end is.
83
+ */
84
+ const outAlready = (state, launch, out) => {
85
+ launch.status = "launched";
86
+ launch.already = true;
87
+ launch.startedAt = Date.now();
88
+ launch.serversSince = out.serversSince ?? out.startedAt ?? 0;
89
+ launch.summary = out.summary ?? `${launch.codebase} at ${out.short} runs already.`;
90
+ launch.finishedAt = Date.now();
91
+ if (holdsCommit(state.moduleDir, out.commit, launch.commit))
92
+ state.current = launch;
93
+ finish(state, launch);
94
+ };
95
+ const start = (state, launch) => {
96
+ // Found out already as it waited.
97
+ const out = launch.again === true ? undefined : isOut(state, launch.commit);
98
+ if (out !== undefined) {
99
+ outAlready(state, launch, out);
100
+ return;
101
+ }
102
+ const abort = new AbortController();
103
+ state.running = { launch, abort };
104
+ launch.status = "running";
105
+ launch.startedAt = Date.now();
106
+ changed(launch);
107
+ record({ kind: "launch.started", launch: launch.id, commit: launch.short, ...("pulse" in launch.cause ? { pulse: launch.cause.pulse } : {}) }, place(launch));
108
+ void runIt(state, launch, abort);
109
+ };
110
+ const runIt = async (state, launch, abort) => {
111
+ // Halted, it is let go at once: what the agent does after is nobody's.
112
+ const halted = new Promise((_, reject) => abort.signal.addEventListener("abort", () => reject(new Error("stopped")), { once: true }));
113
+ halted.catch(() => undefined);
114
+ try {
115
+ // 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));
118
+ await stopLaunched({ moduleName: launch.codebase });
119
+ const code = exportModule(launch.plainFile, { ...(launch.inModule !== undefined ? { inModule: launch.inModule } : {}), commit: launch.commit });
120
+ launch.code = code;
121
+ launch.serversSince = Date.now();
122
+ changed(launch);
123
+ if (abort.signal.aborted)
124
+ throw new Error("stopped");
125
+ const outcome = await Promise.race([options.run(launch, code, abort.signal), halted]);
126
+ if (abort.signal.aborted)
127
+ throw new Error("stopped");
128
+ launch.status = outcome.launched ? "launched" : "failed";
129
+ launch.summary = outcome.summary.trim();
130
+ }
131
+ catch (error) {
132
+ launch.status = abort.signal.aborted ? "stopped" : "failed";
133
+ launch.summary = abort.signal.aborted ? "Stopped on request." : error instanceof Error ? error.message : String(error);
134
+ }
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
+ launch.finishedAt = Date.now();
141
+ // What runs is this launch's - or, stopped, nothing of it.
142
+ state.current = launch.status === "stopped" ? undefined : launch;
143
+ finish(state, launch);
144
+ };
145
+ /**
146
+ * A launch ended: the track free for the next - before anyone hears it ended - then it is told, and the next started.
147
+ * With a newer one waiting that will stop what it started - not out already - it is replaced: whoever asked for it
148
+ * hears the newer one's end instead, never that it is up only for it to be stopped the next moment.
149
+ */
150
+ const finish = (state, launch) => {
151
+ if (state.running?.launch === launch)
152
+ state.running = undefined;
153
+ const next = state.waiting;
154
+ 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;
158
+ finished(launch);
159
+ changed(launch);
160
+ if (replaces)
161
+ handOn(launch, next);
162
+ else
163
+ ended(launch);
164
+ if (next !== undefined)
165
+ start(state, next);
166
+ else
167
+ settle(state);
168
+ };
169
+ const track = {
170
+ request(input) {
171
+ const target = launchTarget(input.plainFile, { ...(input.inModule !== undefined ? { inModule: input.inModule } : {}), ...(input.commit !== undefined ? { commit: input.commit } : {}) });
172
+ const codebase = target.entry.moduleName;
173
+ const state = stateOf(codebase, dirname(target.entry.buildDir));
174
+ const said = input.guidance?.trim();
175
+ if (said !== undefined && said !== "")
176
+ state.guidance = said;
177
+ const guidance = state.guidance;
178
+ const launch = {
179
+ id: `launch-${++count}`,
180
+ codebase,
181
+ moduleDir: state.moduleDir,
182
+ plainFile: target.entry.plainFile,
183
+ ...(input.inModule !== undefined ? { inModule: input.inModule } : {}),
184
+ commit: target.commit,
185
+ short: target.commit.slice(0, 7),
186
+ hostDir: hostDirOf(target.entry.plainFile, options.cwd),
187
+ ...(guidance !== undefined ? { guidance } : {}),
188
+ cause: input.cause,
189
+ status: "waiting",
190
+ queuedAt: Date.now(),
191
+ ...(input.again === true ? { again: true } : {}),
192
+ };
193
+ let resolve;
194
+ const promise = new Promise((done) => (resolve = done));
195
+ ends.set(launch.id, { promise, resolve });
196
+ let resolveTaken;
197
+ const taken = new Promise((done) => (resolveTaken = done));
198
+ takenOver.set(launch.id, { promise: taken, resolve: resolveTaken });
199
+ // Nothing under way, and its code out already: nothing to do - but it ends as any launch does, told to the host
200
+ // (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) {
202
+ const out = isOut(state, launch.commit);
203
+ if (out !== undefined) {
204
+ keep(launch);
205
+ outAlready(state, launch, out);
206
+ return { launch, already: true };
207
+ }
208
+ }
209
+ keep(launch);
210
+ if (state.running === undefined)
211
+ start(state, launch);
212
+ else {
213
+ // The newest wins: what waited is never launched - this one holds its code.
214
+ const older = state.waiting;
215
+ if (older !== undefined) {
216
+ older.status = "superseded";
217
+ older.supersededBy = launch.id;
218
+ older.finishedAt = Date.now();
219
+ changed(older);
220
+ handOn(older, launch);
221
+ }
222
+ state.waiting = launch;
223
+ changed(launch);
224
+ }
225
+ return { launch, already: false };
226
+ },
227
+ current: (codebase) => codebases.get(codebase)?.current,
228
+ pending(codebase) {
229
+ const state = codebases.get(codebase);
230
+ return state?.running?.launch ?? state?.waiting;
231
+ },
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));
237
+ },
238
+ done(id) {
239
+ const end = ends.get(id);
240
+ if (end !== undefined)
241
+ return end.promise;
242
+ const known = launches.find((launch) => launch.id === id);
243
+ return known !== undefined ? Promise.resolve(known) : Promise.reject(new Error(`No launch ${id}.`));
244
+ },
245
+ replaced(id) {
246
+ const taken = takenOver.get(id);
247
+ return taken !== undefined ? taken.promise : Promise.reject(new Error(`No launch ${id}.`));
248
+ },
249
+ holds(codebase, commit) {
250
+ const state = codebases.get(codebase);
251
+ const current = state?.current;
252
+ if (state === undefined || current === undefined)
253
+ return false;
254
+ return holdsCommit(state.moduleDir, commit, current.commit);
255
+ },
256
+ async stop(codebase) {
257
+ const stopped = [];
258
+ for (const [name, state] of codebases) {
259
+ if (codebase !== undefined && name !== codebase)
260
+ continue;
261
+ const waiting = state.waiting;
262
+ if (waiting !== undefined) {
263
+ state.waiting = undefined;
264
+ waiting.status = "stopped";
265
+ waiting.summary = "Stopped on request, before it started.";
266
+ waiting.finishedAt = Date.now();
267
+ changed(waiting);
268
+ ended(waiting);
269
+ stopped.push(`${waiting.id} (${name})`);
270
+ }
271
+ if (state.running !== undefined) {
272
+ state.running.abort.abort();
273
+ stopped.push(`${state.running.launch.id} (${name})`);
274
+ }
275
+ settle(state);
276
+ }
277
+ return stopped;
278
+ },
279
+ halted(codebase) {
280
+ const stopped = [];
281
+ for (const [name, state] of codebases) {
282
+ if (codebase !== undefined && name !== codebase)
283
+ continue;
284
+ const current = state.current;
285
+ if (current === undefined || current.status !== "launched" || runningLaunched(name).length > 0)
286
+ continue;
287
+ current.status = "stopped";
288
+ current.summary = "Stopped on request.";
289
+ current.finishedAt = Date.now();
290
+ state.current = undefined;
291
+ finished(current);
292
+ changed(current);
293
+ stopped.push(current.id);
294
+ }
295
+ return stopped;
296
+ },
297
+ list: () => [...launches],
298
+ async sweep() {
299
+ const stopped = await stopLeftBehind(projectDirOf(join(options.cwd, "turri.plain")));
300
+ noteLeftBehind(stopped);
301
+ return stopped;
302
+ },
303
+ running: (codebase) => runningLaunched(codebase),
304
+ };
305
+ return track;
306
+ }
307
+ /** A launch in a line: its codebase, commit, how it stands - for /halt, pulses and the panel. */
308
+ export function describeLaunchLine(launch) {
309
+ const why = "pulse" in launch.cause ? ` after pulse ${launch.cause.pulse}` : "";
310
+ const how = launch.status === "waiting"
311
+ ? "waiting"
312
+ : launch.status === "running"
313
+ ? "launching"
314
+ : launch.status === "launched"
315
+ ? launch.already === true
316
+ ? "out already"
317
+ : "launched"
318
+ : launch.status;
319
+ return `${launch.id} ${how} ${launch.codebase} at ${launch.short}${why}`;
320
+ }
package/dist/loop-cli.js CHANGED
@@ -12,7 +12,7 @@ import { describeDiagnosis, diagnoseFailure } from "./regenerate/diagnose.js";
12
12
  import { createJobRegistry, pulseName } from "./regenerate/jobs.js";
13
13
  import { createWorkLoop, describeModules, functionalityCompletion } from "./regenerate/loop.js";
14
14
  import { MODULES_DIR, projectDirOf } from "./regenerate/paths.js";
15
- import { exportModule } from "./regenerate/release.js";
15
+ import { exportModule } from "./regenerate/launch.js";
16
16
  import { listFiles } from "./regenerate/testing.js";
17
17
  import { startRunReport } from "./run-report.js";
18
18
  import { configKeyOptions, optionValue } from "./cli-options.js";
@@ -222,12 +222,12 @@ function refuseBuildDir(buildDir, projectDir) {
222
222
  /** The furthest-built codebase's last commit, exported into `dir` - or why nothing was. */
223
223
  function exportCode(plainFile, dir) {
224
224
  try {
225
- const deployment = exportModule(plainFile, undefined, dir);
225
+ const code = exportModule(plainFile, { into: dir });
226
226
  const files = listFiles(dir).length;
227
227
  // Its history began, and nothing landed in it yet: only the harness's own files, which are left out.
228
228
  if (files === 0)
229
- return { exported: false, dir, why: `nothing has landed in ${deployment.moduleName} yet: its codebase holds no code` };
230
- return { exported: true, dir, module: deployment.moduleName, commit: deployment.commit, files };
229
+ return { exported: false, dir, why: `nothing has landed in ${code.moduleName} yet: its codebase holds no code` };
230
+ return { exported: true, dir, module: code.moduleName, commit: code.short, files };
231
231
  }
232
232
  catch (error) {
233
233
  return { exported: false, dir, why: error instanceof Error ? error.message : String(error) };
@@ -1,8 +1,8 @@
1
1
  import { type ExtensionContext, type ToolDefinition } from "@earendil-works/pi-coding-agent";
2
2
  import { Type } from "typebox";
3
3
  import { type ModuleStatus, type WorkLoop } from "./regenerate/loop.ts";
4
- import type { RenderWork } from "./regenerate/engine.ts";
5
4
  import { type Job, type JobRegistry } from "./regenerate/jobs.ts";
5
+ import type { LaunchTrack } from "./launch-track.ts";
6
6
  /**
7
7
  * The tools that act on the work loop - `regenerate`, `drift` and `halt` - defined once, for the conversation and for the
8
8
  * skills alike: a skill that regenerates what a spec holds, or reads how far it is regenerated, uses the conversation's
@@ -13,18 +13,15 @@ type AnyTool = ToolDefinition<any, any, any>;
13
13
  export declare const GUIDANCE_PARAM: Type.TOptional<Type.TString>;
14
14
  export declare const WORKING_DIR_PARAM: Type.TOptional<Type.TString>;
15
15
  export declare const MODEL_PARAM: Type.TOptional<Type.TString>;
16
- export declare const STACK_PARAM: Type.TOptional<Type.TString>;
17
16
  /**
18
- * Why a module asked for with no stack named cannot be built: a project of stacks where it has no stack of its own and
19
- * none is chosen, and config.turri.yaml alone names no unit testing script - every pulse would stop for want of one.
20
- * The stacks and the script each names, and what to do. Undefined when it can be built.
17
+ * Why a module cannot be built with the config it would be built with: two of the modules it requires have a config
18
+ * file of their own (`configModuleFor`); or, in a project where modules have their own files, it has none - nor any
19
+ * module it requires - and config.turri.yaml alone names no unit testing script, so every pulse would stop for want of
20
+ * one. The files there are and the script each names, and what to do. Undefined when it can be built.
21
21
  */
22
- export declare function stacklessBuild(plainFile: string): string | undefined;
23
- /**
24
- * `work` with the stack a call names chosen for it - or, none named, as it is: each module is then built with its own
25
- * (`stackForModule`). A module that could not be built that way is refused before anything is planned (`stacklessBuild`).
26
- */
27
- export declare function withCallStack<T>(plainFile: string, named: string | undefined, work: () => T): T;
22
+ export declare function unbuildableConfig(plainFile: string): string | undefined;
23
+ /** `work`, once the module asked for can be built with the config it would be built with - refused before anything is planned otherwise (`unbuildableConfig`). */
24
+ export declare function whenBuildable<T>(plainFile: string, work: () => T): T;
28
25
  export declare const WAIT_PARAM: Type.TOptional<Type.TBoolean>;
29
26
  /**
30
27
  * A render tool's arguments as if turri had been started in `working_dir`: the .plain file
@@ -75,12 +72,12 @@ export declare function stopJob(jobs: JobRegistry, named: string, reason?: strin
75
72
  export interface LoopToolsOptions {
76
73
  /** Where turri was started: the folder plain_file and working_dir are relative to. */
77
74
  cwd: string;
78
- /** The pulses `halt` stops. Without them - the release agent's - it stops only what activate started. */
75
+ /** The pulses the tools act on. */
79
76
  jobs?: JobRegistry;
80
77
  /** The work loop the tools act on - the conversation's, for a call in it. */
81
78
  loop?: (ctx: ExtensionContext) => WorkLoop;
82
- /** The model a pulse of this call regenerates on: the one named, or the one chosen for the work. Default: the one named. */
83
- model?: (ctx: ExtensionContext, plainFile: string, named?: string, work?: RenderWork) => string | undefined;
79
+ /** The model a pulse of this call regenerates on: the one named, or the module's coding model. Default: the one named. */
80
+ model?: (ctx: ExtensionContext, plainFile: string, named?: string) => string | undefined;
84
81
  /** Whether a call waits for its work to finish, given what it asked. Default: only when it asked to. */
85
82
  wait?: (ctx: ExtensionContext, asked?: boolean) => boolean;
86
83
  }
@@ -96,8 +93,12 @@ export declare function regenerateTool(options: LoopToolsOptions & {
96
93
  export declare function driftTool(options: LoopToolsOptions & {
97
94
  loop: (ctx: ExtensionContext) => WorkLoop;
98
95
  }): AnyTool;
99
- /** halt: stop a pulse, or what activate started. */
100
- export declare function haltTool(options: Pick<LoopToolsOptions, "jobs"> & {
96
+ /** halt: stop a pulse, a module's planned pulses, a launch under way, or what a launch started. */
97
+ export declare function haltTool(options: {
98
+ jobs: JobRegistry;
101
99
  workLoop?: () => WorkLoop | undefined;
100
+ launches?: LaunchTrack;
102
101
  }): AnyTool;
102
+ /** Halt what a launch started by its name, a module's launch under way and what it started, or every one: what was halted, said. */
103
+ export declare function haltLaunched(which: string, launches: LaunchTrack | undefined): Promise<string>;
103
104
  export {};
@@ -3,14 +3,14 @@ import { refuseTestPlainFile } from "./test-plain-files.js";
3
3
  import { basename, relative, resolve } from "node:path";
4
4
  import { defineTool } from "@earendil-works/pi-coding-agent";
5
5
  import { Type } from "typebox";
6
- import { CONFIG_FILE, readProjectConfig, stackConfigFile, stackForModule, stackNamed, stacksOf, withStack } from "./config.js";
6
+ import { CONFIG_FILE, readProjectConfig, moduleConfigFile, configModuleFor, moduleConfigsOf, withConfigModule } from "./config.js";
7
7
  import { checkPlainFile, formatCheckResults } from "./plain/check.js";
8
8
  import { describeDrift, describeModules } from "./regenerate/loop.js";
9
9
  import { describeJob, pulseName } from "./regenerate/jobs.js";
10
10
  import { currentChat } from "./chat-scope.js";
11
11
  import { whyFailed } from "./regenerate/diagnose-job.js";
12
12
  import { didNotLand } from "./regenerate/failure-reports.js";
13
- import { stopDeployed } from "./regenerate/release.js";
13
+ import { runningLaunched, stopLaunched } from "./regenerate/launch.js";
14
14
  import { projectDirOf } from "./regenerate/paths.js";
15
15
  import { findTestScripts } from "./regenerate/test-scripts.js";
16
16
  import { surfaceOf } from "./surface.js";
@@ -26,43 +26,42 @@ export const WORKING_DIR_PARAM = Type.Optional(Type.String({
26
26
  }));
27
27
  export const MODEL_PARAM = Type.Optional(Type.String({
28
28
  description: "The model for the agents of this one call: a provider/model-id, or its name as the user said it. " +
29
- "Omitted: the model chosen for this kind of work with engine, else the conversation's. " +
30
- "To change it for every later pulse, use engine instead.",
31
- }));
32
- export const STACK_PARAM = Type.Optional(Type.String({
33
- description: "In a project of stacks: the stack that builds this module - its config.turri.<stack>.yaml over config.turri.yaml, " +
34
- "its testing scripts, toolchains and models - for every pulse of it, whatever stack is chosen later. \"none\": " +
35
- "config.turri.yaml alone. Omitted: the stack named after the module - config.turri.backend.yaml for backend.plain - " +
36
- "else the one chosen now.",
29
+ "Omitted: the coding model the module's config names, else the conversation's. " +
30
+ "To change it for every later pulse, set coding-model with settings instead.",
37
31
  }));
38
32
  /**
39
- * Why a module asked for with no stack named cannot be built: a project of stacks where it has no stack of its own and
40
- * none is chosen, and config.turri.yaml alone names no unit testing script - every pulse would stop for want of one.
41
- * The stacks and the script each names, and what to do. Undefined when it can be built.
33
+ * Why a module cannot be built with the config it would be built with: two of the modules it requires have a config
34
+ * file of their own (`configModuleFor`); or, in a project where modules have their own files, it has none - nor any
35
+ * module it requires - and config.turri.yaml alone names no unit testing script, so every pulse would stop for want of
36
+ * one. The files there are and the script each names, and what to do. Undefined when it can be built.
42
37
  */
43
- export function stacklessBuild(plainFile) {
38
+ export function unbuildableConfig(plainFile) {
44
39
  const root = projectDirOf(plainFile);
45
- const stacks = stacksOf(root);
46
- if (stacks.length === 0 || stackForModule(plainFile) !== undefined || findTestScripts(root).unit !== undefined)
40
+ let own;
41
+ try {
42
+ own = configModuleFor(plainFile);
43
+ }
44
+ catch (error) {
45
+ return error instanceof Error ? error.message : String(error);
46
+ }
47
+ const files = moduleConfigsOf(root);
48
+ if (files.length === 0 || own !== undefined || findTestScripts(root).unit !== undefined)
47
49
  return undefined;
48
- const scripts = stacks.map((each) => {
49
- const unit = withStack(each, () => findTestScripts(root).unit);
50
- return `${each}${unit !== undefined ? ` (${stackConfigFile(each)}: ${relative(root, unit)})` : ""}`;
50
+ const scripts = files.map((each) => {
51
+ const unit = withConfigModule(each, () => findTestScripts(root).unit);
52
+ return `${moduleConfigFile(each)}${unit !== undefined ? ` (${relative(root, unit)})` : ""}`;
51
53
  });
52
- return (`${basename(plainFile)} would be built with no stack - ${CONFIG_FILE} alone - and that names no unit testing script, so every ` +
53
- `pulse would stop. No stack is named after it, and none is chosen. The project's stacks: ${scripts.join(", ")}. Pass the ` +
54
- `stack that builds ${basename(plainFile)} as stack - or ask the user which, when the spec does not make it plain.`);
54
+ const name = basename(plainFile, ".plain");
55
+ return (`${basename(plainFile)} would be built with ${CONFIG_FILE} alone - it has no ${moduleConfigFile(name)}, and none of the ` +
56
+ `modules it requires has one - and that names no unit testing script, so every pulse would stop. The modules' own ` +
57
+ `files: ${scripts.join(", ")}. Name its testing scripts in its own file - the settings tool, with module ${basename(plainFile)} - ` +
58
+ `or ask the user which, when the ***plain does not make it plain.`);
55
59
  }
56
- /**
57
- * `work` with the stack a call names chosen for it - or, none named, as it is: each module is then built with its own
58
- * (`stackForModule`). A module that could not be built that way is refused before anything is planned (`stacklessBuild`).
59
- */
60
- export function withCallStack(plainFile, named, work) {
61
- if (named !== undefined)
62
- return withStack(stackNamed(projectDirOf(plainFile), named), work);
63
- const stackless = stacklessBuild(plainFile);
64
- if (stackless !== undefined)
65
- throw new Error(`Nothing was started: ${stackless}`);
60
+ /** `work`, once the module asked for can be built with the config it would be built with - refused before anything is planned otherwise (`unbuildableConfig`). */
61
+ export function whenBuildable(plainFile, work) {
62
+ const unbuildable = unbuildableConfig(plainFile);
63
+ if (unbuildable !== undefined)
64
+ throw new Error(`Nothing was started: ${unbuildable}`);
66
65
  return work();
67
66
  }
68
67
  export const WAIT_PARAM = Type.Optional(Type.Boolean({
@@ -237,7 +236,6 @@ export function regenerateTool(options) {
237
236
  "A change to a file the spec links - an API surface, a mapping document - is a change to the spec: regenerate sees it by itself, and regenerates every functional spec that uses what links it.",
238
237
  "Never stop pulses and start them again yourself to follow a spec change: regenerate does it.",
239
238
  "Set from_scratch only when the user asks for the module to be regenerated from scratch - started over, its code deleted - in this conversation, or agrees to it when a module's status says it has to start over: never to fix a pulse that did not land.",
240
- "In a project of stacks - a backend and a frontend, each with its config.turri.<stack>.yaml - a module is built with the stack named after it by itself: backend.plain with config.turri.backend.yaml. Pass stack only for a module whose stack has another name. It is pinned to the module's pulses: a backend and a frontend regenerate side by side, each with its own, without switching the stack chosen. What it says back names the stack each module is built with.",
241
239
  'from_scratch "module" takes out the code where the module is built; the modules below keep theirs, and the module starts from a copy of the code below it. "chain" takes out every codebase of its requires chain, the base\'s too, and builds all of it again from the bottom: use it after modules were split, merged or moved (refactor-module), or when the user asks for the whole chain.',
242
240
  ],
243
241
  parameters: Type.Object({
@@ -251,13 +249,12 @@ export function regenerateTool(options) {
251
249
  description: "Only when the user asks for it: the module's code and conformance tests deleted - committed first, so its lineage keeps them - and the whole module regenerated from its spec. " +
252
250
  '"chain": every module of its requires chain too, built again from the bottom',
253
251
  })),
254
- stack: STACK_PARAM,
255
252
  model: MODEL_PARAM,
256
253
  wait: WAIT_PARAM,
257
254
  }),
258
255
  async execute(_id, given, _signal, _onUpdate, ctx) {
259
256
  const plainFile = plainFileOf(options.cwd, given, "regenerate");
260
- return withCallStack(plainFile, given.stack, async () => {
257
+ return whenBuildable(plainFile, async () => {
261
258
  const check = checkPlainFile(plainFile);
262
259
  // The parser's message as it gives it, a test plain file out of place, and turri's next step for the old syntax.
263
260
  if (!check.ok)
@@ -265,9 +262,7 @@ export function regenerateTool(options) {
265
262
  const again = given.funcIds ?? [];
266
263
  if (again.length > 0 && given.from_scratch !== undefined)
267
264
  throw new Error("Name funcIds or set from_scratch, not both: from scratch regenerates every one of them.");
268
- // Named functionalities are work on functionalities, as engine chooses a model for it; the rest, spec changes.
269
- const work = again.length > 0 ? "functionalities" : "spec_changes";
270
- const model = options.model !== undefined ? options.model(ctx, plainFile, given.model, work) : given.model;
265
+ const model = options.model !== undefined ? options.model(ctx, plainFile, given.model) : given.model;
271
266
  const loop = options.loop(ctx);
272
267
  const request = { ...(model !== undefined ? { model } : {}), ...(given.guidance !== undefined ? { guidance: given.guidance } : {}) };
273
268
  const wait = options.wait !== undefined ? options.wait(ctx, given.wait) : given.wait === true;
@@ -314,49 +309,54 @@ export function driftTool(options) {
314
309
  },
315
310
  });
316
311
  }
317
- const ACTIVATED_PARAM = Type.Optional(Type.String({ description: 'What activate started, by name - or "all" for every one' }));
318
- const HALT_PULSE_PARAMS = Type.Object({
312
+ const HALT_PARAMS = Type.Object({
319
313
  job_id: Type.Optional(Type.String({ description: "The pulse's id, or the start of it; a planned row's id (planned-<module>-...), or a module's name, halts the module" })),
320
314
  reason: Type.Optional(Type.String({ description: "Why it is halted, kept with it - what the spec now says that it did not, say" })),
321
- activated: ACTIVATED_PARAM,
315
+ launched: Type.Optional(Type.String({ description: 'What a launch started, by name; a module\'s name for its launch under way and what it started; or "all"' })),
322
316
  });
323
- /** With no pulses - the release agent's halt - only what activate started. */
324
- const HALT_ACTIVATED_PARAMS = Type.Object({ activated: ACTIVATED_PARAM });
325
- /** halt: stop a pulse, or what activate started. */
317
+ /** halt: stop a pulse, a module's planned pulses, a launch under way, or what a launch started. */
326
318
  export function haltTool(options) {
327
319
  const { jobs } = options;
328
320
  return defineTool({
329
321
  name: "halt",
330
322
  label: "Halt",
331
- description: jobs !== undefined
332
- ? "Halt a pulse, a module's planned pulses, or what activate started. A pulse: a queued one never starts, a running one has its " +
333
- "agent stopped at once, and the pulses queued behind it move up - what a running pulse already changed is rolled back, and what " +
334
- "it was regenerating counts as not regenerated. A planned row (planned-<module>-...) or a module's name halts the module: its " +
335
- "running pulse stopped, none of its planned pulses started, and the modules built on it waiting - until it is asked for again " +
336
- "with regenerate; a spec change does not start it. A module whose .plain file is gone is dropped. What activate started: the " +
337
- "one named, or every one."
338
- : "Stop what activate started: the one named, or every one.",
339
- promptSnippet: jobs !== undefined ? "halt a pulse, or what activate started" : "stop a deployed server, or all of them",
340
- promptGuidelines: jobs !== undefined
341
- ? [
342
- "Halt a pulse only when the user asks, or your instructions say to. Name which one, and say which pulses were queued behind it - they will now run.",
343
- "Halting a planned row halts its whole module - one planned pulse cannot be taken out alone, as the plan is made again from the spec. To build some of it later, or cut it differently, use steer; to drop work, change the spec.",
344
- "A planned row for a module that is no longer in the project is halted the same way, and dropped.",
345
- ]
346
- : [],
347
- parameters: (jobs !== undefined ? HALT_PULSE_PARAMS : HALT_ACTIVATED_PARAMS),
323
+ description: "Halt a pulse, a module's planned pulses, or a launch. A pulse: a queued one never starts, a running one has its " +
324
+ "agent stopped at once, and the pulses queued behind it move up - what a running pulse already changed is rolled back, and what " +
325
+ "it was regenerating counts as not regenerated. A planned row (planned-<module>-...) or a module's name halts the module: its " +
326
+ "running pulse stopped, none of its planned pulses started, and the modules built on it waiting - until it is asked for again " +
327
+ "with regenerate; a spec change does not start it. A module whose .plain file is gone is dropped. launched: what a launch " +
328
+ "started, by name; a module's name, its launch under way and what it started; or all.",
329
+ promptSnippet: "halt a pulse, or a launch and what it started",
330
+ promptGuidelines: [
331
+ "Halt a pulse only when the user asks, or your instructions say to. Name which one, and say which pulses were queued behind it - they will now run.",
332
+ "Halting a planned row halts its whole module - one planned pulse cannot be taken out alone, as the plan is made again from the spec. To build some of it later, or cut it differently, use steer; to drop work, change the spec.",
333
+ "A planned row for a module that is no longer in the project is halted the same way, and dropped.",
334
+ ],
335
+ parameters: HALT_PARAMS,
348
336
  async execute(_id, params) {
349
- if (params.job_id === undefined && params.activated === undefined) {
350
- throw new Error(jobs !== undefined ? "Say what to halt: a job_id, or what activate started (activated)." : 'Say what to stop: its name, or "all" (activated).');
351
- }
337
+ if (params.job_id === undefined && params.launched === undefined)
338
+ throw new Error("Say what to halt: a job_id, or a launch (launched).");
352
339
  const lines = [];
353
- if (params.job_id !== undefined && jobs !== undefined)
340
+ if (params.job_id !== undefined)
354
341
  lines.push(stopJob(jobs, params.job_id, params.reason, options.workLoop?.()));
355
- if (params.activated !== undefined) {
356
- const stopped = await stopDeployed(params.activated === "all" ? {} : { name: params.activated });
357
- lines.push(stopped.length > 0 ? `Halted ${stopped.join(", ")}.` : `Nothing activate started is running${params.activated === "all" ? "" : ` as ${params.activated}`}.`);
358
- }
342
+ if (params.launched !== undefined)
343
+ lines.push(await haltLaunched(params.launched, options.launches));
359
344
  return { content: [{ type: "text", text: lines.join("\n") }], details: {} };
360
345
  },
361
346
  });
362
347
  }
348
+ /** Halt what a launch started by its name, a module's launch under way and what it started, or every one: what was halted, said. */
349
+ export async function haltLaunched(which, launches) {
350
+ const all = which === "all";
351
+ const underWay = launches !== undefined && (all || launches.pending(which) !== undefined) ? await launches.stop(all ? undefined : which) : [];
352
+ const module = !all && runningLaunched(which).length > 0 && !runningLaunched().some((item) => item.name === which);
353
+ const before = runningLaunched();
354
+ const stopped = await stopLaunched(all ? {} : module || underWay.length > 0 ? { moduleName: which } : { name: which });
355
+ // The launches whose servers those were, with nothing of them left running: stopped too - a host hears it, and the next
356
+ // launch of the codebase launches anew.
357
+ const codebases = new Set(before.filter((item) => item.exited !== undefined).map((item) => item.moduleName));
358
+ for (const codebase of codebases)
359
+ launches?.halted(codebase);
360
+ const halted = [...underWay.map((id) => `the launch ${id}`), ...stopped];
361
+ return halted.length > 0 ? `Halted ${halted.join(", ")}.` : `Nothing a launch started is running${all ? "" : ` as ${which}`}, and no launch of it is under way.`;
362
+ }