@turri-dev/cli 0.2.3 → 0.2.4-next.009bd0c
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/README.md +7 -8
- package/dist/bedrock-region.js +3 -3
- package/dist/chat-idle.d.ts +2 -2
- package/dist/chat-idle.js +2 -2
- package/dist/chat-models.d.ts +1 -1
- package/dist/chat-models.js +1 -1
- package/dist/chat-scope.d.ts +1 -3
- package/dist/chat-skills.d.ts +1 -1
- package/dist/chat-skills.js +1 -1
- package/dist/chats.d.ts +44 -20
- package/dist/chats.js +125 -64
- package/dist/cli.js +12 -31
- package/dist/config-edit.d.ts +20 -8
- package/dist/config-edit.js +32 -26
- package/dist/config.d.ts +106 -78
- package/dist/config.js +267 -133
- package/dist/conform-cli.js +14 -3
- package/dist/conformance-switch.d.ts +13 -22
- package/dist/conformance-switch.js +37 -59
- package/dist/drift-cli.js +1 -1
- package/dist/extension.d.ts +17 -10
- package/dist/extension.js +425 -531
- package/dist/genome.js +10 -49
- package/dist/graph.js +3 -5
- package/dist/host-session.d.ts +11 -21
- package/dist/host-session.js +6 -8
- package/dist/host.d.ts +4 -4
- package/dist/host.js +4 -7
- package/dist/identity.js +2 -3
- package/dist/init-config.d.ts +1 -2
- package/dist/init-config.js +10 -17
- package/dist/installed-providers.d.ts +1 -1
- package/dist/installed-providers.js +1 -1
- package/dist/launch-agent.d.ts +41 -0
- package/dist/launch-agent.js +219 -0
- package/dist/{release-cli.js → launch-cli.js} +41 -24
- package/dist/launch-session.d.ts +58 -0
- package/dist/launch-session.js +195 -0
- package/dist/launch-tools.d.ts +28 -0
- package/dist/launch-tools.js +69 -0
- package/dist/launch-track.d.ts +120 -0
- package/dist/launch-track.js +298 -0
- package/dist/loop-cli.d.ts +4 -3
- package/dist/loop-cli.js +17 -15
- package/dist/loop-tools.d.ts +45 -21
- package/dist/loop-tools.js +155 -90
- package/dist/new-project.js +2 -2
- package/dist/notice.d.ts +7 -6
- package/dist/parse-cli.js +2 -2
- package/dist/pi-launch.js +4 -1
- package/dist/pi-settings.d.ts +4 -0
- package/dist/pi-settings.js +39 -0
- package/dist/pi.js +12 -9
- package/dist/plain/check.d.ts +2 -9
- package/dist/plain/check.js +6 -39
- package/dist/plain-files.d.ts +2 -2
- package/dist/plain-files.js +7 -7
- package/dist/regenerate/activity.d.ts +0 -7
- package/dist/regenerate/activity.js +2 -20
- package/dist/regenerate/agent-env.d.ts +1 -1
- package/dist/regenerate/agent-env.js +3 -3
- package/dist/regenerate/agent-shell.js +5 -3
- package/dist/regenerate/audit.js +9 -0
- package/dist/regenerate/base-folder.d.ts +2 -2
- package/dist/regenerate/base-folder.js +1 -1
- package/dist/regenerate/cases.js +7 -0
- package/dist/regenerate/chunk-plan.d.ts +5 -0
- package/dist/regenerate/chunk-plan.js +16 -1
- package/dist/regenerate/command-check.d.ts +1 -1
- package/dist/regenerate/command-check.js +1 -1
- package/dist/regenerate/delivery.d.ts +1 -1
- package/dist/regenerate/delivery.js +3 -3
- package/dist/regenerate/drift.d.ts +4 -0
- package/dist/regenerate/drift.js +26 -6
- package/dist/regenerate/failure-reports.d.ts +28 -0
- package/dist/regenerate/failure-reports.js +79 -0
- package/dist/regenerate/job-panel.js +3 -1
- package/dist/regenerate/jobs-tree.js +1 -1
- package/dist/regenerate/jobs.d.ts +4 -2
- package/dist/regenerate/jobs.js +14 -10
- package/dist/regenerate/launch.d.ts +126 -0
- package/dist/regenerate/{release.js → launch.js} +60 -48
- package/dist/regenerate/ledger-view.d.ts +11 -24
- package/dist/regenerate/ledger-view.js +14 -60
- package/dist/regenerate/ledger.d.ts +26 -16
- package/dist/regenerate/ledger.js +1 -1
- package/dist/regenerate/lineage.d.ts +2 -0
- package/dist/regenerate/lineage.js +8 -0
- package/dist/regenerate/loop.d.ts +54 -67
- package/dist/regenerate/loop.js +312 -148
- package/dist/regenerate/model-names.d.ts +33 -0
- package/dist/regenerate/{engine.js → model-names.js} +2 -28
- package/dist/regenerate/paths.d.ts +3 -3
- package/dist/regenerate/paths.js +4 -4
- package/dist/regenerate/records.d.ts +11 -0
- package/dist/regenerate/records.js +15 -0
- package/dist/regenerate/regenerate.d.ts +0 -2
- package/dist/regenerate/regenerate.js +4 -15
- package/dist/regenerate/renames.js +4 -4
- package/dist/regenerate/requires.d.ts +7 -0
- package/dist/regenerate/requires.js +24 -18
- package/dist/regenerate/scripts-being-written.d.ts +4 -4
- package/dist/regenerate/scripts-being-written.js +3 -3
- package/dist/regenerate/spec-map.js +3 -3
- package/dist/regenerate/standing.js +1 -1
- package/dist/regenerate/submit-work.d.ts +2 -0
- package/dist/regenerate/submit-work.js +8 -3
- package/dist/regenerate/test-scripts.d.ts +2 -1
- package/dist/regenerate/test-scripts.js +33 -23
- package/dist/regenerate/testing-steps.d.ts +16 -5
- package/dist/regenerate/testing-steps.js +28 -9
- package/dist/regenerate-cli.js +18 -9
- package/dist/self-invocation.d.ts +11 -0
- package/dist/self-invocation.js +36 -10
- package/dist/sentinel-check.d.ts +3 -3
- package/dist/sentinel-check.js +3 -3
- package/dist/sentinel.d.ts +17 -12
- package/dist/sentinel.js +75 -46
- package/dist/{config-command.d.ts → settings.d.ts} +13 -8
- package/dist/{config-command.js → settings.js} +155 -24
- package/dist/setup.d.ts +2 -2
- package/dist/setup.js +7 -7
- package/dist/skill.d.ts +0 -11
- package/dist/skill.js +0 -9
- package/dist/tools.js +2 -3
- package/dist/turri-versions.js +2 -1
- package/docs/README.md +4 -6
- package/docs/authoring-plain.md +3 -3
- package/docs/chats.md +6 -9
- package/docs/claude-subscription.md +2 -2
- package/docs/config.md +61 -51
- package/docs/development.md +4 -5
- package/docs/headless.md +7 -6
- package/docs/hosting.md +24 -23
- package/docs/launch.md +63 -0
- package/docs/parser.md +3 -3
- package/docs/regenerating.md +30 -22
- package/docs/sandbox.md +3 -3
- package/docs/sentinel.md +27 -16
- package/docs/skills-and-gates.md +6 -11
- package/docs/using.md +25 -42
- package/genome/rules/project-model.md +2 -1
- package/genome/rules/test-plain-files.md +15 -7
- package/genome/rules/turri-regeneration.md +7 -10
- package/genome/skills/convert-old-syntax/SKILL.md +5 -5
- package/genome/skills/implement-conformance-testing-script/SKILL.md +2 -2
- package/genome/skills/implement-unit-testing-script/SKILL.md +3 -3
- package/package.json +1 -1
- package/dist/advisor-chat.d.ts +0 -63
- package/dist/advisor-chat.js +0 -290
- package/dist/change-plain-cli.js +0 -55
- package/dist/ledger-cli.d.ts +0 -1
- package/dist/ledger-cli.js +0 -50
- package/dist/ledger-tools.d.ts +0 -10
- package/dist/ledger-tools.js +0 -64
- package/dist/regenerate/advisor-records.d.ts +0 -93
- package/dist/regenerate/advisor-records.js +0 -110
- package/dist/regenerate/advisor-runs.d.ts +0 -87
- package/dist/regenerate/advisor-runs.js +0 -327
- package/dist/regenerate/engine.d.ts +0 -52
- package/dist/regenerate/release.d.ts +0 -121
- package/dist/regenerate/test-advisor.d.ts +0 -101
- package/dist/regenerate/test-advisor.js +0 -379
- package/dist/release-agent.d.ts +0 -43
- package/dist/release-agent.js +0 -130
- package/dist/release-cli.d.ts +0 -1
- package/dist/release-tools.d.ts +0 -44
- package/dist/release-tools.js +0 -170
- package/dist/spec-tools.d.ts +0 -36
- package/dist/spec-tools.js +0 -128
- package/dist/stacks.d.ts +0 -13
- package/dist/stacks.js +0 -96
- package/docs/deploy.md +0 -48
- package/docs/test-advisor.md +0 -110
- /package/dist/{change-plain-cli.d.ts → launch-cli.d.ts} +0 -0
package/dist/regenerate/drift.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DEFAULT_CONCEPTS, extractConceptsFromDefinition, extractConceptsFromSpecText } from "../plain/concepts.js";
|
|
2
2
|
import { ACCEPTANCE_TESTS, CONFORMANCE_TESTS, DEFINITIONS, FUNCTIONAL_REQUIREMENTS, REQUIRED_FUNCTIONAL_SPECS } from "../plain/spec.js";
|
|
3
|
-
import { codeTree, conformanceTarget, marksRegenerateAgain } from "./records.js";
|
|
3
|
+
import { codeTree, conformanceTarget, marksConformAgain, marksRegenerateAgain } from "./records.js";
|
|
4
4
|
import { applyChanges, changesBetween, isMove, parseTree, resourcesChanged, serializeTree } from "./spec-steps.js";
|
|
5
5
|
/**
|
|
6
6
|
* The work, derived from the records - see docs/regenerating.md. Nothing here is stored: what is left
|
|
@@ -38,15 +38,26 @@ function scenariosIn(item) {
|
|
|
38
38
|
function codeOf(item) {
|
|
39
39
|
if (item === undefined)
|
|
40
40
|
return "";
|
|
41
|
-
const { [CONFORMANCE_TESTS]: _conformance, [ACCEPTANCE_TESTS]: _acceptance, regenerate_again: _again, ...rest } = item;
|
|
41
|
+
const { [CONFORMANCE_TESTS]: _conformance, [ACCEPTANCE_TESTS]: _acceptance, regenerate_again: _again, conform_again: _conform, ...rest } = item;
|
|
42
42
|
return JSON.stringify({ ...rest, markdown: rest.markdown.trim() });
|
|
43
43
|
}
|
|
44
|
-
/**
|
|
45
|
-
|
|
44
|
+
/**
|
|
45
|
+
* A functional spec's scenarios by case, from the item its tests were written for to the one they are to be. `anew`: its
|
|
46
|
+
* tests are written again, every scenario it has now rewritten.
|
|
47
|
+
*/
|
|
48
|
+
function scenarioCasesOf(spec, was, is, code, anew = false) {
|
|
46
49
|
const before = scenariosIn(was);
|
|
47
50
|
const after = scenariosIn(is);
|
|
48
51
|
const plain = ({ kind, id, text }) => ({ kind, id, text });
|
|
49
|
-
const cases = { ...spec, added: [], changed: [], removed: [], unchanged: [] };
|
|
52
|
+
const cases = { ...spec, added: [], changed: [], removed: [], unchanged: [], rewritten: [] };
|
|
53
|
+
if (anew) {
|
|
54
|
+
for (const scenario of after.values())
|
|
55
|
+
cases.rewritten.push(plain(scenario));
|
|
56
|
+
for (const [key, scenario] of before)
|
|
57
|
+
if (!after.has(key))
|
|
58
|
+
cases.removed.push(plain(scenario));
|
|
59
|
+
return cases;
|
|
60
|
+
}
|
|
50
61
|
for (const [key, scenario] of after) {
|
|
51
62
|
const old = before.get(key);
|
|
52
63
|
if (old === undefined)
|
|
@@ -125,6 +136,8 @@ export function casesOf(before, changes, options = {}) {
|
|
|
125
136
|
const patch = [];
|
|
126
137
|
const again = [];
|
|
127
138
|
const removed = [];
|
|
139
|
+
/** Of those regenerated again, the ones whose conformance tests are written anew: conform asked for them again. */
|
|
140
|
+
const anew = new Set();
|
|
128
141
|
/** Each functional spec touched, as the tests record has it and as it is to be: its scenarios' cases are worked out from them. */
|
|
129
142
|
const items = new Map();
|
|
130
143
|
const keyOf = (spec) => `${spec.module ?? ""}:${spec.funcId}`;
|
|
@@ -139,6 +152,13 @@ export function casesOf(before, changes, options = {}) {
|
|
|
139
152
|
const required = change.section === REQUIRED_FUNCTIONAL_SPECS;
|
|
140
153
|
const was = itemOfLine(change.before);
|
|
141
154
|
const is = itemOfLine(change.after);
|
|
155
|
+
// Its conformance tests marked to be written again: written anew, whatever else changed - its code untouched.
|
|
156
|
+
if (change.kind === "change" && is !== undefined && marksConformAgain(was)) {
|
|
157
|
+
const touched = seen(touchedOf(is, required), was, is);
|
|
158
|
+
again.push(touched);
|
|
159
|
+
anew.add(keyOf(touched));
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
142
162
|
// Marked to regenerate again: regenerated again, whatever else changed in its text - its own or, required, another module's.
|
|
143
163
|
if (change.kind === "change" && is !== undefined && marksRegenerateAgain(was)) {
|
|
144
164
|
again.push(seen(touchedOf(is, required), was, is));
|
|
@@ -199,7 +219,7 @@ export function casesOf(before, changes, options = {}) {
|
|
|
199
219
|
const { was, is } = items.get(keyOf(spec)) ?? {};
|
|
200
220
|
return scenarioCasesOf(spec, was, is, was === is ? "concept" : undefined);
|
|
201
221
|
}),
|
|
202
|
-
...again.map((spec) => scenarioCasesOf(spec, items.get(keyOf(spec))?.was, items.get(keyOf(spec))?.is, "again")),
|
|
222
|
+
...again.map((spec) => scenarioCasesOf(spec, items.get(keyOf(spec))?.was, items.get(keyOf(spec))?.is, "again", anew.has(keyOf(spec)))),
|
|
203
223
|
...removed.map((spec) => scenarioCasesOf(spec, items.get(keyOf(spec))?.was, undefined)),
|
|
204
224
|
]
|
|
205
225
|
: undefined;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Job } from "./jobs.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Why a pulse did not land, kept past its session.
|
|
4
|
+
*
|
|
5
|
+
* Outside debug mode a pulse's log and transcript go as it ends (pulse-files.ts), and the ledger keeps facts, never
|
|
6
|
+
* what a tool printed. So a pulse of an earlier session would be told as one-line facts alone - its failure's first
|
|
7
|
+
* line, its test runs' exit codes. What `pulses` says of one that did not land - its diagnosis, the stages that went
|
|
8
|
+
* wrong, the last failing test run's output, the last review that sent the work back, the tool calls that failed - is
|
|
9
|
+
* written here as it ends, whatever the debug setting, masked as the logs are: `.turri/pulses/<id>.md`. Kept while the
|
|
10
|
+
* ledger is on, and as long as the project keeps a ledger (`ledger-keep:`, 0 for none); the newest `KEPT` alone.
|
|
11
|
+
*/
|
|
12
|
+
/** The folder, in a project's `.turri`. */
|
|
13
|
+
export declare const REPORTS_DIR = "pulses";
|
|
14
|
+
/** How many reports a project keeps: the newest. */
|
|
15
|
+
export declare const KEPT = 200;
|
|
16
|
+
/** Where a project's reports are. */
|
|
17
|
+
export declare function reportsDir(project: string): string;
|
|
18
|
+
/** Whether a pulse ended without landing: failed, stopped, or finished with nothing landed. */
|
|
19
|
+
export declare function didNotLand(job: Job): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* A pulse has ended: one that failed, or finished with nothing landed, has its report written, and the oldest past
|
|
22
|
+
* `KEPT` go. A stopped one has none - the person halted it, or the ***plain moved on, and the ledger says which. Nothing
|
|
23
|
+
* while the ledger is off, or where the project keeps none. Never throws: a report that cannot be written is never a
|
|
24
|
+
* reason for the pulse to fail.
|
|
25
|
+
*/
|
|
26
|
+
export declare function keepFailureReport(project: string, job: Job): void;
|
|
27
|
+
/** A pulse's report, by its whole id - or undefined when it has none. */
|
|
28
|
+
export declare function failureReport(project: string, id: string): string | undefined;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
import { readProjectConfig } from "../config.js";
|
|
4
|
+
import { whyFailed } from "./diagnose-job.js";
|
|
5
|
+
import { DEFAULT_LEDGER_KEEP_MB, ledgerRun } from "./ledger.js";
|
|
6
|
+
import { maskSecrets } from "./masking.js";
|
|
7
|
+
import { ensureInScratch } from "./paths.js";
|
|
8
|
+
/**
|
|
9
|
+
* Why a pulse did not land, kept past its session.
|
|
10
|
+
*
|
|
11
|
+
* Outside debug mode a pulse's log and transcript go as it ends (pulse-files.ts), and the ledger keeps facts, never
|
|
12
|
+
* what a tool printed. So a pulse of an earlier session would be told as one-line facts alone - its failure's first
|
|
13
|
+
* line, its test runs' exit codes. What `pulses` says of one that did not land - its diagnosis, the stages that went
|
|
14
|
+
* wrong, the last failing test run's output, the last review that sent the work back, the tool calls that failed - is
|
|
15
|
+
* written here as it ends, whatever the debug setting, masked as the logs are: `.turri/pulses/<id>.md`. Kept while the
|
|
16
|
+
* ledger is on, and as long as the project keeps a ledger (`ledger-keep:`, 0 for none); the newest `KEPT` alone.
|
|
17
|
+
*/
|
|
18
|
+
/** The folder, in a project's `.turri`. */
|
|
19
|
+
export const REPORTS_DIR = "pulses";
|
|
20
|
+
/** How many reports a project keeps: the newest. */
|
|
21
|
+
export const KEPT = 200;
|
|
22
|
+
/** Where a project's reports are. */
|
|
23
|
+
export function reportsDir(project) {
|
|
24
|
+
return join(resolve(project), ".turri", REPORTS_DIR);
|
|
25
|
+
}
|
|
26
|
+
/** Whether a pulse ended without landing: failed, stopped, or finished with nothing landed. */
|
|
27
|
+
export function didNotLand(job) {
|
|
28
|
+
if (job.status === "failed" || job.status === "stopped")
|
|
29
|
+
return true;
|
|
30
|
+
return job.status === "succeeded" && job.details?.landed === false;
|
|
31
|
+
}
|
|
32
|
+
/** Whether the project keeps a ledger, and so its reports. */
|
|
33
|
+
function keeps(project) {
|
|
34
|
+
try {
|
|
35
|
+
return (readProjectConfig(project).ledgerKeep ?? DEFAULT_LEDGER_KEEP_MB) > 0;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A pulse has ended: one that failed, or finished with nothing landed, has its report written, and the oldest past
|
|
43
|
+
* `KEPT` go. A stopped one has none - the person halted it, or the ***plain moved on, and the ledger says which. Nothing
|
|
44
|
+
* while the ledger is off, or where the project keeps none. Never throws: a report that cannot be written is never a
|
|
45
|
+
* reason for the pulse to fail.
|
|
46
|
+
*/
|
|
47
|
+
export function keepFailureReport(project, job) {
|
|
48
|
+
if (ledgerRun() === undefined || job.status === "stopped" || !didNotLand(job) || !keeps(project))
|
|
49
|
+
return;
|
|
50
|
+
try {
|
|
51
|
+
const dir = ensureInScratch(join(resolve(project), ".turri"), reportsDir(project));
|
|
52
|
+
writeFileSync(join(dir, `${job.id}.md`), `${maskSecrets(whyFailed(job))}\n`);
|
|
53
|
+
prune(dir);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
/* kept when it can be: the ledger still has the facts */
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** The newest `KEPT` reports stay. */
|
|
60
|
+
function prune(dir) {
|
|
61
|
+
const reports = readdirSync(dir)
|
|
62
|
+
.filter((name) => name.endsWith(".md"))
|
|
63
|
+
.map((name) => ({ name, at: statSync(join(dir, name)).mtimeMs }))
|
|
64
|
+
.sort((a, b) => b.at - a.at);
|
|
65
|
+
for (const old of reports.slice(KEPT))
|
|
66
|
+
unlinkSync(join(dir, old.name));
|
|
67
|
+
}
|
|
68
|
+
/** A pulse's report, by its whole id - or undefined when it has none. */
|
|
69
|
+
export function failureReport(project, id) {
|
|
70
|
+
const file = join(reportsDir(project), `${id}.md`);
|
|
71
|
+
if (!existsSync(file))
|
|
72
|
+
return undefined;
|
|
73
|
+
try {
|
|
74
|
+
return readFileSync(file, "utf8").trimEnd();
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -227,7 +227,9 @@ export function jobPanelLines(jobs, options = {}) {
|
|
|
227
227
|
const key = options.keys ?? ((_key, text) => text);
|
|
228
228
|
lines.push(` ${key("trace", `ctrl+o to ${expanded ? "collapse" : "expand"} the trace`)} · ${key("peek", `${PANEL_KEY} to peek at regen`)}`);
|
|
229
229
|
}
|
|
230
|
-
|
|
230
|
+
// A line is one row of the screen: a newline in one - an agent's words, a command - would draw past what the renderer
|
|
231
|
+
// tracks and stay on the screen, so each part is a row of its own.
|
|
232
|
+
return lines.flatMap((line) => line.split(/\r?\n/));
|
|
231
233
|
}
|
|
232
234
|
/**
|
|
233
235
|
* The keys of the line, painted at `now`'s breath: one not pressed yet in the text's colour mixed toward the dim one, one
|
|
@@ -209,7 +209,7 @@ export function jobsTreeLines(jobs, state, width, style) {
|
|
|
209
209
|
});
|
|
210
210
|
// The ledger has more than the runs shown: where to find them.
|
|
211
211
|
if (state.open.earlier && (state.earlierMore ?? 0) > 0) {
|
|
212
|
-
lines.push(style.muted(` ${state.earlierMore} earlier run${state.earlierMore === 1 ? "" : "s"} in the ledger -
|
|
212
|
+
lines.push(style.muted(` ${state.earlierMore} earlier run${state.earlierMore === 1 ? "" : "s"} in the ledger - pulses with runs lists them`));
|
|
213
213
|
}
|
|
214
214
|
return { lines, rowStarts, rows };
|
|
215
215
|
}
|
|
@@ -46,8 +46,8 @@ export interface Job {
|
|
|
46
46
|
note?: string;
|
|
47
47
|
/** "provider/model-id" its agents run on, when known. */
|
|
48
48
|
model?: string;
|
|
49
|
-
/** The
|
|
50
|
-
|
|
49
|
+
/** The module whose config.turri.<module>.yaml it is built with, over config.turri.yaml - as worked out when it was queued. */
|
|
50
|
+
configModule?: string;
|
|
51
51
|
/** The chat it was asked for in (chat-scope.ts): the one told how it went. */
|
|
52
52
|
chat?: string;
|
|
53
53
|
status: JobStatus;
|
|
@@ -60,6 +60,8 @@ export interface Job {
|
|
|
60
60
|
planning?: {
|
|
61
61
|
since: number;
|
|
62
62
|
};
|
|
63
|
+
/** A row of the work loop's planned by a look ahead: it waits for regenerate, conform or /regenerate to start it. */
|
|
64
|
+
lookedAhead?: true;
|
|
63
65
|
/** While queued: the jobs it is waiting for. */
|
|
64
66
|
waitingOn: string[];
|
|
65
67
|
finishedAt?: number;
|
package/dist/regenerate/jobs.js
CHANGED
|
@@ -5,9 +5,10 @@ import { describeEnvironmentError, EnvironmentError, missingCredentials } from "
|
|
|
5
5
|
import { addAgentReport, describeAgents, JobStoppedError, withActivity } from "./activity.js";
|
|
6
6
|
import { projectOfLanes, startJobLog } from "./job-log.js";
|
|
7
7
|
import { firstLine, healing, record } from "./ledger.js";
|
|
8
|
-
import {
|
|
8
|
+
import { debugMode, moduleConfigFile, pinnedConfigModule, withConfigModule } from "../config.js";
|
|
9
9
|
import { currentChat } from "../chat-scope.js";
|
|
10
10
|
import { pulseEnded, pulseWrote } from "./pulse-files.js";
|
|
11
|
+
import { keepFailureReport } from "./failure-reports.js";
|
|
11
12
|
const DEFAULT_TAIL_CHARS = 4000;
|
|
12
13
|
const ACTIVITY_LINES = 10;
|
|
13
14
|
/** A long render's full transcript is kept, up to about this much text. */
|
|
@@ -57,9 +58,9 @@ export function createJobRegistry(options) {
|
|
|
57
58
|
},
|
|
58
59
|
start(input) {
|
|
59
60
|
const id = randomUUID().slice(0, 8);
|
|
60
|
-
// The
|
|
61
|
-
//
|
|
62
|
-
const
|
|
61
|
+
// The config pinned for the work that queues it, as it is queued - not as it starts: a job that waits for a slot is
|
|
62
|
+
// built with the config it was planned with, whatever the files say meanwhile.
|
|
63
|
+
const configModule = pinnedConfigModule();
|
|
63
64
|
const chat = currentChat()?.id;
|
|
64
65
|
const claimed = [...new Set(input.lanes ?? [])];
|
|
65
66
|
const blockers = [
|
|
@@ -81,7 +82,7 @@ export function createJobRegistry(options) {
|
|
|
81
82
|
...(input.diffWhere !== undefined ? { diffWhere: input.diffWhere } : {}),
|
|
82
83
|
...(input.cases !== undefined ? { cases: input.cases } : {}),
|
|
83
84
|
model: input.model,
|
|
84
|
-
...(
|
|
85
|
+
...(configModule !== undefined ? { configModule } : {}),
|
|
85
86
|
...(chat !== undefined ? { chat } : {}),
|
|
86
87
|
...(input.follows !== undefined ? { follows: input.follows } : {}),
|
|
87
88
|
status: blockers.length > 0 || (limit !== undefined && active >= limit) ? "queued" : "running",
|
|
@@ -107,7 +108,7 @@ export function createJobRegistry(options) {
|
|
|
107
108
|
...(input.pulse !== undefined ? { pulse: input.pulse } : {}),
|
|
108
109
|
...(input.title !== undefined ? { title: input.title } : {}),
|
|
109
110
|
...(input.model !== undefined ? { model: input.model } : {}),
|
|
110
|
-
...(
|
|
111
|
+
...(configModule !== undefined ? { configModule } : {}),
|
|
111
112
|
...(input.cases !== undefined ? { cases: input.cases } : {}),
|
|
112
113
|
waitingOn: blockers,
|
|
113
114
|
...(input.follows !== undefined ? { follows: input.follows } : {}),
|
|
@@ -318,9 +319,9 @@ export function createJobRegistry(options) {
|
|
|
318
319
|
// Its log is named only where it is kept: otherwise it goes as the pulse ends.
|
|
319
320
|
const named = log !== undefined && project !== undefined && debugMode(project);
|
|
320
321
|
record({ kind: "job.started", waitedMs: job.startedAt - job.queuedAt, ...(named ? { logFile: log.file } : {}) }, place);
|
|
321
|
-
// What the job's agents start runs until it ends, and no longer (withPulse) - with the
|
|
322
|
-
// with, whatever
|
|
323
|
-
return
|
|
322
|
+
// What the job's agents start runs until it ends, and no longer (withPulse) - with the config it was queued
|
|
323
|
+
// with, whatever the files say while it waits or runs.
|
|
324
|
+
return withConfigModule(configModule, () => (guarded ? runGuarded() : runOnce()));
|
|
324
325
|
})
|
|
325
326
|
.then((outcome) => {
|
|
326
327
|
// Asked to stop, it is stopped - whether its work threw as it unwound or returned what it had.
|
|
@@ -347,6 +348,9 @@ export function createJobRegistry(options) {
|
|
|
347
348
|
// What it wrote for a person goes now, outside debug mode - its log too, which nothing names from then on.
|
|
348
349
|
if (ran && project !== undefined && !pulseEnded({ job: id, project, ...(input.module !== undefined ? { module: input.module } : {}), lanes: claimed }))
|
|
349
350
|
delete finished.logFile;
|
|
351
|
+
// Why one that did not land did not, kept past the session whatever the debug setting (failure-reports.ts).
|
|
352
|
+
if (ran && project !== undefined)
|
|
353
|
+
keepFailureReport(project, finished);
|
|
350
354
|
const outcome = finished.details;
|
|
351
355
|
const stopReason = stopReasons.get(id);
|
|
352
356
|
record({
|
|
@@ -475,7 +479,7 @@ export function pulseName(job) {
|
|
|
475
479
|
}
|
|
476
480
|
/** What the agent is told when it checks on a job. */
|
|
477
481
|
export function describeJob(job) {
|
|
478
|
-
const name = `${pulseName(job)}${job.
|
|
482
|
+
const name = `${pulseName(job)}${job.configModule !== undefined ? ` (built with ${moduleConfigFile(job.configModule)})` : ""}`;
|
|
479
483
|
if (job.status === "queued") {
|
|
480
484
|
return `${name}: queued behind ${job.waitingOn.map((id) => `pulse ${id}`).join(" and ")}. It starts when that finishes.`;
|
|
481
485
|
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { type ChainEntry } from "./requires.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Launch: a codebase's code, as one of its commits has it, put out in `dist/<module>` for the person and the sentinel
|
|
4
|
+
* to try - the commit a pulse landed, or the codebase's last.
|
|
5
|
+
*
|
|
6
|
+
* A pulse works in `plain_modules/<module>/code` while a launch runs, so what is there is half-written. A commit is not:
|
|
7
|
+
* every unit of work starts from one and ends with one, and both are runnable. So the commit is exported from the
|
|
8
|
+
* module's history - git's own list of what it tracks, and nothing else - without a list of what each stack leaves lying
|
|
9
|
+
* around (`node_modules`, `.venv`, `target`). The working tree is never read, reset or touched: the next pulse may be
|
|
10
|
+
* writing in it.
|
|
11
|
+
*
|
|
12
|
+
* What starts it runs here, on the person's machine, unfenced: a server the person opens in their browser, with their
|
|
13
|
+
* toolchains. The launch agent installs and runs what it needs itself, as any agent with a shell would - nothing is put to
|
|
14
|
+
* the person - and everything started is the harness's to stop: on the next launch, on /halt, and when turri exits.
|
|
15
|
+
*/
|
|
16
|
+
/** A codebase's code at a commit, exported - what a launch takes on from. */
|
|
17
|
+
export interface ExportedCode {
|
|
18
|
+
/** The codebase: the module whose `plain_modules/<module>` holds the code. */
|
|
19
|
+
moduleName: string;
|
|
20
|
+
plainFile: string;
|
|
21
|
+
/** `dist/<module>`, in the project: the commit's code. */
|
|
22
|
+
dir: string;
|
|
23
|
+
/** Where the module's code is built: `plain_modules/<module>/code`. */
|
|
24
|
+
buildDir: string;
|
|
25
|
+
/** The commit, whole. */
|
|
26
|
+
commit: string;
|
|
27
|
+
/** The commit, short - as the person and the agents are told it. */
|
|
28
|
+
short: string;
|
|
29
|
+
/** The commit's subject: what the unit of work that landed it did. */
|
|
30
|
+
subject: string;
|
|
31
|
+
/** When, as git says it: "3 minutes ago". */
|
|
32
|
+
when: string;
|
|
33
|
+
/** Work under way in the module - changes nobody committed yet - left out. */
|
|
34
|
+
unfinished: boolean;
|
|
35
|
+
/** The module the spec's code lives in had nothing committed yet: the nearest one below it that had, instead. */
|
|
36
|
+
instead?: string;
|
|
37
|
+
}
|
|
38
|
+
/** The tree of a commit's code: two commits with the same one hold the same code - one landed only tests, say. */
|
|
39
|
+
export declare function codeTreeOf(moduleDir: string, commit: string): string | undefined;
|
|
40
|
+
/** Whether `commit` holds `ancestor`: the same commit, or one built on it. */
|
|
41
|
+
export declare function holdsCommit(moduleDir: string, ancestor: string, commit: string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Which codebase to launch for a spec, and at which commit: the tip of its codebase - code accumulates up a requires
|
|
44
|
+
* chain, so the top module holds everything below it - at `commit`, or its last. Before the tip has anything committed,
|
|
45
|
+
* the nearest module below it that has.
|
|
46
|
+
*/
|
|
47
|
+
export declare function launchTarget(plainFile: string, options?: {
|
|
48
|
+
inModule?: string;
|
|
49
|
+
commit?: string;
|
|
50
|
+
}): {
|
|
51
|
+
entry: ChainEntry;
|
|
52
|
+
commit: string;
|
|
53
|
+
instead?: string;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Export a codebase's code at a commit - its last, unless `commit` names one - into `dist/<module>`, or `into`
|
|
57
|
+
* (`turri regenerate --build-dir`), replacing whatever was there, the harness's own files (what the code is built from,
|
|
58
|
+
* the agents' notes) left out.
|
|
59
|
+
*/
|
|
60
|
+
export declare function exportModule(plainFile: string, options?: {
|
|
61
|
+
inModule?: string;
|
|
62
|
+
into?: string;
|
|
63
|
+
commit?: string;
|
|
64
|
+
}): ExportedCode;
|
|
65
|
+
/**
|
|
66
|
+
* The host codebase a launch with guidance works in: the git repository the project is in - an embedded project's host -
|
|
67
|
+
* or else `fallback`, where turri runs.
|
|
68
|
+
*/
|
|
69
|
+
export declare function hostDirOf(plainFile: string, fallback: string): string;
|
|
70
|
+
/** Where a path is, said from the current directory when it is below it. */
|
|
71
|
+
export declare function shortPath(path: string): string;
|
|
72
|
+
/** What was exported, in a line or three. */
|
|
73
|
+
export declare function describeExport(code: ExportedCode): string;
|
|
74
|
+
export interface LaunchedProcess {
|
|
75
|
+
name: string;
|
|
76
|
+
moduleName: string;
|
|
77
|
+
command: string;
|
|
78
|
+
/** Where it runs. */
|
|
79
|
+
dir: string;
|
|
80
|
+
url?: string;
|
|
81
|
+
/** Its output, both streams. */
|
|
82
|
+
log: string;
|
|
83
|
+
pid: number;
|
|
84
|
+
startedAt: number;
|
|
85
|
+
/** Set once it has ended. */
|
|
86
|
+
exited?: {
|
|
87
|
+
code: number | null;
|
|
88
|
+
signal: string | null;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/** Everything a launch started, running or ended, oldest first. */
|
|
92
|
+
export declare function listLaunched(): LaunchedProcess[];
|
|
93
|
+
/** The ones still running. */
|
|
94
|
+
export declare function runningLaunched(moduleName?: string): LaunchedProcess[];
|
|
95
|
+
/** Where what a project's launches started write their output: its scratch, not the code in dist. */
|
|
96
|
+
export declare function launchLogDir(projectDir: string): string;
|
|
97
|
+
/** The end of a log, for when something did not come up. */
|
|
98
|
+
export declare function logTail(log: string, lines?: number, chars?: number): string;
|
|
99
|
+
/** Stop one launched process, or every one of a module, or every one: politely, then not. Returns the names stopped. */
|
|
100
|
+
export declare function stopLaunched(which?: {
|
|
101
|
+
name?: string;
|
|
102
|
+
moduleName?: string;
|
|
103
|
+
}): Promise<string[]>;
|
|
104
|
+
/** Stop everything at once, without waiting: for when turri itself is going. */
|
|
105
|
+
export declare function stopAllLaunchedNow(): void;
|
|
106
|
+
/** How long a server is given to answer at its URL, and to stay up when it has none. */
|
|
107
|
+
export declare const READY_TIMEOUT_MS: number;
|
|
108
|
+
export interface StartResult {
|
|
109
|
+
ok: boolean;
|
|
110
|
+
/** What happened, for the agent and the person. */
|
|
111
|
+
text: string;
|
|
112
|
+
process?: LaunchedProcess;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Start what keeps running, in `dir` - the folder `root` it is named from, or one inside it. A folder that is not there
|
|
116
|
+
* starts nothing: said, with what `root` holds, so the agent can name the right one.
|
|
117
|
+
*/
|
|
118
|
+
export declare function startLaunched(input: {
|
|
119
|
+
name: string;
|
|
120
|
+
command: string;
|
|
121
|
+
dir: string;
|
|
122
|
+
moduleName: string;
|
|
123
|
+
logDir: string;
|
|
124
|
+
url?: string;
|
|
125
|
+
root?: string;
|
|
126
|
+
}): Promise<StartResult>;
|
|
@@ -10,41 +10,58 @@ import { RECORD_FILE } from "./paths.js";
|
|
|
10
10
|
function git(moduleDir, args) {
|
|
11
11
|
return spawnSync("git", ["--git-dir", join(moduleDir, HISTORY_DIR), "--work-tree", moduleDir, ...args], { cwd: moduleDir, encoding: "utf8" });
|
|
12
12
|
}
|
|
13
|
-
/**
|
|
14
|
-
function committedCode(moduleDir) {
|
|
13
|
+
/** A commit of the module's history, whole - `HEAD` its last - when it has one with code in it. */
|
|
14
|
+
function committedCode(moduleDir, commit = "HEAD") {
|
|
15
15
|
if (!existsSync(join(moduleDir, HISTORY_DIR)))
|
|
16
16
|
return undefined;
|
|
17
|
-
const
|
|
18
|
-
if (
|
|
17
|
+
const found = git(moduleDir, ["rev-parse", "--verify", "--quiet", `${commit}^{commit}`]);
|
|
18
|
+
if (found.status !== 0)
|
|
19
19
|
return undefined;
|
|
20
|
+
const whole = found.stdout.trim();
|
|
20
21
|
// A commit with no code folder in it has nothing to run.
|
|
21
|
-
if (git(moduleDir, ["rev-parse", "--verify", "--quiet",
|
|
22
|
+
if (git(moduleDir, ["rev-parse", "--verify", "--quiet", `${whole}:code`]).status !== 0)
|
|
22
23
|
return undefined;
|
|
23
|
-
return
|
|
24
|
+
return whole;
|
|
25
|
+
}
|
|
26
|
+
/** The tree of a commit's code: two commits with the same one hold the same code - one landed only tests, say. */
|
|
27
|
+
export function codeTreeOf(moduleDir, commit) {
|
|
28
|
+
const tree = git(moduleDir, ["rev-parse", "--verify", "--quiet", `${commit}:code`]);
|
|
29
|
+
return tree.status === 0 ? tree.stdout.trim() : undefined;
|
|
30
|
+
}
|
|
31
|
+
/** Whether `commit` holds `ancestor`: the same commit, or one built on it. */
|
|
32
|
+
export function holdsCommit(moduleDir, ancestor, commit) {
|
|
33
|
+
return git(moduleDir, ["merge-base", "--is-ancestor", ancestor, commit]).status === 0;
|
|
24
34
|
}
|
|
25
35
|
/**
|
|
26
|
-
* Which
|
|
27
|
-
* the top module holds everything below it. Before the tip has anything committed,
|
|
28
|
-
* below it that has.
|
|
36
|
+
* Which codebase to launch for a spec, and at which commit: the tip of its codebase - code accumulates up a requires
|
|
37
|
+
* chain, so the top module holds everything below it - at `commit`, or its last. Before the tip has anything committed,
|
|
38
|
+
* the nearest module below it that has.
|
|
29
39
|
*/
|
|
30
|
-
export function
|
|
31
|
-
const { tip, chain } = findCodebaseTip(plainFile, { allowNoFunctionalities: true, ...(inModule !== undefined ? { inModule } : {}) });
|
|
40
|
+
export function launchTarget(plainFile, options = {}) {
|
|
41
|
+
const { tip, chain } = findCodebaseTip(plainFile, { allowNoFunctionalities: true, ...(options.inModule !== undefined ? { inModule: options.inModule } : {}) });
|
|
42
|
+
if (options.commit !== undefined) {
|
|
43
|
+
const commit = committedCode(dirname(tip.buildDir), options.commit);
|
|
44
|
+
if (commit === undefined)
|
|
45
|
+
throw new Error(`${tip.moduleName} has no commit ${options.commit} with code in it: nothing to launch.`);
|
|
46
|
+
return { entry: tip, commit };
|
|
47
|
+
}
|
|
32
48
|
const candidates = [tip, ...[...chain].reverse().filter((entry) => entry.moduleName !== tip.moduleName)];
|
|
33
49
|
for (const entry of candidates) {
|
|
34
50
|
const commit = committedCode(dirname(entry.buildDir));
|
|
35
51
|
if (commit !== undefined)
|
|
36
52
|
return { entry, commit, ...(entry.moduleName !== tip.moduleName ? { instead: tip.moduleName } : {}) };
|
|
37
53
|
}
|
|
38
|
-
throw new Error(`Nothing is built yet for ${tip.moduleName}${candidates.length > 1 ? " or the modules it requires" : ""}: there is no code to
|
|
54
|
+
throw new Error(`Nothing is built yet for ${tip.moduleName}${candidates.length > 1 ? " or the modules it requires" : ""}: there is no code to launch. Regenerate it first.`);
|
|
39
55
|
}
|
|
40
56
|
/**
|
|
41
|
-
* Export
|
|
42
|
-
* replacing whatever was there, the harness's own files (what the code is built from,
|
|
57
|
+
* Export a codebase's code at a commit - its last, unless `commit` names one - into `dist/<module>`, or `into`
|
|
58
|
+
* (`turri regenerate --build-dir`), replacing whatever was there, the harness's own files (what the code is built from,
|
|
59
|
+
* the agents' notes) left out.
|
|
43
60
|
*/
|
|
44
|
-
export function exportModule(plainFile,
|
|
45
|
-
const { entry, commit, instead } =
|
|
61
|
+
export function exportModule(plainFile, options = {}) {
|
|
62
|
+
const { entry, commit, instead } = launchTarget(plainFile, options);
|
|
46
63
|
const moduleDir = dirname(entry.buildDir);
|
|
47
|
-
const dir = into ?? distDirFor(projectDirOf(entry.plainFile), entry.moduleName);
|
|
64
|
+
const dir = options.into ?? distDirFor(projectDirOf(entry.plainFile), entry.moduleName);
|
|
48
65
|
// Emptied, not removed: the folder may be a mount point - a container's volume - that cannot be removed.
|
|
49
66
|
mkdirSync(dir, { recursive: true });
|
|
50
67
|
for (const entry of readdirSync(dir))
|
|
@@ -59,10 +76,10 @@ export function exportModule(plainFile, inModule, into) {
|
|
|
59
76
|
return {
|
|
60
77
|
moduleName: entry.moduleName,
|
|
61
78
|
plainFile: entry.plainFile,
|
|
62
|
-
way: "dist",
|
|
63
79
|
dir,
|
|
64
80
|
buildDir: entry.buildDir,
|
|
65
|
-
commit
|
|
81
|
+
commit,
|
|
82
|
+
short: short ?? commit.slice(0, 8),
|
|
66
83
|
subject: subject ?? "",
|
|
67
84
|
when: when ?? "",
|
|
68
85
|
unfinished,
|
|
@@ -70,7 +87,7 @@ export function exportModule(plainFile, inModule, into) {
|
|
|
70
87
|
};
|
|
71
88
|
}
|
|
72
89
|
/**
|
|
73
|
-
* The host codebase a
|
|
90
|
+
* The host codebase a launch with guidance works in: the git repository the project is in - an embedded project's host -
|
|
74
91
|
* or else `fallback`, where turri runs.
|
|
75
92
|
*/
|
|
76
93
|
export function hostDirOf(plainFile, fallback) {
|
|
@@ -82,34 +99,29 @@ export function shortPath(path) {
|
|
|
82
99
|
const fromHere = relative(process.cwd(), path);
|
|
83
100
|
return fromHere === "" || fromHere.startsWith("..") ? path : fromHere;
|
|
84
101
|
}
|
|
85
|
-
/** What was
|
|
86
|
-
export function
|
|
102
|
+
/** What was exported, in a line or three. */
|
|
103
|
+
export function describeExport(code) {
|
|
87
104
|
return [
|
|
88
|
-
|
|
89
|
-
...(
|
|
90
|
-
...(
|
|
91
|
-
|
|
92
|
-
? [
|
|
93
|
-
deployment.hostDir === undefined
|
|
94
|
-
? "A pulse is at work on the module right now: what it has written so far is not finished, and is left out."
|
|
95
|
-
: `A pulse is at work on the module right now: what it has written so far is not finished, and is left out of ${shortPath(deployment.dir)} - but ${shortPath(deployment.buildDir)} holds it, so take the code from ${shortPath(deployment.dir)}, never from there.`,
|
|
96
|
-
]
|
|
105
|
+
`${code.moduleName}'s code at commit ${code.short} (${code.when}: ${code.subject}) is in ${shortPath(code.dir)}.`,
|
|
106
|
+
...(code.instead !== undefined ? [`${code.instead}, the module on top, has nothing built yet - this is ${code.moduleName}, the module below it.`] : []),
|
|
107
|
+
...(code.unfinished
|
|
108
|
+
? [`A pulse is at work on the module right now: what it has written so far is not finished, and is left out of ${shortPath(code.dir)} - ${shortPath(code.buildDir)} holds it, so take the code from ${shortPath(code.dir)}, never from there.`]
|
|
97
109
|
: []),
|
|
98
110
|
].join("\n");
|
|
99
111
|
}
|
|
100
112
|
const processes = new Map();
|
|
101
|
-
/** Everything
|
|
102
|
-
export function
|
|
113
|
+
/** Everything a launch started, running or ended, oldest first. */
|
|
114
|
+
export function listLaunched() {
|
|
103
115
|
return [...processes.values()].map((entry) => entry.info);
|
|
104
116
|
}
|
|
105
117
|
/** The ones still running. */
|
|
106
|
-
export function
|
|
107
|
-
return
|
|
118
|
+
export function runningLaunched(moduleName) {
|
|
119
|
+
return listLaunched().filter((info) => info.exited === undefined && (moduleName === undefined || info.moduleName === moduleName));
|
|
108
120
|
}
|
|
109
|
-
/** Where a project's
|
|
110
|
-
export function
|
|
121
|
+
/** Where what a project's launches started write their output: its scratch, not the code in dist. */
|
|
122
|
+
export function launchLogDir(projectDir) {
|
|
111
123
|
const scratch = join(projectDir, ".turri");
|
|
112
|
-
return ensureInScratch(scratch, join(scratch, "
|
|
124
|
+
return ensureInScratch(scratch, join(scratch, "launch"));
|
|
113
125
|
}
|
|
114
126
|
/** The end of a log, for when something did not come up. */
|
|
115
127
|
export function logTail(log, lines = 40, chars = 4000) {
|
|
@@ -136,8 +148,8 @@ function signalGroup(pid, signal) {
|
|
|
136
148
|
}
|
|
137
149
|
}
|
|
138
150
|
const sleep = (ms) => new Promise((done) => setTimeout(done, ms));
|
|
139
|
-
/** Stop one
|
|
140
|
-
export async function
|
|
151
|
+
/** Stop one launched process, or every one of a module, or every one: politely, then not. Returns the names stopped. */
|
|
152
|
+
export async function stopLaunched(which = {}) {
|
|
141
153
|
const targets = [...processes.values()].filter(({ info }) => info.exited === undefined && (which.name === undefined || info.name === which.name) && (which.moduleName === undefined || info.moduleName === which.moduleName));
|
|
142
154
|
for (const { info } of targets)
|
|
143
155
|
signalGroup(info.pid, "SIGTERM");
|
|
@@ -150,7 +162,7 @@ export async function stopDeployed(which = {}) {
|
|
|
150
162
|
return targets.map(({ info }) => info.name);
|
|
151
163
|
}
|
|
152
164
|
/** Stop everything at once, without waiting: for when turri itself is going. */
|
|
153
|
-
export function
|
|
165
|
+
export function stopAllLaunchedNow() {
|
|
154
166
|
for (const { info } of processes.values())
|
|
155
167
|
if (info.exited === undefined)
|
|
156
168
|
signalGroup(info.pid, "SIGTERM");
|
|
@@ -160,7 +172,7 @@ function stopOnExit() {
|
|
|
160
172
|
if (exitHooked)
|
|
161
173
|
return;
|
|
162
174
|
exitHooked = true;
|
|
163
|
-
process.on("exit",
|
|
175
|
+
process.on("exit", stopAllLaunchedNow);
|
|
164
176
|
}
|
|
165
177
|
function portOf(url) {
|
|
166
178
|
if (url.port !== "")
|
|
@@ -195,7 +207,7 @@ async function answers(url) {
|
|
|
195
207
|
}
|
|
196
208
|
}
|
|
197
209
|
/** How long a server is given to answer at its URL, and to stay up when it has none. */
|
|
198
|
-
export const READY_TIMEOUT_MS = Number(process.env.
|
|
210
|
+
export const READY_TIMEOUT_MS = Number(process.env.TURRI_LAUNCH_READY_TIMEOUT ?? 60) * 1000;
|
|
199
211
|
const ALIVE_AFTER_MS = 4000;
|
|
200
212
|
/**
|
|
201
213
|
* Start something that keeps running - a server, a frontend's dev server - in `dir`, on this machine,
|
|
@@ -219,10 +231,10 @@ function listing(dir) {
|
|
|
219
231
|
}
|
|
220
232
|
}
|
|
221
233
|
/**
|
|
222
|
-
* Start what keeps running, in `dir` - the
|
|
223
|
-
* nothing: said, with what
|
|
234
|
+
* Start what keeps running, in `dir` - the folder `root` it is named from, or one inside it. A folder that is not there
|
|
235
|
+
* starts nothing: said, with what `root` holds, so the agent can name the right one.
|
|
224
236
|
*/
|
|
225
|
-
export async function
|
|
237
|
+
export async function startLaunched(input) {
|
|
226
238
|
let isFolder = false;
|
|
227
239
|
try {
|
|
228
240
|
isFolder = statSync(input.dir).isDirectory();
|
|
@@ -235,11 +247,11 @@ export async function startDeployed(input) {
|
|
|
235
247
|
return {
|
|
236
248
|
ok: false,
|
|
237
249
|
text: input.root !== undefined
|
|
238
|
-
? `${input.name} was not started: ${shortPath(input.dir)} ${why}. \`dir\` is relative to
|
|
250
|
+
? `${input.name} was not started: ${shortPath(input.dir)} ${why}. \`dir\` is relative to ${shortPath(input.root)} - a folder inside it, e.g. frontend, or none for the folder itself; never the project's path to it. ${shortPath(input.root)} holds: ${listing(input.root)}.`
|
|
239
251
|
: `${input.name} was not started: ${shortPath(input.dir)} ${why}.`,
|
|
240
252
|
};
|
|
241
253
|
}
|
|
242
|
-
await
|
|
254
|
+
await stopLaunched({ name: input.name });
|
|
243
255
|
let url;
|
|
244
256
|
if (input.url !== undefined) {
|
|
245
257
|
try {
|