@turri-dev/cli 0.2.4-next.8422d0f → 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 (175) hide show
  1. package/README.md +7 -8
  2. package/dist/bedrock-region.js +3 -3
  3. package/dist/chat-idle.d.ts +2 -2
  4. package/dist/chat-idle.js +2 -2
  5. package/dist/chat-models.d.ts +1 -1
  6. package/dist/chat-models.js +1 -1
  7. package/dist/chat-scope.d.ts +1 -3
  8. package/dist/chat-skills.d.ts +1 -1
  9. package/dist/chat-skills.js +1 -1
  10. package/dist/chats.d.ts +44 -20
  11. package/dist/chats.js +125 -64
  12. package/dist/cli.js +12 -31
  13. package/dist/config-edit.d.ts +20 -8
  14. package/dist/config-edit.js +32 -26
  15. package/dist/config.d.ts +106 -78
  16. package/dist/config.js +267 -133
  17. package/dist/conform-cli.js +14 -3
  18. package/dist/conformance-switch.d.ts +13 -22
  19. package/dist/conformance-switch.js +37 -59
  20. package/dist/drift-cli.js +1 -1
  21. package/dist/extension.d.ts +17 -10
  22. package/dist/extension.js +435 -532
  23. package/dist/genome.js +10 -49
  24. package/dist/graph.js +3 -5
  25. package/dist/host-session.d.ts +11 -21
  26. package/dist/host-session.js +6 -8
  27. package/dist/host.d.ts +4 -4
  28. package/dist/host.js +4 -7
  29. package/dist/identity.js +2 -3
  30. package/dist/init-config.d.ts +1 -2
  31. package/dist/init-config.js +10 -17
  32. package/dist/installed-providers.d.ts +1 -1
  33. package/dist/installed-providers.js +1 -1
  34. package/dist/launch-agent.d.ts +51 -0
  35. package/dist/launch-agent.js +267 -0
  36. package/dist/{release-cli.js → launch-cli.js} +41 -24
  37. package/dist/launch-session.d.ts +68 -0
  38. package/dist/launch-session.js +217 -0
  39. package/dist/launch-tools.d.ts +28 -0
  40. package/dist/launch-tools.js +69 -0
  41. package/dist/launch-track.d.ts +125 -0
  42. package/dist/launch-track.js +320 -0
  43. package/dist/loop-cli.d.ts +4 -3
  44. package/dist/loop-cli.js +17 -15
  45. package/dist/loop-tools.d.ts +45 -21
  46. package/dist/loop-tools.js +155 -90
  47. package/dist/new-project.js +2 -2
  48. package/dist/notice.d.ts +7 -6
  49. package/dist/parse-cli.js +2 -2
  50. package/dist/pi-launch.js +4 -1
  51. package/dist/pi-settings.d.ts +4 -0
  52. package/dist/pi-settings.js +39 -0
  53. package/dist/pi.js +12 -9
  54. package/dist/plain/check.d.ts +2 -9
  55. package/dist/plain/check.js +6 -39
  56. package/dist/plain-files.d.ts +2 -2
  57. package/dist/plain-files.js +7 -7
  58. package/dist/regenerate/activity.d.ts +0 -7
  59. package/dist/regenerate/activity.js +2 -20
  60. package/dist/regenerate/agent-env.d.ts +1 -1
  61. package/dist/regenerate/agent-env.js +3 -3
  62. package/dist/regenerate/agent-shell.js +5 -3
  63. package/dist/regenerate/audit.js +9 -0
  64. package/dist/regenerate/base-folder.d.ts +2 -2
  65. package/dist/regenerate/base-folder.js +1 -1
  66. package/dist/regenerate/cases.js +7 -0
  67. package/dist/regenerate/chunk-plan.d.ts +5 -0
  68. package/dist/regenerate/chunk-plan.js +16 -1
  69. package/dist/regenerate/command-check.d.ts +7 -1
  70. package/dist/regenerate/command-check.js +43 -1
  71. package/dist/regenerate/delivery.d.ts +1 -1
  72. package/dist/regenerate/delivery.js +3 -3
  73. package/dist/regenerate/drift.d.ts +4 -0
  74. package/dist/regenerate/drift.js +26 -6
  75. package/dist/regenerate/failure-reports.d.ts +28 -0
  76. package/dist/regenerate/failure-reports.js +79 -0
  77. package/dist/regenerate/job-panel.js +3 -1
  78. package/dist/regenerate/jobs-tree.js +1 -1
  79. package/dist/regenerate/jobs.d.ts +4 -2
  80. package/dist/regenerate/jobs.js +14 -10
  81. package/dist/regenerate/launch.d.ts +154 -0
  82. package/dist/regenerate/{release.js → launch.js} +195 -51
  83. package/dist/regenerate/ledger-view.d.ts +11 -24
  84. package/dist/regenerate/ledger-view.js +14 -60
  85. package/dist/regenerate/ledger.d.ts +34 -16
  86. package/dist/regenerate/ledger.js +1 -1
  87. package/dist/regenerate/lineage.d.ts +2 -0
  88. package/dist/regenerate/lineage.js +8 -0
  89. package/dist/regenerate/loop.d.ts +54 -67
  90. package/dist/regenerate/loop.js +312 -148
  91. package/dist/regenerate/model-names.d.ts +33 -0
  92. package/dist/regenerate/{engine.js → model-names.js} +2 -28
  93. package/dist/regenerate/paths.d.ts +3 -3
  94. package/dist/regenerate/paths.js +4 -4
  95. package/dist/regenerate/records.d.ts +11 -0
  96. package/dist/regenerate/records.js +15 -0
  97. package/dist/regenerate/regenerate.d.ts +0 -2
  98. package/dist/regenerate/regenerate.js +4 -15
  99. package/dist/regenerate/renames.js +4 -4
  100. package/dist/regenerate/requires.d.ts +7 -0
  101. package/dist/regenerate/requires.js +24 -18
  102. package/dist/regenerate/scripts-being-written.d.ts +4 -4
  103. package/dist/regenerate/scripts-being-written.js +3 -3
  104. package/dist/regenerate/spec-map.js +3 -3
  105. package/dist/regenerate/standing.js +1 -1
  106. package/dist/regenerate/submit-work.d.ts +2 -0
  107. package/dist/regenerate/submit-work.js +8 -3
  108. package/dist/regenerate/test-scripts.d.ts +2 -1
  109. package/dist/regenerate/test-scripts.js +33 -23
  110. package/dist/regenerate/testing-steps.d.ts +16 -5
  111. package/dist/regenerate/testing-steps.js +28 -9
  112. package/dist/regenerate-cli.js +18 -9
  113. package/dist/self-invocation.d.ts +11 -0
  114. package/dist/self-invocation.js +36 -10
  115. package/dist/sentinel-check.d.ts +3 -3
  116. package/dist/sentinel-check.js +3 -3
  117. package/dist/sentinel.d.ts +18 -12
  118. package/dist/sentinel.js +75 -46
  119. package/dist/{config-command.d.ts → settings.d.ts} +13 -8
  120. package/dist/{config-command.js → settings.js} +155 -24
  121. package/dist/setup.d.ts +2 -2
  122. package/dist/setup.js +7 -7
  123. package/dist/skill.d.ts +0 -11
  124. package/dist/skill.js +0 -9
  125. package/dist/tools.js +2 -3
  126. package/dist/turri-versions.js +2 -1
  127. package/docs/README.md +4 -6
  128. package/docs/authoring-plain.md +3 -3
  129. package/docs/chats.md +6 -9
  130. package/docs/claude-subscription.md +2 -2
  131. package/docs/config.md +61 -51
  132. package/docs/development.md +4 -5
  133. package/docs/headless.md +7 -6
  134. package/docs/hosting.md +25 -24
  135. package/docs/launch.md +67 -0
  136. package/docs/parser.md +3 -3
  137. package/docs/regenerating.md +30 -22
  138. package/docs/sandbox.md +3 -3
  139. package/docs/sentinel.md +28 -16
  140. package/docs/skills-and-gates.md +6 -11
  141. package/docs/using.md +25 -42
  142. package/genome/rules/project-model.md +2 -1
  143. package/genome/rules/test-plain-files.md +15 -7
  144. package/genome/rules/turri-regeneration.md +7 -10
  145. package/genome/skills/convert-old-syntax/SKILL.md +5 -5
  146. package/genome/skills/implement-conformance-testing-script/SKILL.md +2 -2
  147. package/genome/skills/implement-unit-testing-script/SKILL.md +3 -3
  148. package/package.json +1 -1
  149. package/dist/advisor-chat.d.ts +0 -63
  150. package/dist/advisor-chat.js +0 -290
  151. package/dist/change-plain-cli.js +0 -55
  152. package/dist/ledger-cli.d.ts +0 -1
  153. package/dist/ledger-cli.js +0 -50
  154. package/dist/ledger-tools.d.ts +0 -10
  155. package/dist/ledger-tools.js +0 -64
  156. package/dist/regenerate/advisor-records.d.ts +0 -93
  157. package/dist/regenerate/advisor-records.js +0 -110
  158. package/dist/regenerate/advisor-runs.d.ts +0 -87
  159. package/dist/regenerate/advisor-runs.js +0 -327
  160. package/dist/regenerate/engine.d.ts +0 -52
  161. package/dist/regenerate/release.d.ts +0 -121
  162. package/dist/regenerate/test-advisor.d.ts +0 -101
  163. package/dist/regenerate/test-advisor.js +0 -379
  164. package/dist/release-agent.d.ts +0 -43
  165. package/dist/release-agent.js +0 -130
  166. package/dist/release-cli.d.ts +0 -1
  167. package/dist/release-tools.d.ts +0 -44
  168. package/dist/release-tools.js +0 -170
  169. package/dist/spec-tools.d.ts +0 -36
  170. package/dist/spec-tools.js +0 -128
  171. package/dist/stacks.d.ts +0 -13
  172. package/dist/stacks.js +0 -96
  173. package/docs/deploy.md +0 -48
  174. package/docs/test-advisor.md +0 -110
  175. /package/dist/{change-plain-cli.d.ts → launch-cli.d.ts} +0 -0
@@ -0,0 +1,217 @@
1
+ import { configForSpec, readProjectConfig } from "./config.js";
2
+ import { createLaunchTrack } from "./launch-track.js";
3
+ import { runLaunchAgent } from "./launch-agent.js";
4
+ import { holdsCommit, runningLaunched } from "./regenerate/launch.js";
5
+ import { distDirFor, projectDirOf } from "./regenerate/paths.js";
6
+ import { pulseName } from "./regenerate/jobs.js";
7
+ /** How long a pulse that landed is waited for to say its commit: the loop says it as the pulse settles. */
8
+ const COMMIT_WAIT_MS = 10_000;
9
+ export function createSessionLaunches(options) {
10
+ const landedPulses = new Map();
11
+ const waiters = new Map();
12
+ const track = createLaunchTrack({
13
+ cwd: options.cwd,
14
+ run: (launch, code, signal) => {
15
+ const model = options.model(launch.plainFile);
16
+ return runLaunchAgent({ launch, code, cwd: options.cwd, signal, ...(model !== undefined ? { model } : {}) });
17
+ },
18
+ onChange: options.onChange,
19
+ });
20
+ // What an earlier session's launches left running holds the ports this one's need: stopped as the session starts.
21
+ void track.sweep().catch(() => undefined);
22
+ /** Whether the pulse's module launches what lands: its config as the pulse was queued with it. */
23
+ const launchesAfter = (job) => {
24
+ try {
25
+ return readProjectConfig(options.cwd, job.configModule).launchAfterPulse === true;
26
+ }
27
+ catch {
28
+ return false;
29
+ }
30
+ };
31
+ const landedJob = (job) => job.status === "succeeded" && job.details?.landed === true && job.module !== undefined;
32
+ /** The pulse's landing, once the loop has said its commit - none for one that did not land, or never said. */
33
+ const landingOf = async (job) => {
34
+ if (!landedJob(job))
35
+ return undefined;
36
+ const known = landedPulses.get(job.id);
37
+ if (known !== undefined)
38
+ return known;
39
+ await new Promise((resolve) => {
40
+ const timer = setTimeout(resolve, COMMIT_WAIT_MS);
41
+ const list = waiters.get(job.id) ?? [];
42
+ list.push(() => (clearTimeout(timer), resolve()));
43
+ waiters.set(job.id, list);
44
+ });
45
+ return landedPulses.get(job.id);
46
+ };
47
+ 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. */
54
+ const mustHold = (job, landing) => {
55
+ const current = track.current(landing.codebase);
56
+ if (current === undefined) {
57
+ 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
+ }
59
+ 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.`);
61
+ }
62
+ return current;
63
+ };
64
+ return {
65
+ track,
66
+ landed({ job, plainFile, moduleName, commit, title }) {
67
+ const landing = { commit, plainFile, codebase: moduleName };
68
+ if (configForSpec(plainFile).launchAfterPulse === true) {
69
+ try {
70
+ const { launch } = track.request({ plainFile, commit, cause: { pulse: job.id, title } });
71
+ landing.codebase = launch.codebase;
72
+ landing.launch = launch.id;
73
+ }
74
+ catch (error) {
75
+ landing.notAsked = error instanceof Error ? error.message : String(error);
76
+ }
77
+ }
78
+ landedPulses.set(job.id, landing);
79
+ for (const resolve of waiters.get(job.id) ?? [])
80
+ resolve();
81
+ waiters.delete(job.id);
82
+ },
83
+ async readyFor(job) {
84
+ // Nothing is launched for it: there is nothing to wait for.
85
+ if (!launchesAfter(job))
86
+ return;
87
+ const landing = await landingOf(job);
88
+ if (landing === undefined || landing.launch === undefined)
89
+ return;
90
+ await track.settled(landing.codebase);
91
+ if (stoppedLast(landing.codebase))
92
+ return;
93
+ mustHold(job, landing);
94
+ },
95
+ async readyForCheck(check) {
96
+ await track.settled(check.module);
97
+ if (track.current(check.module) === undefined && runningLaunched(check.module).length === 0) {
98
+ throw new Error(`nothing of ${check.module} is launched to test it in - ask the chat to try it first, which launches it.`);
99
+ }
100
+ },
101
+ settled: (codebase) => track.settled(codebase),
102
+ forPulse(job) {
103
+ const landing = landedPulses.get(job.id);
104
+ if (landing === undefined)
105
+ return { later: [], laterSpecs: [], running: [], ...(landedJob(job) && !launchesAfter(job) ? { off: true } : {}) };
106
+ const base = { commit: landing.commit, running: runningLaunched(landing.codebase), later: [], laterSpecs: [] };
107
+ if (landing.notAsked !== undefined)
108
+ return { ...base, notAsked: landing.notAsked };
109
+ if (landing.launch === undefined)
110
+ return { ...base, off: true };
111
+ const launch = track.current(landing.codebase);
112
+ if (launch === undefined || !track.holds(landing.codebase, landing.commit))
113
+ return { ...base, stopped: true };
114
+ // The pulses that landed after it, which what runs holds too: what they changed is theirs to test.
115
+ const later = options.jobs
116
+ .list()
117
+ .filter((other) => {
118
+ const theirs = landedPulses.get(other.id);
119
+ return (other.id !== job.id &&
120
+ theirs !== undefined &&
121
+ theirs.codebase === landing.codebase &&
122
+ theirs.commit !== landing.commit &&
123
+ holdsCommit(launch.moduleDir, landing.commit, theirs.commit) &&
124
+ holdsCommit(launch.moduleDir, theirs.commit, launch.commit));
125
+ })
126
+ .sort((a, b) => a.sequence - b.sequence);
127
+ const key = (spec) => `${spec.module}:${spec.funcId}`;
128
+ const theirs = new Set(later.flatMap((other) => specsOf(other).map(key)));
129
+ return { ...base, launch, later, laterSpecs: specsOf(job).filter((spec) => theirs.has(key(spec))) };
130
+ },
131
+ resumeText(work) {
132
+ if ("job" in work) {
133
+ const landing = landedPulses.get(work.job.id);
134
+ if (landing === undefined)
135
+ throw new Error(`turri has no commit for pulse ${work.job.id}.`);
136
+ const launch = mustHold(work.job, landing);
137
+ 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:",
140
+ ...(launch.status === "failed" ? [] : whatRuns(runningLaunched(launch.codebase), launchedDir(launch))),
141
+ "",
142
+ LAUNCHED_ONLY,
143
+ "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
+ ].join("\n");
145
+ }
146
+ const running = runningLaunched(work.check.module);
147
+ if (track.current(work.check.module) === undefined && running.length === 0)
148
+ throw new Error(`nothing of ${work.check.module} runs any more to test check ${work.check.id} in.`);
149
+ 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),
152
+ "",
153
+ LAUNCHED_ONLY,
154
+ "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.",
155
+ ].join("\n");
156
+ },
157
+ };
158
+ }
159
+ /** A pulse's functional specs, every case. */
160
+ function specsOf(job) {
161
+ const cases = job.cases;
162
+ return cases === undefined ? [] : [...cases.add, ...cases.patch, ...cases.again, ...cases.delete];
163
+ }
164
+ /**
165
+ * What the sentinel tests in, whatever is launched: what turri launched, and nothing it starts itself. Said in every
166
+ * brief - a server it starts from plain_modules would pass on code nobody launched.
167
+ */
168
+ export const LAUNCHED_ONLY = "Never run the code in plain_modules, where a pulse may be writing, nor start a server of your own - not in your shell, not with a host's terminal: what would pass there is not what the person tries. A server that should run and does not is your finding.";
169
+ /** The folder a launch's code is in: dist/<module>, where it is tried from. */
170
+ export function launchedDir(launch) {
171
+ return launch.code?.dir ?? distDirFor(projectDirOf(launch.plainFile), launch.codebase);
172
+ }
173
+ /**
174
+ * What runs of a launch, a line each: where, from where, its output - or that nothing was left running, and the folder it
175
+ * is tried from.
176
+ */
177
+ export function whatRuns(running, from) {
178
+ if (running.length === 0) {
179
+ return [
180
+ from !== undefined
181
+ ? ` nothing is left running. It is in place in ${from}: try it from there - a CLI or a library as its README and entry points say. Something there that should serve and does not is what you find out about.`
182
+ : " nothing is left running.",
183
+ ];
184
+ }
185
+ return running.map((item) => ` ${item.name}: ${item.url ?? item.command} - in ${item.dir}, its output in ${item.log}`);
186
+ }
187
+ /** Why a launch was asked for, as the chat is told it: after which pulse landed - nothing for one a chat asked for. */
188
+ const afterPulse = (launch, job) => ("pulse" in launch.cause ? ` after ${job !== undefined ? pulseName(job) : `pulse ${launch.cause.pulse}`} landed` : "");
189
+ /**
190
+ * What the chat that asked for a launch is told when a newer one takes its place - superseded as it waited, or ended with
191
+ * the newer one waiting, which stops what it started: it is told the newer one's end instead.
192
+ */
193
+ export function replacedNote(launch, next, job) {
194
+ const how = launch.status === "superseded" ? "never started" : launch.status === "launched" ? "came up, but not for long" : "ended";
195
+ return [
196
+ `The launch of ${launch.codebase} at ${launch.short} you asked for (${launch.id}) ${how}: a newer launch of it, ${next.id} at ${next.short}${afterPulse(next, job)}, takes its place${launch.status === "superseded" ? "" : " and stops what it started"}.`,
197
+ "You are told where that one runs, or why it did not come up, once it ends. Say so in a line, if the person is waiting for it; open nothing and start nothing for it now.",
198
+ ].join("\n");
199
+ }
200
+ /** What a chat is told of a launch that ended - one it asked for, or one after a pulse with the sentinel off. */
201
+ export function launchedNote(launch, job) {
202
+ const after = afterPulse(launch, job);
203
+ if (launch.status === "stopped")
204
+ return `The launch of ${launch.codebase} at ${launch.short}${after} was stopped on request: nothing of it runs. Say so in a line.`;
205
+ const head = launch.status === "launched"
206
+ ? `${launch.codebase} at ${launch.short} is launched${after}${launch.already === true ? " - out already" : ""}.`
207
+ : `The launch of ${launch.codebase} at ${launch.short}${after} did not come up.`;
208
+ return [
209
+ head,
210
+ "",
211
+ (launch.summary ?? "").trim(),
212
+ "",
213
+ launch.status === "launched"
214
+ ? "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."
215
+ : "Tell the person in a line or two why it did not come up and what they can do - what the machine lacks they install themselves. Do not launch it again unless they ask.",
216
+ ].join("\n");
217
+ }
@@ -0,0 +1,28 @@
1
+ import { type ExtensionContext } from "@earendil-works/pi-coding-agent";
2
+ import { Type } from "typebox";
3
+ import type { Launch, LaunchTrack } from "./launch-track.ts";
4
+ /**
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
+ * at once - the launch agent works in the background, and the chat is told how it went once it ends. The harness does
7
+ * the parts that must hold - exporting the commit, stopping what the last launch started, owning what this one starts -
8
+ * and the agent the rest.
9
+ */
10
+ export declare function launchTool(options: {
11
+ cwd: string;
12
+ track: LaunchTrack;
13
+ /** The spec launch takes when it is given none: the project's module. */
14
+ defaultPlainFile: () => string | undefined;
15
+ /** The chat it is called in. */
16
+ chat: () => string | undefined;
17
+ /** The launch asked for ended - or the one that took its place: the chat is told how it went. */
18
+ ended: (launch: Launch) => void;
19
+ /** A newer launch took the place of the one asked for: the chat is told it hears that one's end instead. */
20
+ replaced?: (launch: Launch, next: Launch) => void;
21
+ /** Whether the call waits for the launch to end - pi's print, json and rpc modes, which end with the reply. Default: never. */
22
+ wait?: (ctx: ExtensionContext) => boolean;
23
+ }): import("@earendil-works/pi-coding-agent").ToolDefinition<Type.TObject<{
24
+ plain_file: Type.TOptional<Type.TString>;
25
+ in_module: Type.TOptional<Type.TString>;
26
+ again: Type.TOptional<Type.TBoolean>;
27
+ guidance: Type.TOptional<Type.TString>;
28
+ }>, unknown, any> & import("@earendil-works/pi-coding-agent").ToolDefinition<any, any, any>;
@@ -0,0 +1,69 @@
1
+ import { resolve } from "node:path";
2
+ import { defineTool } from "@earendil-works/pi-coding-agent";
3
+ import { Type } from "typebox";
4
+ import { refuseTestPlainFile } from "./test-plain-files.js";
5
+ /**
6
+ * 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
+ * at once - the launch agent works in the background, and the chat is told how it went once it ends. The harness does
8
+ * the parts that must hold - exporting the commit, stopping what the last launch started, owning what this one starts -
9
+ * and the agent the rest.
10
+ */
11
+ export function launchTool(options) {
12
+ return defineTool({
13
+ name: "launch",
14
+ label: "Launch",
15
+ description: "Launch what is regenerated for the person to try, in the background: the last commit of the module on top of the " +
16
+ "spec's requires chain, which holds the code of the ones below, exported to dist/<module>, and an agent that starts it " +
17
+ "on this machine - or, with guidance, follows it from the host codebase: an integration a host application loads, " +
18
+ "say, put in place with the host's scripts. Before you call it, ask yourself whether there is guidance for launching " +
19
+ "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
+ "and says so. Under launch-after-pulse turri launches what each pulse lands itself: never call it for that.",
22
+ promptSnippet: "launch the regenerated code for the person to try, in the background - as the project's guidance says, or from dist/<module>",
23
+ parameters: Type.Object({
24
+ plain_file: Type.Optional(Type.String({ description: "A .plain file of the module. Default: the project's module from config.turri.yaml." })),
25
+ in_module: Type.Optional(Type.String({ description: "The codebase to take, when modules built on this one branch" })),
26
+ again: Type.Optional(Type.Boolean({ description: "Launch even when its code is out already - only when the last launch did not leave it as the person needs it, or they want it launched some other way." })),
27
+ guidance: Type.Optional(Type.String({ description: "The guidance for launching this project, whole, from wherever it is - the person, AGENTS.md, a skill: the scripts to run and in which order, where the code goes. Omit when there is none." })),
28
+ }),
29
+ async execute(_id, params, _signal, _onUpdate, ctx) {
30
+ const named = params.plain_file ?? options.defaultPlainFile();
31
+ if (named === undefined)
32
+ throw new Error("Which spec? config.turri.yaml names no module: pass plain_file.");
33
+ const plainFile = resolve(options.cwd, named);
34
+ refuseTestPlainFile(plainFile);
35
+ const chat = options.chat();
36
+ const { launch, already } = options.track.request({
37
+ plainFile,
38
+ ...(params.in_module !== undefined ? { inModule: params.in_module } : {}),
39
+ ...(params.guidance !== undefined ? { guidance: params.guidance } : {}),
40
+ ...(params.again === true ? { again: true } : {}),
41
+ cause: chat !== undefined ? { chat } : {},
42
+ });
43
+ const details = { launch: launch.id, module: launch.codebase, commit: launch.short, already };
44
+ if (already) {
45
+ 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.` }],
47
+ details,
48
+ };
49
+ }
50
+ // Where the process ends with the reply, the call waits: a launch left running would end with it.
51
+ if (ctx !== undefined && options.wait?.(ctx) === true) {
52
+ const ended = await options.track.done(launch.id);
53
+ 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
+ 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.` }],
56
+ details: { ...details, status: ended.status },
57
+ };
58
+ }
59
+ void options.track.done(launch.id).then(options.ended, () => undefined);
60
+ if (options.replaced !== undefined)
61
+ void options.track.replaced(launch.id).then((next) => options.replaced(launch, next), () => undefined);
62
+ const behind = launch.status === "waiting" ? " - after the launch of it under way" : "";
63
+ return {
64
+ content: [{ type: "text", text: `Launching ${launch.codebase} at ${launch.short} in the background (${launch.id})${behind}. You are told where it runs, or why it did not come up, once it ends: say so in a line, and start nothing for it.` }],
65
+ details,
66
+ };
67
+ },
68
+ });
69
+ }
@@ -0,0 +1,125 @@
1
+ import { type ExportedCode, type LaunchedProcess, type LaunchRecord } from "./regenerate/launch.ts";
2
+ /**
3
+ * The launch track (docs/launch.md): each codebase's launches, one at a time, the newest commit winning. A pulse that lands
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
5
+ * last: neither waits for it, and no pulse waits on it. While one runs, a newer commit asked for waits as the next, and
6
+ * replaces any older one waiting - a commit nobody will try is never launched, and the one after it holds its code.
7
+ *
8
+ * What is launched is recorded - the codebase, the commit, what it started, whether it came up - and the sentinel tests a
9
+ * pulse only in a launch whose commit holds the pulse's (`holds`).
10
+ */
11
+ export type LaunchStatus = "waiting" | "running" | "launched" | "failed" | "stopped" | "superseded";
12
+ /** Why a launch was asked for: a pulse landed, under launch-after-pulse - or a chat, or `turri launch`, asked. */
13
+ export type LaunchCause = {
14
+ pulse: string;
15
+ title: string;
16
+ } | {
17
+ chat?: string;
18
+ };
19
+ export interface Launch {
20
+ id: string;
21
+ /** The codebase: the module whose `plain_modules/<module>` holds the code. */
22
+ codebase: string;
23
+ /** `plain_modules/<module>`: its history is there. */
24
+ moduleDir: string;
25
+ plainFile: string;
26
+ inModule?: string;
27
+ /** The commit it launches, whole. */
28
+ commit: string;
29
+ short: string;
30
+ /** The host codebase a launch with guidance works in: the git repository the project is in, else where turri runs. */
31
+ hostDir: string;
32
+ /** How this project launches it, as the person or the chat said it. */
33
+ guidance?: string;
34
+ cause: LaunchCause;
35
+ status: LaunchStatus;
36
+ queuedAt: number;
37
+ startedAt?: number;
38
+ finishedAt?: number;
39
+ /** What the agent said it did - where it runs - or why it did not come up. */
40
+ summary?: string;
41
+ /** Its code, once exported. */
42
+ code?: ExportedCode;
43
+ /** When what runs for it was started: a launch that found its code out already keeps the one before it's. */
44
+ serversSince?: number;
45
+ /** It found the commit's code out already: nothing exported, stopped or started. */
46
+ already?: true;
47
+ /** Superseded while it waited: the launch that took its place. */
48
+ supersededBy?: string;
49
+ /**
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.
52
+ */
53
+ replacedBy?: string;
54
+ /** Asked for even were its code out already. */
55
+ again?: true;
56
+ }
57
+ export interface LaunchOutcome {
58
+ launched: boolean;
59
+ summary: string;
60
+ }
61
+ export interface LaunchRequest {
62
+ /** A .plain file of the codebase - its tip, or a module whose codebase it is. */
63
+ plainFile: string;
64
+ /** The codebase to take, when modules built on this one branch. */
65
+ inModule?: string;
66
+ /** The commit to launch - the one a pulse landed. Default: the codebase's last. */
67
+ commit?: string;
68
+ /** How this project launches it - kept for the codebase's launches after it. */
69
+ guidance?: string;
70
+ /** Launch even when its code is out already. */
71
+ again?: boolean;
72
+ cause: LaunchCause;
73
+ }
74
+ export interface LaunchTrack {
75
+ /**
76
+ * Ask for a launch: queued, never waited for. `already` when nothing is under way for the codebase and its code is out
77
+ * already - the same code, nothing it started ended: then nothing is done, and what runs is left.
78
+ */
79
+ request(input: LaunchRequest): {
80
+ launch: Launch;
81
+ already: boolean;
82
+ };
83
+ /** The codebase's last launch that ended - launched or failed - what runs being its. */
84
+ current(codebase: string): Launch | undefined;
85
+ /** A launch of the codebase running, or waiting. */
86
+ pending(codebase: string): Launch | undefined;
87
+ /** Resolves once nothing of the codebase's is running or waiting. */
88
+ settled(codebase: string): Promise<void>;
89
+ /**
90
+ * Resolves with the launch once it ends - or, superseded as it waited or replaced as it ended, with the one that took
91
+ * its place once that ends.
92
+ */
93
+ done(id: string): Promise<Launch>;
94
+ /**
95
+ * Resolves with the launch that takes this one's place - superseded as it waited, or ended with a newer one waiting,
96
+ * which stops what it started - as soon as it does. Never resolves for a launch nothing takes the place of.
97
+ */
98
+ 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. */
100
+ holds(codebase: string, commit: string): boolean;
101
+ /** Stop the codebase's launch under way and the one waiting - every codebase's, none named. Returns what was stopped. */
102
+ stop(codebase?: string): Promise<string[]>;
103
+ /**
104
+ * What launches started was stopped on request (`/halt launched`): the codebase's last launch - every codebase's, none
105
+ * named - that has nothing left running is stopped, nothing of it runs, and the next launch of it launches anew. Told
106
+ * as any launch's end is. Returns the launches stopped.
107
+ */
108
+ halted(codebase?: string): string[];
109
+ list(): Launch[];
110
+ /**
111
+ * Stop what launches of an earlier turri left running in the project - as a session starts. Said in the ledger, and in
112
+ * the summary of the next launch of each codebase it stopped something of. A launch does it for its codebase too.
113
+ */
114
+ sweep(): Promise<LaunchRecord[]>;
115
+ /** What the codebase's last launch started, still running. */
116
+ running(codebase: string): LaunchedProcess[];
117
+ }
118
+ export declare function createLaunchTrack(options: {
119
+ cwd: string;
120
+ /** The agent that takes exported code on and starts it. */
121
+ run: (launch: Launch, code: ExportedCode, signal: AbortSignal) => Promise<LaunchOutcome>;
122
+ onChange?: (launch: Launch) => void;
123
+ }): LaunchTrack;
124
+ /** A launch in a line: its codebase, commit, how it stands - for /halt, pulses and the panel. */
125
+ export declare function describeLaunchLine(launch: Launch): string;