@turri-dev/cli 0.4.2-next.a6867e8 → 0.4.3-next.aea3ca1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chat-terminal.js +7 -7
- package/dist/chat-waiting.d.ts +4 -1
- package/dist/chat-waiting.js +7 -4
- package/dist/chats.d.ts +1 -1
- package/dist/chats.js +1 -1
- package/dist/extension.js +66 -84
- package/dist/identity.js +1 -1
- package/dist/loop-tools.d.ts +2 -3
- package/dist/loop-tools.js +7 -12
- package/dist/regenerate/chunk-plan.d.ts +2 -11
- package/dist/regenerate/chunk-plan.js +9 -20
- package/dist/regenerate/command-check.d.ts +9 -0
- package/dist/regenerate/command-check.js +83 -3
- package/dist/regenerate/loop.d.ts +6 -14
- package/dist/regenerate/loop.js +42 -34
- package/dist/regenerate/test-scripts.d.ts +3 -0
- package/dist/regenerate/test-scripts.js +16 -5
- package/dist/resume-line.d.ts +4 -1
- package/dist/resume-line.js +5 -2
- package/dist/sentinel.js +1 -1
- package/docs/chats.md +0 -1
- package/docs/config.md +2 -0
- package/docs/regenerating.md +8 -7
- package/docs/sandbox.md +2 -0
- package/docs/skills-and-gates.md +1 -1
- package/docs/using.md +2 -3
- package/genome/rules/turri-regeneration.md +1 -1
- package/package.json +3 -3
- package/dist/regenerate/steer.d.ts +0 -34
- package/dist/regenerate/steer.js +0 -91
|
@@ -5,7 +5,6 @@ import { ACCEPTANCE_TESTS, CONFORMANCE_TESTS, DEFINITIONS, FUNCTIONAL_REQUIREMEN
|
|
|
5
5
|
import { ask, BEGIN, createExecutor } from "../pi.js";
|
|
6
6
|
import { reportActivity, reportStage } from "./activity.js";
|
|
7
7
|
import { firstLine, record } from "./ledger.js";
|
|
8
|
-
import { steeringBlock } from "./steer.js";
|
|
9
8
|
import { marksRegenerateAgain } from "./records.js";
|
|
10
9
|
import { validateConcepts } from "../plain/concepts.js";
|
|
11
10
|
import { applyChanges, changesBetween, inconsistencies, layoutOf, makeStep, parseTree, serializeTree } from "./spec-steps.js";
|
|
@@ -384,9 +383,9 @@ function titleChangeOf(change) {
|
|
|
384
383
|
}
|
|
385
384
|
/**
|
|
386
385
|
* Cut the queue's work - from `input.base` to `input.current` - into jobs, as the three steps say. Returns the draft
|
|
387
|
-
* the work loop runs: checked (checkDraft), or, when nothing holds, the whole work as one job. `notes` is given
|
|
388
|
-
* the plan
|
|
389
|
-
*
|
|
386
|
+
* the work loop runs: checked (checkDraft), or, when nothing holds, the whole work as one job. `notes` is given where
|
|
387
|
+
* the plan fell back - an answer that was not given or did not hold, a group split for its size - for the conversation
|
|
388
|
+
* to say, rather than guess.
|
|
390
389
|
*/
|
|
391
390
|
/** A planner agent that failed: the plan falls back, and the ledger says why. */
|
|
392
391
|
function plannerFailed(step, error) {
|
|
@@ -495,7 +494,7 @@ function funcIdOf(change) {
|
|
|
495
494
|
async function cut(input, agents, notes) {
|
|
496
495
|
// How big a pulse may be: the config's, else the defaults.
|
|
497
496
|
const { specs: maxSpecs, lines: maxLines } = input.limits ?? { specs: MAX_SPECS_PER_JOB, lines: MAX_LINES_PER_JOB };
|
|
498
|
-
/**
|
|
497
|
+
/** Where the plan fell back: in the activity, and in the notes. */
|
|
499
498
|
const say = (text) => {
|
|
500
499
|
reportActivity(` ${text}`);
|
|
501
500
|
notes?.push(text);
|
|
@@ -598,7 +597,7 @@ async function cut(input, agents, notes) {
|
|
|
598
597
|
say(answer === undefined ? "the titles were not given - each pulse titled by its functional specs' first lines" : `the titles did not hold (${problems.join(" ")}) - each pulse titled by its functional specs' first lines`);
|
|
599
598
|
return list;
|
|
600
599
|
};
|
|
601
|
-
const grouped = conformance ? undefined : ((await agents?.group(numbered, (answer) => groupProblems(numbered, answer, maxSpecs, builtShown),
|
|
600
|
+
const grouped = conformance ? undefined : ((await agents?.group(numbered, (answer) => groupProblems(numbered, answer, maxSpecs, builtShown), maxSpecs, builtShown.length > 0 ? builtShown : undefined).catch((error) => plannerFailed("group", error))) ?? undefined);
|
|
602
601
|
const holds = grouped !== undefined && groupProblems(numbered, grouped, maxSpecs, builtShown).length === 0;
|
|
603
602
|
// The grouping holds: each change to what is built goes where it was placed.
|
|
604
603
|
if (holds) {
|
|
@@ -617,8 +616,6 @@ async function cut(input, agents, notes) {
|
|
|
617
616
|
: grouped !== undefined && holds
|
|
618
617
|
? grouped.groups
|
|
619
618
|
: numbered.map((spec, index) => ({ specs: [spec.number], title: titleOf(specs[index]) }));
|
|
620
|
-
if (grouped?.notes !== undefined && grouped.notes.trim() !== "")
|
|
621
|
-
say(`the grouping: ${grouped.notes.trim()}`);
|
|
622
619
|
if (!conformance && agents !== undefined) {
|
|
623
620
|
if (grouped === undefined) {
|
|
624
621
|
record({ kind: "planner.fellBack", step: "group", why: "no grouping was given" });
|
|
@@ -641,15 +638,12 @@ async function cut(input, agents, notes) {
|
|
|
641
638
|
if (implementationReqs.length + testReqs.length > 0) {
|
|
642
639
|
reportStage(`planning the queue: where each of ${implementationReqs.length + testReqs.length} new req${implementationReqs.length + testReqs.length === 1 ? "" : "s"} goes`);
|
|
643
640
|
const placeInput = {
|
|
644
|
-
...(input.steering !== undefined ? { steering: input.steering } : {}),
|
|
645
641
|
groups: newChunks().map((chunk, index) => ({ number: index + 1, title: chunk.title, specs: chunk.specs.map(textOf), definitions: chunk.definitions.map(textOf) })),
|
|
646
642
|
built: chunks.some((chunk) => chunk.built !== undefined),
|
|
647
643
|
implementationReqs: implementationReqs.map((change, index) => ({ number: index + 1, text: textOf(change) })),
|
|
648
644
|
testReqs: testReqs.map((change, index) => ({ number: index + 1, text: textOf(change) })),
|
|
649
645
|
};
|
|
650
646
|
const answer = (await planners?.place(placeInput, (given) => placeProblems(placeInput, given)).catch((error) => plannerFailed("place", error))) ?? undefined;
|
|
651
|
-
if (answer?.notes !== undefined && answer.notes.trim() !== "")
|
|
652
|
-
say(`the placement: ${answer.notes.trim()}`);
|
|
653
647
|
placement = answer !== undefined && placeProblems(placeInput, answer).length === 0 ? answer : undefined;
|
|
654
648
|
if (placement === undefined && planners !== undefined)
|
|
655
649
|
record({ kind: "planner.fellBack", step: "place", why: answer === undefined ? "no placement was given" : firstLine(placeProblems(placeInput, answer).join(" "), 300) });
|
|
@@ -741,7 +735,7 @@ async function cut(input, agents, notes) {
|
|
|
741
735
|
}
|
|
742
736
|
// ---------------------------------------------------------------------------------------------
|
|
743
737
|
// The agents.
|
|
744
|
-
export function groupPrompt(specs,
|
|
738
|
+
export function groupPrompt(specs, maxSpecs = MAX_SPECS_PER_JOB, built = []) {
|
|
745
739
|
return [
|
|
746
740
|
"You plan how new work on a codebase is built: which of its new functional specs are built together, in one job.",
|
|
747
741
|
"",
|
|
@@ -760,7 +754,6 @@ export function groupPrompt(specs, steering, maxSpecs = MAX_SPECS_PER_JOB, built
|
|
|
760
754
|
"The specification is split into modules - a ***plain matter, not how the code is laid out. A functional spec has a",
|
|
761
755
|
"func-id, unique in its module: each below is given with its module, its func-id, its place among the module's functional specs, and a number of its own to answer with.",
|
|
762
756
|
"",
|
|
763
|
-
...steeringBlock(steering),
|
|
764
757
|
...(specs.some((spec) => spec.again === true)
|
|
765
758
|
? [
|
|
766
759
|
"Those marked again=\"true\" are built already, and are regenerated again - rewritten, doing what they say. Group them as",
|
|
@@ -804,7 +797,6 @@ export function placePrompt(input) {
|
|
|
804
797
|
"- A test req goes with the first group whose conformance tests need it; one about all the tests to \"all\".",
|
|
805
798
|
...(input.built ? ['- "built" is the job that changes what is built already, and goes first: a req about the code there already goes there.'] : []),
|
|
806
799
|
"",
|
|
807
|
-
...steeringBlock(input.steering),
|
|
808
800
|
...input.groups.map((group) => [
|
|
809
801
|
// A title that is only its first spec's first line is not said twice.
|
|
810
802
|
group.specs[0] !== undefined && group.specs[0].includes(group.title.trim().replace(/\.$/, "")) ? `<group number="${group.number}">` : `<group number="${group.number}" title="${group.title}">`,
|
|
@@ -852,7 +844,6 @@ export function titlePrompt(groups, track) {
|
|
|
852
844
|
].join("\n");
|
|
853
845
|
}
|
|
854
846
|
const TargetSchema = Type.Union([Type.Number(), Type.Literal("all"), Type.Literal("built")]);
|
|
855
|
-
const NOTES = "Each of the person's wishes for how the queue is planned that you did not follow, and why - a limit it would break, say. Leave it out when you followed them all, or there are none.";
|
|
856
847
|
/** Ask one step of an agent, and ask again with what was wrong, until it holds or the retries are spent. */
|
|
857
848
|
async function askStep(options) {
|
|
858
849
|
let answer;
|
|
@@ -877,11 +868,11 @@ async function askStep(options) {
|
|
|
877
868
|
export function llmChunkAgents(options) {
|
|
878
869
|
const label = options.label ?? "queue planner";
|
|
879
870
|
return {
|
|
880
|
-
group: (specs, check,
|
|
871
|
+
group: (specs, check, maxSpecs, built) => askStep({
|
|
881
872
|
cwd: options.cwd,
|
|
882
873
|
model: options.model,
|
|
883
874
|
label: `${label} grouping`,
|
|
884
|
-
task: groupPrompt(specs,
|
|
875
|
+
task: groupPrompt(specs, maxSpecs, built),
|
|
885
876
|
check,
|
|
886
877
|
tool: (take) => defineTool({
|
|
887
878
|
name: "submit_groups",
|
|
@@ -892,7 +883,6 @@ export function llmChunkAgents(options) {
|
|
|
892
883
|
built: Type.Optional(Type.Array(Type.Object({ change: Type.Number(), to: Type.Union([Type.Number(), Type.Literal("first")]) }), {
|
|
893
884
|
description: 'Where each change to what is built goes: with a group, by its number, or "first" - a pulse of its own, before the new work.',
|
|
894
885
|
})),
|
|
895
|
-
notes: Type.Optional(Type.String({ description: NOTES })),
|
|
896
886
|
}),
|
|
897
887
|
async execute(_id, params) {
|
|
898
888
|
take(params);
|
|
@@ -913,11 +903,10 @@ export function llmChunkAgents(options) {
|
|
|
913
903
|
parameters: Type.Object({
|
|
914
904
|
implementation_reqs: Type.Array(Type.Object({ req: Type.Number(), to: TargetSchema })),
|
|
915
905
|
test_reqs: Type.Array(Type.Object({ req: Type.Number(), to: TargetSchema })),
|
|
916
|
-
notes: Type.Optional(Type.String({ description: NOTES })),
|
|
917
906
|
}),
|
|
918
907
|
async execute(_id, params) {
|
|
919
908
|
const given = params;
|
|
920
|
-
take({ implementationReqs: given.implementation_reqs, testReqs: given.test_reqs
|
|
909
|
+
take({ implementationReqs: given.implementation_reqs, testReqs: given.test_reqs });
|
|
921
910
|
return { content: [{ type: "text", text: "Recorded." }], details: {}, terminate: true };
|
|
922
911
|
},
|
|
923
912
|
}),
|
|
@@ -53,5 +53,14 @@ export declare function writesPlain(command: string): string | undefined;
|
|
|
53
53
|
export declare function runsBuiltCode(command: string): string | undefined;
|
|
54
54
|
/** What turri says when a command would change the machine: what it does instead. */
|
|
55
55
|
export declare function machineChangeReason(why: string): string;
|
|
56
|
+
/**
|
|
57
|
+
* The command as the shell reads its operators, the same length: what quotes hold has its `<`, `>`, `|`, `&`, `;` and
|
|
58
|
+
* newlines put out of the way - a `>` in `grep "</content>"` redirects nothing, a `;` in a string ends no command - and
|
|
59
|
+
* the body of a here-document fed to cat or tee with a quoted delimiter, so not expanded, is blanked: it is the text of
|
|
60
|
+
* a file being written, and a `../lib/logger` or a `>` in it is code, not a path or a redirection. A `$(...)` in double
|
|
61
|
+
* quotes, an unquoted delimiter's body and a here-document fed to anything else - a shell, an interpreter - run, and are
|
|
62
|
+
* read as they are.
|
|
63
|
+
*/
|
|
64
|
+
export declare function shellCode(command: string): string;
|
|
56
65
|
/** Check one command line against a role's fence: `{ ok: true }`, or which rule it breaks and what to do instead. */
|
|
57
66
|
export declare function checkCommand(command: string, fence: CommandFence): CheckResult;
|
|
@@ -247,6 +247,85 @@ const RUN_DOWNLOAD = /\b(ba|z|da|k)?sh\s+(-\w+\s+)*["']?\$\(\s*(curl|wget)\b|<\(
|
|
|
247
247
|
/** Killing by name, or by what holds a port. */
|
|
248
248
|
const KILL_BY_LOOKUP = /\bkill\b[^;&|\n]*(\$\(|`)\s*(lsof|fuser|pgrep|pidof|ss|netstat)\b/;
|
|
249
249
|
const LOOKUP_TO_KILL = /\b(lsof|pgrep|pidof|fuser|ss|netstat)\b[^;&\n]*\|\s*xargs\s+(-\S+\s+)*kill\b/;
|
|
250
|
+
/** A here-document's start: `<<'EOF'`, `<<-"END"`, `<<EOF` - not a here-string's `<<<`. */
|
|
251
|
+
const HEREDOC = /(?<!<)<<(-?)\s*(?:'([^'\n]+)'|"([^"\n]+)"|\\?([A-Za-z_][A-Za-z0-9_]*))/g;
|
|
252
|
+
/** The programs whose here-document is a file's text: they write it out, and run nothing in it. */
|
|
253
|
+
const DATA_SINKS = new Set(["cat", "tee"]);
|
|
254
|
+
/**
|
|
255
|
+
* The command as the shell reads its operators, the same length: what quotes hold has its `<`, `>`, `|`, `&`, `;` and
|
|
256
|
+
* newlines put out of the way - a `>` in `grep "</content>"` redirects nothing, a `;` in a string ends no command - and
|
|
257
|
+
* the body of a here-document fed to cat or tee with a quoted delimiter, so not expanded, is blanked: it is the text of
|
|
258
|
+
* a file being written, and a `../lib/logger` or a `>` in it is code, not a path or a redirection. A `$(...)` in double
|
|
259
|
+
* quotes, an unquoted delimiter's body and a here-document fed to anything else - a shell, an interpreter - run, and are
|
|
260
|
+
* read as they are.
|
|
261
|
+
*/
|
|
262
|
+
export function shellCode(command) {
|
|
263
|
+
const lines = command.split("\n");
|
|
264
|
+
const out = [];
|
|
265
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
266
|
+
const line = lines[index];
|
|
267
|
+
out.push(line);
|
|
268
|
+
// The here-documents this line opens, in order: each body runs to its delimiter alone on a line.
|
|
269
|
+
const opened = [];
|
|
270
|
+
for (const match of maskQuotes(line).matchAll(HEREDOC)) {
|
|
271
|
+
const quoted = match[2] ?? match[3];
|
|
272
|
+
const before = line.slice(0, match.index).split(/&&|\|\||[;|]/).pop() ?? "";
|
|
273
|
+
const program = programOf(before)?.program;
|
|
274
|
+
opened.push({ delimiter: quoted ?? match[4], strip: match[1] === "-", data: quoted !== undefined && program !== undefined && DATA_SINKS.has(program) });
|
|
275
|
+
}
|
|
276
|
+
for (const heredoc of opened) {
|
|
277
|
+
while (index + 1 < lines.length) {
|
|
278
|
+
index += 1;
|
|
279
|
+
const body = lines[index];
|
|
280
|
+
if ((heredoc.strip ? body.replace(/^\t+/, "") : body) === heredoc.delimiter) {
|
|
281
|
+
out.push(body);
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
out.push(heredoc.data ? " ".repeat(body.length) : body);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return maskQuotes(out.join("\n"));
|
|
289
|
+
}
|
|
290
|
+
/** `text` with what its quotes hold out of the shell's way: operators and newlines in a string are a space each. */
|
|
291
|
+
function maskQuotes(text) {
|
|
292
|
+
let out = "";
|
|
293
|
+
let quote;
|
|
294
|
+
/** Inside double quotes, a command substitution runs: read as it is to the end of the string. */
|
|
295
|
+
let substituting = false;
|
|
296
|
+
for (let at = 0; at < text.length; at += 1) {
|
|
297
|
+
const char = text[at];
|
|
298
|
+
if (quote === undefined) {
|
|
299
|
+
if (char === "\\" && at + 1 < text.length) {
|
|
300
|
+
out += char + text[at + 1];
|
|
301
|
+
at += 1;
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
if (char === "'" || char === '"')
|
|
305
|
+
quote = char;
|
|
306
|
+
out += char;
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
if (quote === '"' && char === "\\" && at + 1 < text.length) {
|
|
310
|
+
out += char + (substituting ? text[at + 1] : maskedChar(text[at + 1]));
|
|
311
|
+
at += 1;
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
if (char === quote) {
|
|
315
|
+
quote = undefined;
|
|
316
|
+
substituting = false;
|
|
317
|
+
out += char;
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
if (quote === '"' && (char === "`" || (char === "$" && text[at + 1] === "(")))
|
|
321
|
+
substituting = true;
|
|
322
|
+
out += substituting ? char : maskedChar(char);
|
|
323
|
+
}
|
|
324
|
+
return out;
|
|
325
|
+
}
|
|
326
|
+
function maskedChar(char) {
|
|
327
|
+
return /[<>|&;\n]/.test(char) ? " " : char;
|
|
328
|
+
}
|
|
250
329
|
/** One check, the paths of one platform. */
|
|
251
330
|
class Paths {
|
|
252
331
|
path;
|
|
@@ -342,7 +421,8 @@ function writeTargets(segment) {
|
|
|
342
421
|
if (found === undefined)
|
|
343
422
|
continue;
|
|
344
423
|
const { program, args } = found;
|
|
345
|
-
|
|
424
|
+
// A redirection among its words - `2>/dev/null`, `>out.txt` - is the shell's, read above: never an operand.
|
|
425
|
+
const operands = args.filter((arg) => !arg.startsWith("-") && !/^(\d|&)?[<>]/.test(arg));
|
|
346
426
|
if (program === "tee")
|
|
347
427
|
targets.push(...operands);
|
|
348
428
|
else if ((program === "cp" || program === "mv" || program === "install" || program === "ln") && operands.length >= 2)
|
|
@@ -388,9 +468,9 @@ export function checkCommand(command, fence) {
|
|
|
388
468
|
return refusal("kill", killReason());
|
|
389
469
|
}
|
|
390
470
|
}
|
|
391
|
-
// Paths, a simple command at a time from where the cds before it left it.
|
|
471
|
+
// Paths, a simple command at a time from where the cds before it left it - read as the shell reads its operators.
|
|
392
472
|
let cwd = fence.cwd;
|
|
393
|
-
for (const segment of command.split(/&&|\|\||[;\n]/)) {
|
|
473
|
+
for (const segment of shellCode(command).split(/&&|\|\||[;\n]/)) {
|
|
394
474
|
for (const word of pathWords(segment, paths, fence)) {
|
|
395
475
|
const target = resolveWord(word, cwd, fence, paths);
|
|
396
476
|
if (target !== undefined && !paths.inside(target, readable)) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type ChunkAgents } from "./chunk-plan.ts";
|
|
2
2
|
import { type SpecGap } from "./notes.ts";
|
|
3
3
|
import { type Job, type JobRegistry, type PulseCases } from "./jobs.ts";
|
|
4
|
-
import type { Steering } from "./steer.ts";
|
|
5
4
|
import { type ChainEntry } from "./requires.ts";
|
|
6
5
|
import { type SpecSnapshot } from "./regenerate.ts";
|
|
7
6
|
import { type JobSteering } from "./steering.ts";
|
|
@@ -81,8 +80,8 @@ export interface ModuleStatus {
|
|
|
81
80
|
specs?: string[];
|
|
82
81
|
}>;
|
|
83
82
|
/**
|
|
84
|
-
*
|
|
85
|
-
*
|
|
83
|
+
* Where the plan of its code fell back: a planner's answer that was not given or did not hold, a group split for its
|
|
84
|
+
* size.
|
|
86
85
|
*/
|
|
87
86
|
planNotes?: string[];
|
|
88
87
|
/** Why nothing runs there, when nothing does. */
|
|
@@ -149,23 +148,20 @@ export interface WorkLoop {
|
|
|
149
148
|
*/
|
|
150
149
|
bringUp(plainFile: string, options?: {
|
|
151
150
|
model?: string;
|
|
152
|
-
guidance?: string;
|
|
153
151
|
}): Promise<ModuleStatus[]>;
|
|
154
152
|
/**
|
|
155
|
-
* Plan a spec's module as `bringUp` would - the same codebases, its config pinned
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
* what it is built from or the steering changed since. A module the person halted stays halted, and a codebase whose
|
|
153
|
+
* Plan a spec's module as `bringUp` would - the same codebases, its config pinned - and start nothing: the plans are kept, and its pulses held until regenerate, conform or /regenerate
|
|
154
|
+
* asks for the module. Then the first pulse of the kept plan starts as it is, planned again only when the ***plain or
|
|
155
|
+
* what it is built from changed since. A module the person halted stays halted, and a codebase whose
|
|
159
156
|
* chain has a pulse running goes on as it was, planning what follows it. Says what is planned.
|
|
160
157
|
*/
|
|
161
158
|
lookAhead(plainFile: string, options?: {
|
|
162
159
|
model?: string;
|
|
163
|
-
guidance?: string;
|
|
164
160
|
}): Promise<ModuleStatus[]>;
|
|
165
161
|
/**
|
|
166
162
|
* A planned row (`planned-<module>-N`, as `planned` names it) as the loop keeps it: its cases and, for the next pulse
|
|
167
163
|
* of a codebase with nothing running, the whole prompt its coding agent will get - built from the kept plan, never
|
|
168
|
-
* planned again. Otherwise, or when the ***plain
|
|
164
|
+
* planned again. Otherwise, or when the ***plain changed since the plan was made, `why` says why no
|
|
169
165
|
* prompt is shown. Undefined when no row has that id.
|
|
170
166
|
*/
|
|
171
167
|
plannedPulse(rowId: string): Promise<PlannedPulse | undefined>;
|
|
@@ -177,7 +173,6 @@ export interface WorkLoop {
|
|
|
177
173
|
*/
|
|
178
174
|
regenerateAgain(plainFile: string, funcIds: string | string[], options?: {
|
|
179
175
|
model?: string;
|
|
180
|
-
guidance?: string;
|
|
181
176
|
}): Promise<ModuleStatus[]>;
|
|
182
177
|
/**
|
|
183
178
|
* What is left to regenerate, for a spec's module, in each codebase where its code lives: the code's work from its
|
|
@@ -222,7 +217,6 @@ export interface WorkLoop {
|
|
|
222
217
|
*/
|
|
223
218
|
fromScratch(plainFile: string, options?: {
|
|
224
219
|
model?: string;
|
|
225
|
-
guidance?: string;
|
|
226
220
|
chain?: boolean;
|
|
227
221
|
}): Promise<ModuleStatus[]>;
|
|
228
222
|
/**
|
|
@@ -367,8 +361,6 @@ export declare function createWorkLoop(options: {
|
|
|
367
361
|
planner?: ChunkAgents | false;
|
|
368
362
|
/** The planner's model, read afresh each plan - the chat's, in a conversation. */
|
|
369
363
|
plannerModel?: string | (() => string | undefined);
|
|
370
|
-
/** How the person wants the work cut and ordered, for every plan of a spec's module. */
|
|
371
|
-
steering?: (plainFile: string) => Steering[];
|
|
372
364
|
/** Renders a job. Default: a spec diff render that lands on its unit tests. */
|
|
373
365
|
run?: JobRunner;
|
|
374
366
|
/** Writes and runs a conformance job's tests. Default: a spec diff's conformance run, the whole suite with it. */
|
package/dist/regenerate/loop.js
CHANGED
|
@@ -15,7 +15,7 @@ import { adoptDigests, chainTree, codeTree, conformanceTarget, CONFORM_AGAIN, ma
|
|
|
15
15
|
import { describeSpecDiffConformance, renderSpecDiffConformance } from "./conform.js";
|
|
16
16
|
import { conformanceDirFor } from "./conformance.js";
|
|
17
17
|
import { modulesRoot, projectRootOf } from "./paths.js";
|
|
18
|
-
import { configForSpec, configModuleFor, moduleConfigFile, testDirOf, withConfigModule } from "../config.js";
|
|
18
|
+
import { configForSpec, configModuleFor, moduleConfigFile, moduleConfigsOf, testDirOf, withConfigModule } from "../config.js";
|
|
19
19
|
import { describeSpecChange } from "./prompt.js";
|
|
20
20
|
import { resolveTemplateDirs } from "./paths.js";
|
|
21
21
|
import { builtTips, copyRequiredCode, copyRequiredTests, importingModules, isImportModule, newlyRequired, resolveRequiresChain, startFromScratch } from "./requires.js";
|
|
@@ -33,7 +33,7 @@ import { baseFolderDrift, baseOfCodebase, seedFromBaseFolder } from "./base-fold
|
|
|
33
33
|
import { BASE_RECORD_FILE } from "./paths.js";
|
|
34
34
|
import { onScriptRunEnded, scriptBeingWritten } from "./scripts-being-written.js";
|
|
35
35
|
import { conformanceTestsOn } from "../conformance-switch.js";
|
|
36
|
-
import { projectRootFor } from "./test-scripts.js";
|
|
36
|
+
import { findTestScripts, projectRootFor } from "./test-scripts.js";
|
|
37
37
|
/** What is left to regenerate, as the conversation and the command line read it. */
|
|
38
38
|
export function describeDrift(reports) {
|
|
39
39
|
if (reports.length === 0)
|
|
@@ -304,6 +304,20 @@ export function createWorkLoop(options) {
|
|
|
304
304
|
// Lacking the script, or with one being written over: a pulse started now would run without it, or against the old one.
|
|
305
305
|
return scriptBeingWritten(root, kind, configModuleFor(tip.plainFile));
|
|
306
306
|
};
|
|
307
|
+
/**
|
|
308
|
+
* Why a codebase waits for a unit testing script of its own, or undefined: the project's modules name their scripts in
|
|
309
|
+
* config files of their own - each its own stack's - and none applies to it, nor names a script it could run. Its
|
|
310
|
+
* script is still to come: a pulse started now would stop for want of one. Looked at again when a script run ends, or
|
|
311
|
+
* the module is asked for again.
|
|
312
|
+
*/
|
|
313
|
+
const lacksOwnScript = (state) => {
|
|
314
|
+
const tip = tipEntry(state);
|
|
315
|
+
const root = projectRootFor(tip.plainFile, tip.buildDir);
|
|
316
|
+
if (configModuleFor(tip.plainFile) !== undefined || moduleConfigsOf(root).length === 0)
|
|
317
|
+
return undefined;
|
|
318
|
+
const found = withModuleConfig(state, () => findTestScripts(root, tip.plainFile, tip.buildDir));
|
|
319
|
+
return found.unit !== undefined ? undefined : `${NO_OWN_SCRIPT}${found.notes?.unit !== undefined ? ` ${found.notes.unit}` : ""}`;
|
|
320
|
+
};
|
|
307
321
|
/**
|
|
308
322
|
* The base folder a codebase started from, as its status says it. Counting the files still there looks at each, and the
|
|
309
323
|
* status is read often: so it is read again only when the base record or the code record moved - a pulse landed.
|
|
@@ -514,12 +528,6 @@ export function createWorkLoop(options) {
|
|
|
514
528
|
reportActivity(` ⇢ steered pulse ${running.jobId} (${steering.steers} of ${MAX_STEERS}): ${why}`);
|
|
515
529
|
return true;
|
|
516
530
|
};
|
|
517
|
-
/** How the person wants a codebase's work planned: the conversation's and AGENTS.md's steering, then the requests'. */
|
|
518
|
-
const steeringOf = (state) => [
|
|
519
|
-
...(options.steering?.(state.askedFile) ?? []),
|
|
520
|
-
...state.guidance.map((text) => ({ source: "the request that asked for the work", text })),
|
|
521
|
-
];
|
|
522
|
-
const steeringKeyOf = (state) => JSON.stringify(steeringOf(state));
|
|
523
531
|
const plan = async (state, spec, from, track = "code") => {
|
|
524
532
|
const tip = tipEntry(state);
|
|
525
533
|
const current = track === "code" ? codeTree(spec.tree) : conformanceOf(state, spec, from);
|
|
@@ -531,7 +539,6 @@ export function createWorkLoop(options) {
|
|
|
531
539
|
catch {
|
|
532
540
|
/* the layout is only for how the diffs read */
|
|
533
541
|
}
|
|
534
|
-
const steering = steeringOf(state);
|
|
535
542
|
const separately = track === "conformance" && state.conformanceSeparately === true;
|
|
536
543
|
// How big a pulse may be: the module's config, else the defaults.
|
|
537
544
|
const config = configForSpec(tip.plainFile);
|
|
@@ -540,7 +547,7 @@ export function createWorkLoop(options) {
|
|
|
540
547
|
// A pure rename is turri's to make before the next pulse, not a delete and an add: the work is planned from the code as renamed.
|
|
541
548
|
const renamed = track === "code" ? pureRenames(from, readRecord(testsDirOf(state)), spec.tree, tip.moduleName) : undefined;
|
|
542
549
|
const base = renamed !== undefined && renamed.renames.length > 0 && renamed.code !== null ? codeTree(renamed.code) : from;
|
|
543
|
-
const input = { base, current, specFile, specText,
|
|
550
|
+
const input = { base, current, specFile, specText, track, moduleName: tip.moduleName, limits, ...(separately ? { separately } : {}), ...(testPlainPath !== undefined ? { testPlainPath } : {}) };
|
|
544
551
|
const model = typeof options.plannerModel === "function" ? options.plannerModel() : options.plannerModel;
|
|
545
552
|
const agents = options.planner === false ? undefined : (options.planner ?? llmChunkAgents({ cwd: options.cwd, model: model ?? state.model, label: `${basename(tip.plainFile)} planner` }));
|
|
546
553
|
reportStage(`${tip.moduleName}: planning the ${track === "code" ? "work" : "conformance tests"} into pulses`);
|
|
@@ -876,7 +883,7 @@ export function createWorkLoop(options) {
|
|
|
876
883
|
}
|
|
877
884
|
for (const chain of chains)
|
|
878
885
|
for (const entry of toBuild(chain))
|
|
879
|
-
states.add(track(chain.slice(0, chain.indexOf(entry) + 1),
|
|
886
|
+
states.add(track(chain.slice(0, chain.indexOf(entry) + 1), request));
|
|
880
887
|
}
|
|
881
888
|
return states;
|
|
882
889
|
};
|
|
@@ -972,18 +979,16 @@ export function createWorkLoop(options) {
|
|
|
972
979
|
return;
|
|
973
980
|
}
|
|
974
981
|
}
|
|
975
|
-
// Still wanted: what comes after it is planned now, from what it will land - not once it has.
|
|
976
|
-
// changed, the code's is planned again too: what is not running yet follows it.
|
|
982
|
+
// Still wanted: what comes after it is planned now, from what it will land - not once it has.
|
|
977
983
|
const planOf = track === "code" ? state.plan : state.conformancePlan;
|
|
978
|
-
|
|
979
|
-
if (planOf === undefined || planOf.specKey !== specKey || (track === "code" && state.plan?.steeringKey !== steeringKey)) {
|
|
984
|
+
if (planOf === undefined || planOf.specKey !== specKey) {
|
|
980
985
|
const running = state.running;
|
|
981
986
|
// Shown as being planned on the regeneration; the status goes on showing the running job.
|
|
982
987
|
const rest = workOf(track, running.after, state, spec).length === 0 ? { jobs: [], notes: [] } : await planIdle(state, spec, running.after, track);
|
|
983
988
|
const next = { specKey, from: serializeTree(running.from), jobs: [running.planned, ...rest.jobs] };
|
|
984
989
|
if (state.running === running) {
|
|
985
990
|
if (track === "code")
|
|
986
|
-
state.plan = { ...next,
|
|
991
|
+
state.plan = { ...next, notes: rest.notes };
|
|
987
992
|
else
|
|
988
993
|
state.conformancePlan = { ...next, codeKey: codeKeyOf(state) };
|
|
989
994
|
}
|
|
@@ -1089,15 +1094,14 @@ export function createWorkLoop(options) {
|
|
|
1089
1094
|
return;
|
|
1090
1095
|
}
|
|
1091
1096
|
const fromKey = serializeTree(from);
|
|
1092
|
-
|
|
1093
|
-
if (state.plan === undefined || state.plan.specKey !== specKey || state.plan.from !== fromKey || state.plan.steeringKey !== steeringKey || state.plan.jobs.length === 0) {
|
|
1097
|
+
if (state.plan === undefined || state.plan.specKey !== specKey || state.plan.from !== fromKey || state.plan.jobs.length === 0) {
|
|
1094
1098
|
if (!mayPlan) {
|
|
1095
1099
|
state.plan = undefined;
|
|
1096
1100
|
state.why = LOOK_AGAIN;
|
|
1097
1101
|
return;
|
|
1098
1102
|
}
|
|
1099
1103
|
const { jobs, notes } = await planIdle(state, spec, from, "code");
|
|
1100
|
-
state.plan = { specKey, from: fromKey,
|
|
1104
|
+
state.plan = { specKey, from: fromKey, jobs, notes };
|
|
1101
1105
|
if (jobs.length === 0) {
|
|
1102
1106
|
state.why = NO_PLAN;
|
|
1103
1107
|
return;
|
|
@@ -1107,6 +1111,11 @@ export function createWorkLoop(options) {
|
|
|
1107
1111
|
state.why = SCRIPT_BEING_WRITTEN("unit testing script");
|
|
1108
1112
|
return;
|
|
1109
1113
|
}
|
|
1114
|
+
const lacking = lacksOwnScript(state);
|
|
1115
|
+
if (lacking !== undefined) {
|
|
1116
|
+
state.why = lacking;
|
|
1117
|
+
return;
|
|
1118
|
+
}
|
|
1110
1119
|
state.why = undefined;
|
|
1111
1120
|
startJob(state, spec, from, state.plan.jobs[0]);
|
|
1112
1121
|
};
|
|
@@ -1213,11 +1222,11 @@ export function createWorkLoop(options) {
|
|
|
1213
1222
|
* Look after a codebase - its chain up to it - from now on; says its state. Its config is worked out again - its tip's
|
|
1214
1223
|
* (`configModuleFor`): `asked`, one that cannot be told refuses the ask; otherwise it keeps the one it had.
|
|
1215
1224
|
*/
|
|
1216
|
-
const track = (chain,
|
|
1225
|
+
const track = (chain, request, asked = false) => {
|
|
1217
1226
|
const tip = tipOf(chain);
|
|
1218
1227
|
let state = modules.get(tip.buildDir);
|
|
1219
1228
|
if (state === undefined) {
|
|
1220
|
-
state = { chain
|
|
1229
|
+
state = { chain };
|
|
1221
1230
|
modules.set(tip.buildDir, state);
|
|
1222
1231
|
// Bottom of the chain first: a codebase is looked at after those it is built on.
|
|
1223
1232
|
const at = order.findIndex((key) => modules.get(key).chain.some((entry) => entry.buildDir === tip.buildDir));
|
|
@@ -1227,7 +1236,6 @@ export function createWorkLoop(options) {
|
|
|
1227
1236
|
order.splice(at, 0, tip.buildDir);
|
|
1228
1237
|
}
|
|
1229
1238
|
state.chain = chain;
|
|
1230
|
-
state.askedFile = askedFile;
|
|
1231
1239
|
try {
|
|
1232
1240
|
state.configModule = { name: configModuleFor(tip.plainFile) };
|
|
1233
1241
|
}
|
|
@@ -1239,8 +1247,6 @@ export function createWorkLoop(options) {
|
|
|
1239
1247
|
const model = request.model ?? withModuleConfig(state, () => options.modelFor?.(tip.plainFile));
|
|
1240
1248
|
if (model !== undefined)
|
|
1241
1249
|
state.model = model;
|
|
1242
|
-
if (request.guidance !== undefined && !state.guidance.includes(request.guidance))
|
|
1243
|
-
state.guidance.push(request.guidance);
|
|
1244
1250
|
return state;
|
|
1245
1251
|
};
|
|
1246
1252
|
const loop = {
|
|
@@ -1253,7 +1259,7 @@ export function createWorkLoop(options) {
|
|
|
1253
1259
|
ahead.delete(file);
|
|
1254
1260
|
}
|
|
1255
1261
|
// Asked for, its config is worked out - its own file, or one of a module it requires - and pinned to its pulses.
|
|
1256
|
-
const states = withParseCache(() => files.flatMap((file) => chainsFor(file).flatMap((chain) => toBuild(chain).map((entry) => track(chain.slice(0, chain.indexOf(entry) + 1),
|
|
1262
|
+
const states = withParseCache(() => files.flatMap((file) => chainsFor(file).flatMap((chain) => toBuild(chain).map((entry) => track(chain.slice(0, chain.indexOf(entry) + 1), given, true)))));
|
|
1257
1263
|
// Asked again, a halted codebase is tried again - one the person halted too. Looked ahead at, its kept plan starts.
|
|
1258
1264
|
for (const state of states) {
|
|
1259
1265
|
state.halted = undefined;
|
|
@@ -1274,7 +1280,7 @@ export function createWorkLoop(options) {
|
|
|
1274
1280
|
if (!asked.has(file))
|
|
1275
1281
|
ahead.set(file, { ...ahead.get(file), ...given });
|
|
1276
1282
|
// Its config pinned as an ask pins it: the plan is made, and its pulses run, with the config regenerate would use.
|
|
1277
|
-
const tracked = withParseCache(() => files.flatMap((file) => chainsFor(file).flatMap((chain) => toBuild(chain).map((entry) => track(chain.slice(0, chain.indexOf(entry) + 1),
|
|
1283
|
+
const tracked = withParseCache(() => files.flatMap((file) => chainsFor(file).flatMap((chain) => toBuild(chain).map((entry) => track(chain.slice(0, chain.indexOf(entry) + 1), given, true)))));
|
|
1278
1284
|
// A chain with a pulse running is being built as asked, and goes on; every other codebase is held - one asked for
|
|
1279
1285
|
// earlier too, which would otherwise start the work the look ahead plans.
|
|
1280
1286
|
const building = (state) => state.chain.some((entry) => modules.get(entry.buildDir)?.running !== undefined);
|
|
@@ -1317,7 +1323,7 @@ export function createWorkLoop(options) {
|
|
|
1317
1323
|
return why(`It follows ${index - 1} planned pulse${index === 2 ? "" : "s"} here: its prompt depends on what ${index === 2 ? "that one lands" : "they land"}, and is built when it starts.`);
|
|
1318
1324
|
if (job.track === "conformance")
|
|
1319
1325
|
return why("A conformance pulse's prompt is built from what the code it tests holds once it is built: it is not shown before.");
|
|
1320
|
-
// The plan as kept, and only while it fits the ***plain
|
|
1326
|
+
// The plan as kept, and only while it fits the ***plain as it is now - else regenerate would plan again.
|
|
1321
1327
|
let spec;
|
|
1322
1328
|
try {
|
|
1323
1329
|
spec = chainSpec(state.chain);
|
|
@@ -1325,8 +1331,8 @@ export function createWorkLoop(options) {
|
|
|
1325
1331
|
catch (error) {
|
|
1326
1332
|
return why(`Its ***plain does not parse now: ${error instanceof Error ? error.message : String(error)}`);
|
|
1327
1333
|
}
|
|
1328
|
-
if (state.plan === undefined || !state.plan.jobs.includes(job) || state.plan.specKey !== keyOf(spec)
|
|
1329
|
-
return why("The ***plain
|
|
1334
|
+
if (state.plan === undefined || !state.plan.jobs.includes(job) || state.plan.specKey !== keyOf(spec)) {
|
|
1335
|
+
return why("The ***plain changed since it was planned: regenerate would plan it again. Look ahead again to see the new plan.");
|
|
1330
1336
|
}
|
|
1331
1337
|
const task = await withModuleConfig(state, () => promptOf({ plainFile: tip.plainFile, spec: { ...spec, tree: job.step.tree }, planned: job }));
|
|
1332
1338
|
return task !== undefined ? { ...pulse, task } : why("It has no prompt to show.");
|
|
@@ -1386,7 +1392,7 @@ export function createWorkLoop(options) {
|
|
|
1386
1392
|
const codebase = chain.slice(0, chain.indexOf(entry) + 1);
|
|
1387
1393
|
const tip = tipOf(codebase);
|
|
1388
1394
|
// The codebase as the loop knows it, or - never asked for - as its records have it.
|
|
1389
|
-
const state = modules.get(tip.buildDir) ?? { chain: codebase
|
|
1395
|
+
const state = modules.get(tip.buildDir) ?? { chain: codebase };
|
|
1390
1396
|
return withModuleConfig(state, () => {
|
|
1391
1397
|
const report = { module: tip.moduleName, plainFile: tip.plainFile, code: undefined, conformance: undefined, ...(conformanceTestsOn(tip.plainFile) ? {} : { conformanceOff: true }) };
|
|
1392
1398
|
let spec;
|
|
@@ -1494,7 +1500,7 @@ export function createWorkLoop(options) {
|
|
|
1494
1500
|
}
|
|
1495
1501
|
}
|
|
1496
1502
|
}
|
|
1497
|
-
const tracked = withParseCache(() => (wentBack ? [own] : chainsFor(file)).flatMap((chain) => toBuild(chain).map((entry) => track(chain.slice(0, chain.indexOf(entry) + 1),
|
|
1503
|
+
const tracked = withParseCache(() => (wentBack ? [own] : chainsFor(file)).flatMap((chain) => toBuild(chain).map((entry) => track(chain.slice(0, chain.indexOf(entry) + 1), request, true))));
|
|
1498
1504
|
// The module asked for, in its own codebase - and those below it: never the codebases built on it.
|
|
1499
1505
|
const asking = tracked.find((state) => tipEntry(state).buildDir === self.buildDir);
|
|
1500
1506
|
const states = asking !== undefined ? tracked.filter((state) => own.some((entry) => entry.buildDir === tipEntry(state).buildDir)) : tracked;
|
|
@@ -1766,11 +1772,13 @@ export const UP_TO_DATE = "built from the ***plain as it is";
|
|
|
1766
1772
|
const LOOKED_AHEAD = "looked ahead - planned, and nothing starts until regenerate, conform or /regenerate asks for it";
|
|
1767
1773
|
/** What a planned row of a codebase a look ahead planned says first. */
|
|
1768
1774
|
const LOOKED_AHEAD_NOTE = "Planned by a look ahead: it waits for regenerate, conform or /regenerate to start it.";
|
|
1769
|
-
/** Why a codebase held for a look ahead has no plan: its ***plain
|
|
1770
|
-
const LOOK_AGAIN = "looked ahead, and the ***plain
|
|
1775
|
+
/** Why a codebase held for a look ahead has no plan: its ***plain moved since, and only a look ahead plans it. */
|
|
1776
|
+
const LOOK_AGAIN = "looked ahead, and the ***plain changed since - look ahead again to plan it, or regenerate it";
|
|
1771
1777
|
/** Why a codebase with work left has no plan: the planner found none. */
|
|
1772
1778
|
/** Why a codebase waits for a testing script being written in the background. */
|
|
1773
1779
|
const SCRIPT_BEING_WRITTEN = (what) => `waiting for its ${what}, which is being written`;
|
|
1780
|
+
/** Why a codebase waits where modules name their testing scripts in files of their own and it has none: the note says which file names which. */
|
|
1781
|
+
const NO_OWN_SCRIPT = "waiting for a unit testing script of its own - write one for its stack (implement-unit-testing-script), named in its own config file.";
|
|
1774
1782
|
const NO_PLAN = "the planner found no way to cut the work into pulses that hold together";
|
|
1775
1783
|
/**
|
|
1776
1784
|
* Where the functional specs' test plain files of a module's chain are, by func-id and module - the module's own when none
|
|
@@ -1990,7 +1998,7 @@ export function describeModules(statuses, options = {}) {
|
|
|
1990
1998
|
? ` ${index + 1}. ${job.track === "conformance" ? "conformance tests: " : ""}${job.title} - being planned into pulses`
|
|
1991
1999
|
: ` ${index + 1}. ${job.track === "conformance" ? "conformance tests: " : ""}${job.title} - ${casesText(job.cases)}`));
|
|
1992
2000
|
if (status.planNotes !== undefined)
|
|
1993
|
-
lines.push("
|
|
2001
|
+
lines.push(" where the plan fell back:", ...status.planNotes.map((note) => ` - ${note}`));
|
|
1994
2002
|
// A look ahead from the command line keeps its plan only while the process lives: the run that starts it plans again.
|
|
1995
2003
|
if (status.why !== undefined)
|
|
1996
2004
|
lines.push(options.for === "command line" && status.why === LOOKED_AHEAD
|
|
@@ -71,6 +71,9 @@ export declare function projectRootFor(plainFile: string, buildDir: string): str
|
|
|
71
71
|
*
|
|
72
72
|
* A folder holding two of a kind does not say which is meant: it is skipped, and noted, so the
|
|
73
73
|
* error that stops the build can say to name one in config.turri.yaml.
|
|
74
|
+
*
|
|
75
|
+
* Where modules have config files of their own and none applies to this one, a script one of those files names is that
|
|
76
|
+
* module's - of its stack - and never found in a folder for this one: a frontend is not tested with the backend's script.
|
|
74
77
|
*/
|
|
75
78
|
export declare function findTestScripts(root: string, plainFile?: string, buildDir?: string): TestScripts;
|
|
76
79
|
/**
|
|
@@ -54,12 +54,15 @@ export function projectRootFor(plainFile, buildDir) {
|
|
|
54
54
|
const index = parts.lastIndexOf("plain_modules");
|
|
55
55
|
return index > 0 ? parts.slice(0, index).join(sep) : dirname(resolve(plainFile));
|
|
56
56
|
}
|
|
57
|
-
/**
|
|
58
|
-
|
|
57
|
+
/**
|
|
58
|
+
* The one script of a kind in a folder, by the names the skills give them; two or more say which. What `claimed` holds -
|
|
59
|
+
* the scripts other modules' own files name - is never one of them.
|
|
60
|
+
*/
|
|
61
|
+
function onlyScriptIn(dir, kind, claimed = new Set()) {
|
|
59
62
|
if (!existsSync(dir))
|
|
60
63
|
return {};
|
|
61
64
|
const candidates = readdirSync(dir)
|
|
62
|
-
.filter((name) => (kind === "prepare" ? PREPARE_NAME.test(name) : scriptKind(name) === kind) && isFile(join(dir, name)))
|
|
65
|
+
.filter((name) => (kind === "prepare" ? PREPARE_NAME.test(name) : scriptKind(name) === kind) && isFile(join(dir, name)) && !claimed.has(resolve(dir, name)))
|
|
63
66
|
.sort();
|
|
64
67
|
if (candidates.length === 1)
|
|
65
68
|
return { path: join(dir, candidates[0]) };
|
|
@@ -79,6 +82,9 @@ function onlyScriptIn(dir, kind) {
|
|
|
79
82
|
*
|
|
80
83
|
* A folder holding two of a kind does not say which is meant: it is skipped, and noted, so the
|
|
81
84
|
* error that stops the build can say to name one in config.turri.yaml.
|
|
85
|
+
*
|
|
86
|
+
* Where modules have config files of their own and none applies to this one, a script one of those files names is that
|
|
87
|
+
* module's - of its stack - and never found in a folder for this one: a frontend is not tested with the backend's script.
|
|
82
88
|
*/
|
|
83
89
|
export function findTestScripts(root, plainFile, buildDir) {
|
|
84
90
|
const found = {};
|
|
@@ -89,6 +95,11 @@ export function findTestScripts(root, plainFile, buildDir) {
|
|
|
89
95
|
const file = own !== undefined ? `${moduleConfigFileIn(root, own)} (over ${projectConfigFile(root)})` : projectConfigFile(root);
|
|
90
96
|
// Modules with files of their own, none of them this one's: its scripts are likely named in theirs.
|
|
91
97
|
const others = own === undefined ? moduleConfigsOf(root) : [];
|
|
98
|
+
// What their files name is theirs: never this module's, found in a folder.
|
|
99
|
+
const claimed = new Set(others.flatMap((each) => {
|
|
100
|
+
const theirs = readProjectConfig(root, each);
|
|
101
|
+
return [theirs.unittestsScript, theirs.conformanceTestsScript, theirs.prepareEnvironmentScript].flatMap((named) => (named !== undefined ? [resolve(root, named.trim())] : []));
|
|
102
|
+
}));
|
|
92
103
|
// Where a script is named: the module's own file - or, where modules have their own, the one of the module that builds it.
|
|
93
104
|
const nameIn = own !== undefined
|
|
94
105
|
? moduleConfigFileIn(root, own)
|
|
@@ -114,7 +125,7 @@ export function findTestScripts(root, plainFile, buildDir) {
|
|
|
114
125
|
}
|
|
115
126
|
}
|
|
116
127
|
for (const dir of [root, join(root, SCRIPTS_DIR)]) {
|
|
117
|
-
const { path, several } = onlyScriptIn(dir, kind);
|
|
128
|
+
const { path, several } = onlyScriptIn(dir, kind, claimed);
|
|
118
129
|
if (path !== undefined) {
|
|
119
130
|
found[kind] = path;
|
|
120
131
|
break;
|
|
@@ -137,7 +148,7 @@ export function findTestScripts(root, plainFile, buildDir) {
|
|
|
137
148
|
if (preparePath !== undefined)
|
|
138
149
|
notes.prepare = `${file} names ${prepareNamed.trim()} as the ${CONFIG_KEYS.prepareEnvironmentScript}, and there is no such file.`;
|
|
139
150
|
for (const dir of [root, join(root, SCRIPTS_DIR)]) {
|
|
140
|
-
const { path, several } = onlyScriptIn(dir, "prepare");
|
|
151
|
+
const { path, several } = onlyScriptIn(dir, "prepare", claimed);
|
|
141
152
|
if (path !== undefined) {
|
|
142
153
|
found.prepare = path;
|
|
143
154
|
break;
|