@turri-dev/cli 0.2.4-next.8422d0f → 0.2.4-next.efe96fe
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 +5 -6
- 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/chats.d.ts +2 -12
- package/dist/chats.js +3 -26
- package/dist/cli.js +11 -30
- package/dist/config-edit.d.ts +20 -8
- package/dist/config-edit.js +29 -23
- package/dist/config.d.ts +62 -71
- package/dist/config.js +170 -125
- 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 +8 -10
- package/dist/extension.js +257 -429
- package/dist/genome.js +9 -48
- package/dist/graph.js +3 -5
- package/dist/host-session.d.ts +5 -16
- package/dist/host-session.js +4 -6
- package/dist/host.d.ts +2 -4
- package/dist/host.js +4 -7
- package/dist/identity.js +0 -1
- package/dist/init-config.d.ts +0 -1
- package/dist/init-config.js +3 -10
- package/dist/installed-providers.d.ts +1 -1
- package/dist/installed-providers.js +1 -1
- package/dist/loop-cli.d.ts +4 -3
- package/dist/loop-cli.js +13 -11
- package/dist/loop-tools.d.ts +37 -18
- package/dist/loop-tools.js +118 -58
- package/dist/new-project.js +2 -2
- 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.js +4 -4
- 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/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/ledger-view.d.ts +11 -24
- package/dist/regenerate/ledger-view.js +14 -60
- package/dist/regenerate/ledger.d.ts +2 -15
- package/dist/regenerate/ledger.js +1 -1
- package/dist/regenerate/loop.d.ts +48 -62
- package/dist/regenerate/loop.js +296 -131
- 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 +1 -1
- package/dist/regenerate/paths.js +2 -2
- 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 +33 -7
- package/dist/sentinel.js +8 -5
- 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 +2 -4
- package/docs/authoring-plain.md +3 -3
- package/docs/chats.md +4 -7
- package/docs/claude-subscription.md +2 -2
- package/docs/config.md +55 -45
- package/docs/deploy.md +1 -1
- package/docs/development.md +3 -4
- package/docs/headless.md +6 -5
- package/docs/hosting.md +11 -11
- package/docs/parser.md +3 -3
- package/docs/regenerating.md +27 -19
- package/docs/sentinel.md +6 -6
- package/docs/skills-and-gates.md +4 -9
- package/docs/using.md +20 -37
- package/genome/rules/project-model.md +2 -1
- package/genome/rules/test-plain-files.md +15 -7
- package/genome/rules/turri-regeneration.md +6 -9
- 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.d.ts +0 -1
- 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/test-advisor.d.ts +0 -101
- package/dist/regenerate/test-advisor.js +0 -379
- 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/test-advisor.md +0 -110
package/dist/regenerate/loop.js
CHANGED
|
@@ -9,16 +9,16 @@ import { llmChunkAgents, MAX_LINES_PER_JOB, MAX_SPECS_PER_JOB, planChunks, steps
|
|
|
9
9
|
import { commitNotes, landWork, recordHistory, resetToLastCommit } from "./lineage.js";
|
|
10
10
|
import { firstLine, record } from "./ledger.js";
|
|
11
11
|
import { NOTES_FILE, recordPulse } from "./notes.js";
|
|
12
|
-
import {
|
|
12
|
+
import { formatDuration } from "./jobs.js";
|
|
13
13
|
import { moduleLanes } from "./lanes.js";
|
|
14
|
-
import { adoptDigests, chainTree, codeTree, conformanceTarget,
|
|
14
|
+
import { adoptDigests, chainTree, codeTree, conformanceTarget, CONFORM_AGAIN, marksTestsAgain, REGENERATE_AGAIN, inheritedRecord, isOldRecord, notBuilt, readRecord, RECORD_FILE, withResourceDigests, writeCodeRecord, writeTestsRecord, hasScenarios, identityOf, testedFuncIds, } from "./records.js";
|
|
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,
|
|
18
|
+
import { configForSpec, configModuleFor, moduleConfigFile, testDirOf, withConfigModule } from "../config.js";
|
|
19
19
|
import { describeSpecChange } from "./prompt.js";
|
|
20
20
|
import { resolveTemplateDirs } from "./paths.js";
|
|
21
|
-
import { builtTips, copyRequiredCode, importingModules, isImportModule, newlyRequired, resolveRequiresChain, startFromScratch } from "./requires.js";
|
|
21
|
+
import { builtTips, copyRequiredCode, copyRequiredTests, importingModules, isImportModule, newlyRequired, resolveRequiresChain, startFromScratch } from "./requires.js";
|
|
22
22
|
import { describeSpecDiff, renderSpecDiff, specFilesOf } from "./regenerate.js";
|
|
23
23
|
import { locateDiffLines } from "./diff-view.js";
|
|
24
24
|
import { agentChanges, changeDiffInFiles } from "./change-view.js";
|
|
@@ -28,12 +28,12 @@ import { changesBetween, parseTree, serializeTree } from "./spec-steps.js";
|
|
|
28
28
|
import { hasFiles } from "./testing.js";
|
|
29
29
|
import { makeRenames, pureRenames, renameText } from "./renames.js";
|
|
30
30
|
import { casesOf, codeWork, stillWanted, whyNotWanted } from "./drift.js";
|
|
31
|
-
import { testingGap } from "./testing-steps.js";
|
|
31
|
+
import { stepsToScenarios, testingGap } from "./testing-steps.js";
|
|
32
32
|
import { baseFolderDrift, baseOfCodebase, seedFromBaseFolder } from "./base-folder.js";
|
|
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 {
|
|
36
|
+
import { 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)
|
|
@@ -208,8 +208,9 @@ export function codebaseCompletion(chain) {
|
|
|
208
208
|
codebase.forEach((entry, index) => {
|
|
209
209
|
const count = counts[index];
|
|
210
210
|
const completed = entry.funcIds.filter((funcId) => !touched.has(`${entry.moduleName}:${funcId}`));
|
|
211
|
-
// Tests marked to regenerate again were written against code since replaced
|
|
212
|
-
|
|
211
|
+
// Tests marked to regenerate again were written against code since replaced, and those marked to be written again
|
|
212
|
+
// are to be written anew: not conformance tested until rewritten.
|
|
213
|
+
const tested = ownItems(testsRecord ?? undefined, entry.moduleName, entry.moduleName === tip.moduleName).filter((item) => item.id !== undefined && !marksTestsAgain(item) && reads(item) === specText(entry.moduleName, item.id));
|
|
213
214
|
count.completed = completed.length;
|
|
214
215
|
count.tested = completed.filter((funcId) => tested.some((item) => item.id === funcId));
|
|
215
216
|
count.conformanceTested = count.tested.length;
|
|
@@ -240,8 +241,8 @@ export function createWorkLoop(options) {
|
|
|
240
241
|
const tip = tipEntry(state);
|
|
241
242
|
return { project: projectRootOf(tip.buildDir), module: tip.moduleName, job };
|
|
242
243
|
};
|
|
243
|
-
/** `work` with the codebase's
|
|
244
|
-
const
|
|
244
|
+
/** `work` with the codebase's config pinned - its module's own file, or one it requires - once it is worked out. */
|
|
245
|
+
const withModuleConfig = (state, work) => (state.configModule !== undefined ? withConfigModule(state.configModule.name, work) : work());
|
|
245
246
|
const keyOf = (spec) => serializeTree(codeTree(spec.tree));
|
|
246
247
|
/** What a codebase is built from: its record, or - nothing built - what it starts from, the code of the module it requires. */
|
|
247
248
|
const builtOf = (state) => {
|
|
@@ -286,7 +287,7 @@ export function createWorkLoop(options) {
|
|
|
286
287
|
(spec.tree[TEST_REQUIREMENTS] ?? []).length > 0 && readRecord(tipEntry(state).buildDir) !== null && gapOf(state, spec) === undefined;
|
|
287
288
|
/**
|
|
288
289
|
* The step of adding tests a codebase skipped - its functional specs have scenarios, and it has no test reqs or no
|
|
289
|
-
* conformance testing script
|
|
290
|
+
* conformance testing script: no conformance pulse of it starts, in the loop or from conform, and it
|
|
290
291
|
* waits on that step until the spec or the scripts change.
|
|
291
292
|
*/
|
|
292
293
|
const gapOf = (state, spec) => {
|
|
@@ -294,13 +295,14 @@ export function createWorkLoop(options) {
|
|
|
294
295
|
return testingGap({ moduleName: tip.moduleName, plainFile: tip.plainFile, tree: spec.tree, buildDir: tip.buildDir });
|
|
295
296
|
};
|
|
296
297
|
/**
|
|
297
|
-
* Whether a
|
|
298
|
-
* rather than fail for want of it, and is looked at again once the run ends.
|
|
298
|
+
* Whether a testing script of this kind is being written for a codebase now - one it lacks, or one written over: it waits
|
|
299
|
+
* for it, rather than fail for want of it or run against the old one, and is looked at again once the run ends.
|
|
299
300
|
*/
|
|
300
301
|
const awaitsScript = (state, kind) => {
|
|
301
302
|
const tip = tipEntry(state);
|
|
302
303
|
const root = projectRootFor(tip.plainFile, tip.buildDir);
|
|
303
|
-
|
|
304
|
+
// Lacking the script, or with one being written over: a pulse started now would run without it, or against the old one.
|
|
305
|
+
return scriptBeingWritten(root, kind, configModuleFor(tip.plainFile));
|
|
304
306
|
};
|
|
305
307
|
/**
|
|
306
308
|
* The base folder a codebase started from, as its status says it. Counting the files still there looks at each, and the
|
|
@@ -353,15 +355,96 @@ export function createWorkLoop(options) {
|
|
|
353
355
|
}
|
|
354
356
|
return narrowed;
|
|
355
357
|
};
|
|
356
|
-
/**
|
|
357
|
-
|
|
358
|
+
/**
|
|
359
|
+
* The functional specs conform named - func-ids of `module` - and every functional spec as it reads now, to tell a
|
|
360
|
+
* change to one after. In a codebase built on `module`, they are among the functional specs it requires.
|
|
361
|
+
*/
|
|
362
|
+
const namedOnly = (state, funcIds, module) => {
|
|
358
363
|
const tree = chainSpec(state.chain).tree;
|
|
359
364
|
const read = new Map();
|
|
360
365
|
for (const section of [FUNCTIONAL_REQUIREMENTS, REQUIRED_FUNCTIONAL_SPECS]) {
|
|
361
366
|
for (const item of tree[section] ?? [])
|
|
362
367
|
read.set(identityOf(item), JSON.stringify(item));
|
|
363
368
|
}
|
|
364
|
-
|
|
369
|
+
const own = tipEntry(state).moduleName === module;
|
|
370
|
+
return { specs: new Set(funcIds.map((id) => identityOf(own ? { id } : { id, module }))), read };
|
|
371
|
+
};
|
|
372
|
+
/**
|
|
373
|
+
* Conformance tests written already, to be written again as conform names them - their code untouched: the functional
|
|
374
|
+
* specs named, func-ids of `self`, marked in the tests record of every codebase where its code lives - the tips of its
|
|
375
|
+
* chains, whose suite holds the chain's tests, among the functional specs required there for a module below - each
|
|
376
|
+
* committed. Refused while a pulse runs in one it marks. Says which functional specs were marked.
|
|
377
|
+
*/
|
|
378
|
+
const conformAgain = (file, self, funcIds) => {
|
|
379
|
+
const codebases = [...new Map(chainsFor(file).map(tipOf).map((entry) => [entry.buildDir, entry])).values()];
|
|
380
|
+
// What is marked, worked out before anything is: a codebase that has none of them is not touched, nor refused.
|
|
381
|
+
const touching = codebases.flatMap((entry) => {
|
|
382
|
+
const testsDir = conformanceDirFor(entry.moduleName, modulesRoot(projectDirOf(entry.plainFile)));
|
|
383
|
+
const tests = readRecord(testsDir);
|
|
384
|
+
if (tests === null)
|
|
385
|
+
return [];
|
|
386
|
+
const section = entry.moduleName === self.moduleName ? FUNCTIONAL_REQUIREMENTS : REQUIRED_FUNCTIONAL_SPECS;
|
|
387
|
+
const items = tests[section] ?? [];
|
|
388
|
+
const funcIdOf = (item) => (section === FUNCTIONAL_REQUIREMENTS || item.module === self.moduleName ? (item.id ?? "") : "");
|
|
389
|
+
const taken = items.flatMap((item) => (funcIds.includes(funcIdOf(item)) ? [funcIdOf(item)] : []));
|
|
390
|
+
if (taken.length === 0)
|
|
391
|
+
return [];
|
|
392
|
+
const marked = items.map((item) => (funcIds.includes(funcIdOf(item)) ? { ...item, [CONFORM_AGAIN]: true } : item));
|
|
393
|
+
return [{ entry, testsDir, taken, record: { ...tests, [section]: marked } }];
|
|
394
|
+
});
|
|
395
|
+
for (const { entry } of touching) {
|
|
396
|
+
if (modules.get(entry.buildDir)?.running !== undefined)
|
|
397
|
+
throw new Error(`${entry.moduleName} has a pulse running: halt it, or ask again once it is done. Nothing was started.`);
|
|
398
|
+
}
|
|
399
|
+
const found = new Set();
|
|
400
|
+
for (const { entry, testsDir, taken, record } of touching) {
|
|
401
|
+
writeTestsRecord(testsDir, record);
|
|
402
|
+
recordHistory(entry.buildDir, `the conformance tests of ${namesOf(self.moduleName, taken)} to write again`);
|
|
403
|
+
for (const funcId of taken)
|
|
404
|
+
found.add(funcId);
|
|
405
|
+
const state = modules.get(entry.buildDir);
|
|
406
|
+
if (state === undefined)
|
|
407
|
+
continue;
|
|
408
|
+
state.conformancePlan = undefined;
|
|
409
|
+
state.conformanceHalted = undefined;
|
|
410
|
+
}
|
|
411
|
+
return [...found];
|
|
412
|
+
};
|
|
413
|
+
/**
|
|
414
|
+
* A module's conformance tests from scratch, where its code lives - the tip of each chain it is built in, as
|
|
415
|
+
* `fromScratch` regenerates its code there, never a codebase in the middle - the code untouched: each tip's tests folder
|
|
416
|
+
* taken out whole, committed so its history keeps it; then, `fromBelow`, the tests of the module the tip requires copied
|
|
417
|
+
* in, as the codebase started from them - its own tests written anew on them, those it inherits brought up to date.
|
|
418
|
+
* Without, nothing: every functional spec of the chain is written anew there. Nothing below a tip is touched. Refused
|
|
419
|
+
* while a pulse runs in one. Says which codebases' tests were taken out.
|
|
420
|
+
*/
|
|
421
|
+
const testsFromScratch = (file, fromBelow) => {
|
|
422
|
+
const chains = chainsFor(file);
|
|
423
|
+
const tips = [...new Map(chains.map((chain) => [tipOf(chain).buildDir, chain])).values()].flatMap((chain) => {
|
|
424
|
+
const tip = tipOf(chain);
|
|
425
|
+
const testsDir = conformanceDirFor(tip.moduleName, modulesRoot(projectDirOf(tip.plainFile)));
|
|
426
|
+
// Nothing built and no tests: there is nothing to start again - they are written once the code is.
|
|
427
|
+
return started(tip) || existsSync(testsDir) ? [{ chain, tip, testsDir }] : [];
|
|
428
|
+
});
|
|
429
|
+
for (const { tip } of tips) {
|
|
430
|
+
if (modules.get(tip.buildDir)?.running !== undefined)
|
|
431
|
+
throw new Error(`${tip.moduleName} has a pulse running: halt it, or ask again once it is done. Nothing was started.`);
|
|
432
|
+
}
|
|
433
|
+
for (const { chain, tip, testsDir } of tips) {
|
|
434
|
+
rmSync(testsDir, { recursive: true, force: true });
|
|
435
|
+
const below = fromBelow ? chain.find((entry) => entry.moduleName === tip.requires) : undefined;
|
|
436
|
+
if (below !== undefined)
|
|
437
|
+
copyRequiredTests(below.buildDir, tip.buildDir, below.moduleName);
|
|
438
|
+
const why = below !== undefined ? `asked to be written again from scratch, starting from ${below.moduleName}'s` : "asked to be written again from scratch, with its whole chain's";
|
|
439
|
+
recordHistory(tip.buildDir, `conformance tests from scratch: ${why}`);
|
|
440
|
+
reportActivity(` ${tip.moduleName}: its conformance tests are taken out${below !== undefined ? `, and ${below.moduleName}'s copied in` : ""} - ${why}`);
|
|
441
|
+
const state = modules.get(tip.buildDir);
|
|
442
|
+
if (state === undefined)
|
|
443
|
+
continue;
|
|
444
|
+
state.conformancePlan = undefined;
|
|
445
|
+
state.conformanceHalted = undefined;
|
|
446
|
+
}
|
|
447
|
+
return tips.map(({ tip }) => tip.moduleName);
|
|
365
448
|
};
|
|
366
449
|
/** The work of a track, from where it is built from to what it is to be - for the conformance tests, as conform narrowed them unless `narrowed` is false. */
|
|
367
450
|
const workOf = (track, from, state, spec, narrowed = true) => track === "code" ? codeWork(from, spec.tree) : changesBetween(serializeTree(from), serializeTree(conformanceOf(state, spec, from, narrowed)));
|
|
@@ -486,20 +569,18 @@ export function createWorkLoop(options) {
|
|
|
486
569
|
options.registry.notify?.();
|
|
487
570
|
}
|
|
488
571
|
};
|
|
489
|
-
/** A dry run's first jobs, by codebase: what each would start. */
|
|
490
|
-
const firsts = new Map();
|
|
491
572
|
const startJob = (state, spec, from, planned) => {
|
|
492
573
|
// Halted while it was being planned: the plan is made, nothing starts.
|
|
493
574
|
if (state.held !== undefined) {
|
|
494
575
|
state.why = state.held.why;
|
|
495
576
|
return;
|
|
496
577
|
}
|
|
497
|
-
|
|
498
|
-
if (
|
|
499
|
-
|
|
500
|
-
state.why = `would start: ${planned.title}`;
|
|
578
|
+
// Looked ahead: the plan is kept, and its first pulse waits for the module to be asked for.
|
|
579
|
+
if (state.lookedAhead === true) {
|
|
580
|
+
state.why = LOOKED_AHEAD;
|
|
501
581
|
return;
|
|
502
582
|
}
|
|
583
|
+
const tip = tipEntry(state);
|
|
503
584
|
const conformance = planned.track === "conformance";
|
|
504
585
|
// A code job can be steered while it regenerates: its target moves with the spec, inside what it regenerates.
|
|
505
586
|
const steering = conformance ? undefined : createSteering(planned.step.tree, tip.moduleName);
|
|
@@ -549,7 +630,7 @@ export function createWorkLoop(options) {
|
|
|
549
630
|
}
|
|
550
631
|
// Nothing here yet, and nothing below: the codebase starts from its base folder, when the config names one.
|
|
551
632
|
if (tip.requires === null && !started(tip))
|
|
552
|
-
|
|
633
|
+
withModuleConfig(state, () => seedFromBaseFolder(tip.buildDir, tip.plainFile, tip.moduleName));
|
|
553
634
|
// A conformance job is shown the spec whole - its test reqs and scenarios are its to write from.
|
|
554
635
|
const result = await (conformance ? runConformance : run)({
|
|
555
636
|
plainFile: tip.plainFile,
|
|
@@ -718,8 +799,8 @@ export function createWorkLoop(options) {
|
|
|
718
799
|
* nothing running there - so the code is taken to be built from them, rather than everything linking one built again.
|
|
719
800
|
*/
|
|
720
801
|
const hashResources = (state, spec) => {
|
|
721
|
-
// A
|
|
722
|
-
if (
|
|
802
|
+
// A look ahead only reads.
|
|
803
|
+
if (state.lookedAhead === true)
|
|
723
804
|
return;
|
|
724
805
|
const code = tipEntry(state).buildDir;
|
|
725
806
|
for (const dir of [code, testsDirOf(state)]) {
|
|
@@ -749,11 +830,15 @@ export function createWorkLoop(options) {
|
|
|
749
830
|
};
|
|
750
831
|
// A testing script written in the background, or not: what waited for it is looked at again - started, or failed for want of it.
|
|
751
832
|
onScriptRunEnded(() => {
|
|
752
|
-
if (asked.size > 0
|
|
833
|
+
if (asked.size > 0 || ahead.size > 0)
|
|
753
834
|
void tick();
|
|
754
835
|
});
|
|
755
836
|
/** The files asked for, each with how: what the loop brings up, worked out again each look. */
|
|
756
837
|
const asked = new Map();
|
|
838
|
+
/** The files looked ahead at and not asked for since: their codebases are looked at, their pulses held. */
|
|
839
|
+
const ahead = new Map();
|
|
840
|
+
/** The codebases a look ahead is planning now: the only looks that plan a codebase held for one. */
|
|
841
|
+
const planningAhead = new Set();
|
|
757
842
|
/**
|
|
758
843
|
* The modules asked for whose plan is not made yet - their code being deleted, what is left being worked out, the
|
|
759
844
|
* planner not started - by name, with since when: each shows as being planned from the moment it is asked for, not
|
|
@@ -776,10 +861,13 @@ export function createWorkLoop(options) {
|
|
|
776
861
|
options.registry.notify?.();
|
|
777
862
|
}
|
|
778
863
|
};
|
|
779
|
-
/**
|
|
780
|
-
|
|
864
|
+
/**
|
|
865
|
+
* The codebases the requests bring up now - where each module's code lives, and what is to be built on it - those
|
|
866
|
+
* asked for and, unless `requests` names others, those looked ahead at.
|
|
867
|
+
*/
|
|
868
|
+
const active = (requests = [...asked, ...ahead]) => {
|
|
781
869
|
const states = new Set();
|
|
782
|
-
for (const [file, request] of
|
|
870
|
+
for (const [file, request] of requests) {
|
|
783
871
|
let chains;
|
|
784
872
|
try {
|
|
785
873
|
chains = chainsFor(file);
|
|
@@ -805,6 +893,9 @@ export function createWorkLoop(options) {
|
|
|
805
893
|
for (const file of [...asked.keys()])
|
|
806
894
|
if (!existsSync(file))
|
|
807
895
|
asked.delete(file);
|
|
896
|
+
for (const file of [...ahead.keys()])
|
|
897
|
+
if (!existsSync(file))
|
|
898
|
+
ahead.delete(file);
|
|
808
899
|
for (const key of [...order]) {
|
|
809
900
|
const state = modules.get(key);
|
|
810
901
|
if (state.running === undefined && !existsSync(tipEntry(state).plainFile))
|
|
@@ -821,7 +912,7 @@ export function createWorkLoop(options) {
|
|
|
821
912
|
// A codebase left behind - built on since - is not looked at, unless a job of it is still running; what it had
|
|
822
913
|
// planned, or waited for, is no longer shown.
|
|
823
914
|
if (now.has(state) || state.running !== undefined)
|
|
824
|
-
await
|
|
915
|
+
await withModuleConfig(state, () => look(state));
|
|
825
916
|
else {
|
|
826
917
|
state.why = "left behind: the code is built on further up the chain, where changes to it are made";
|
|
827
918
|
state.waitsFor = undefined;
|
|
@@ -853,14 +944,6 @@ export function createWorkLoop(options) {
|
|
|
853
944
|
}
|
|
854
945
|
const specKey = keyOf(spec);
|
|
855
946
|
state.seen = spec;
|
|
856
|
-
if (options.onSpec !== undefined) {
|
|
857
|
-
try {
|
|
858
|
-
options.onSpec({ chain: state.chain, tree: spec.tree, built: builtOf(state) });
|
|
859
|
-
}
|
|
860
|
-
catch {
|
|
861
|
-
/* what watches the spec never stops the loop */
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
947
|
if (state.running !== undefined) {
|
|
865
948
|
if (state.running.stopping === true)
|
|
866
949
|
return;
|
|
@@ -947,8 +1030,10 @@ export function createWorkLoop(options) {
|
|
|
947
1030
|
// A func-id or a scenario-id renamed, and nothing else with it: turri renames it in the records and relabels the tests
|
|
948
1031
|
// itself, as one unit of work - no pulse, the code untouched. Failing, it is rolled back whole, and the codebase halts
|
|
949
1032
|
// rather than build the functional spec anew.
|
|
950
|
-
|
|
951
|
-
|
|
1033
|
+
// Looked ahead, they are not made - a look ahead writes nothing - and the code is planned from as they would leave it.
|
|
1034
|
+
const renamed = readRecord(tip.buildDir) === null ? undefined : pureRenames(readRecord(tip.buildDir), readRecord(testsDirOf(state)), spec.tree, tip.moduleName);
|
|
1035
|
+
const pending = state.lookedAhead === true && renamed !== undefined && renamed.renames.length > 0 && renamed.code !== null ? renamed.code : undefined;
|
|
1036
|
+
if (renamed !== undefined && renamed.renames.length > 0 && state.lookedAhead !== true) {
|
|
952
1037
|
const made = makeRenames({ buildDir: tip.buildDir, testsDir: testsDirOf(state), moduleName: tip.moduleName, renamed, place: { project: projectRootOf(tip.buildDir), module: tip.moduleName } });
|
|
953
1038
|
if (!made) {
|
|
954
1039
|
state.halted = { why: `renaming ${renamed.renames.map(renameText).join(", ")} failed, and was rolled back - it is tried again once the spec changes, or the module is asked for again`, specKey };
|
|
@@ -959,8 +1044,10 @@ export function createWorkLoop(options) {
|
|
|
959
1044
|
}
|
|
960
1045
|
// The module's code first, every job of it; then its conformance tests - once, for the module as built, with one
|
|
961
1046
|
// explorer and one run of the whole suite - and only then is anything built on it (waitingOn).
|
|
962
|
-
const from = builtOf(state);
|
|
1047
|
+
const from = pending !== undefined ? codeTree(pending) : builtOf(state);
|
|
963
1048
|
const codeLeft = codeWork(from, spec.tree).length > 0;
|
|
1049
|
+
// Held for a look ahead, a codebase is planned by a look ahead alone: a plan that no longer fits is dropped, not made again.
|
|
1050
|
+
const mayPlan = state.lookedAhead !== true || planningAhead.has(state);
|
|
964
1051
|
if (state.conformanceHalted !== undefined && state.conformanceHalted.key !== conformanceKey(state))
|
|
965
1052
|
state.conformanceHalted = undefined;
|
|
966
1053
|
if (!codeLeft && conformanceWanted(state, spec) && state.conformanceHalted === undefined) {
|
|
@@ -971,6 +1058,11 @@ export function createWorkLoop(options) {
|
|
|
971
1058
|
// Made again when the spec, the tests or the code it was planned against moved: what the tests are written for
|
|
972
1059
|
// follows the code, and a plan made before a code pulse landed would test it as it was.
|
|
973
1060
|
if (existing === undefined || existing.specKey !== specKey || existing.from !== testedKey || existing.codeKey !== codeKeyOf(state) || existing.jobs.length === 0) {
|
|
1061
|
+
if (!mayPlan) {
|
|
1062
|
+
state.conformancePlan = undefined;
|
|
1063
|
+
state.why = LOOK_AGAIN;
|
|
1064
|
+
return;
|
|
1065
|
+
}
|
|
974
1066
|
state.conformancePlan = { specKey, from: testedKey, codeKey: codeKeyOf(state), jobs: (await planIdle(state, spec, tested, "conformance")).jobs };
|
|
975
1067
|
}
|
|
976
1068
|
const next = state.conformancePlan.jobs[0];
|
|
@@ -1000,6 +1092,11 @@ export function createWorkLoop(options) {
|
|
|
1000
1092
|
const fromKey = serializeTree(from);
|
|
1001
1093
|
const steeringKey = steeringKeyOf(state);
|
|
1002
1094
|
if (state.plan === undefined || state.plan.specKey !== specKey || state.plan.from !== fromKey || state.plan.steeringKey !== steeringKey || state.plan.jobs.length === 0) {
|
|
1095
|
+
if (!mayPlan) {
|
|
1096
|
+
state.plan = undefined;
|
|
1097
|
+
state.why = LOOK_AGAIN;
|
|
1098
|
+
return;
|
|
1099
|
+
}
|
|
1003
1100
|
const { jobs, notes } = await planIdle(state, spec, from, "code");
|
|
1004
1101
|
state.plan = { specKey, from: fromKey, steeringKey, jobs, notes };
|
|
1005
1102
|
if (jobs.length === 0) {
|
|
@@ -1015,6 +1112,17 @@ export function createWorkLoop(options) {
|
|
|
1015
1112
|
startJob(state, spec, from, state.plan.jobs[0]);
|
|
1016
1113
|
};
|
|
1017
1114
|
const statusOf = (state) => describe(state).status;
|
|
1115
|
+
/** A planned row's codebase and its place there, from its id - `planned-<module>-N`, the longest module name it starts with, as a name may hold a hyphen. */
|
|
1116
|
+
const rowOf = (rowId) => {
|
|
1117
|
+
const state = order
|
|
1118
|
+
.map((key) => modules.get(key))
|
|
1119
|
+
.filter((candidate) => rowId.startsWith(`planned-${tipEntry(candidate).moduleName}-`))
|
|
1120
|
+
.sort((a, b) => tipEntry(b).moduleName.length - tipEntry(a).moduleName.length)[0];
|
|
1121
|
+
if (state === undefined)
|
|
1122
|
+
return undefined;
|
|
1123
|
+
const rest = rowId.slice(`planned-${tipEntry(state).moduleName}-`.length);
|
|
1124
|
+
return /^[1-9]\d*$/.test(rest) ? { state, index: Number(rest) } : undefined;
|
|
1125
|
+
};
|
|
1018
1126
|
/** The modules asked for that the loop holds nothing of yet - turri just opened, say: their code being planned all the same. */
|
|
1019
1127
|
const preparingAlone = () => {
|
|
1020
1128
|
const held = new Set(order.map((key) => tipEntry(modules.get(key)).moduleName));
|
|
@@ -1028,7 +1136,7 @@ export function createWorkLoop(options) {
|
|
|
1028
1136
|
}));
|
|
1029
1137
|
};
|
|
1030
1138
|
/** A codebase's status, and beside each job it lists as planned, the planned job it is - none for one being planned or scheduled. */
|
|
1031
|
-
const describe = (state) =>
|
|
1139
|
+
const describe = (state) => withModuleConfig(state, () => describeIn(state));
|
|
1032
1140
|
const describeIn = (state) => {
|
|
1033
1141
|
// What runs next: the code's jobs, then the conformance tests' - the module's, once its code is built - the running job first.
|
|
1034
1142
|
const running = state.running?.planned;
|
|
@@ -1084,7 +1192,7 @@ export function createWorkLoop(options) {
|
|
|
1084
1192
|
plainFile: tip.plainFile,
|
|
1085
1193
|
...(base !== undefined ? { base } : {}),
|
|
1086
1194
|
...(renames.length > 0 ? { renames: renames.map(renameText) } : {}),
|
|
1087
|
-
...(state.
|
|
1195
|
+
...(state.configModule?.name !== undefined ? { configModule: state.configModule.name } : {}),
|
|
1088
1196
|
...(state.running !== undefined
|
|
1089
1197
|
? {
|
|
1090
1198
|
running: {
|
|
@@ -1103,10 +1211,10 @@ export function createWorkLoop(options) {
|
|
|
1103
1211
|
return { status, jobs: shown.map((item) => item.job), ahead: shown.map((item) => (item.entry.afterCode === true ? { title: item.entry.title, specs: item.entry.specs ?? [] } : undefined)) };
|
|
1104
1212
|
};
|
|
1105
1213
|
/**
|
|
1106
|
-
* Look after a codebase - its chain up to it - from now on; says its state.
|
|
1107
|
-
*
|
|
1214
|
+
* Look after a codebase - its chain up to it - from now on; says its state. Its config is worked out again - its tip's
|
|
1215
|
+
* (`configModuleFor`): `asked`, one that cannot be told refuses the ask; otherwise it keeps the one it had.
|
|
1108
1216
|
*/
|
|
1109
|
-
const track = (chain, askedFile, request,
|
|
1217
|
+
const track = (chain, askedFile, request, asked = false) => {
|
|
1110
1218
|
const tip = tipOf(chain);
|
|
1111
1219
|
let state = modules.get(tip.buildDir);
|
|
1112
1220
|
if (state === undefined) {
|
|
@@ -1121,12 +1229,15 @@ export function createWorkLoop(options) {
|
|
|
1121
1229
|
}
|
|
1122
1230
|
state.chain = chain;
|
|
1123
1231
|
state.askedFile = askedFile;
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1232
|
+
try {
|
|
1233
|
+
state.configModule = { name: configModuleFor(tip.plainFile) };
|
|
1234
|
+
}
|
|
1235
|
+
catch (error) {
|
|
1236
|
+
if (asked)
|
|
1237
|
+
throw error;
|
|
1238
|
+
}
|
|
1239
|
+
// Its model as its config has it: a module's own file can name a coding model of its own.
|
|
1240
|
+
const model = request.model ?? withModuleConfig(state, () => options.modelFor?.(tip.plainFile));
|
|
1130
1241
|
if (model !== undefined)
|
|
1131
1242
|
state.model = model;
|
|
1132
1243
|
if (request.guidance !== undefined && !state.guidance.includes(request.guidance))
|
|
@@ -1135,29 +1246,91 @@ export function createWorkLoop(options) {
|
|
|
1135
1246
|
};
|
|
1136
1247
|
const loop = {
|
|
1137
1248
|
async bringUp(plainFile, given = {}) {
|
|
1138
|
-
|
|
1139
|
-
|
|
1249
|
+
// Asked for, it shows as being planned at once.
|
|
1250
|
+
return preparingFor(plainFile, async () => {
|
|
1140
1251
|
const files = codebasesOf(resolve(options.cwd, plainFile));
|
|
1141
|
-
for (const file of files)
|
|
1142
|
-
asked.set(file, { ...asked.get(file), ...
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
const states = withParseCache(() => files.flatMap((file) => chainsFor(file).flatMap((chain) => toBuild(chain).map((entry) => track(chain.slice(0, chain.indexOf(entry) + 1), file,
|
|
1147
|
-
// Asked again, a halted codebase is tried again - one the person halted too
|
|
1252
|
+
for (const file of files) {
|
|
1253
|
+
asked.set(file, { ...ahead.get(file), ...asked.get(file), ...given });
|
|
1254
|
+
ahead.delete(file);
|
|
1255
|
+
}
|
|
1256
|
+
// Asked for, its config is worked out - its own file, or one of a module it requires - and pinned to its pulses.
|
|
1257
|
+
const states = withParseCache(() => files.flatMap((file) => chainsFor(file).flatMap((chain) => toBuild(chain).map((entry) => track(chain.slice(0, chain.indexOf(entry) + 1), file, given, true)))));
|
|
1258
|
+
// Asked again, a halted codebase is tried again - one the person halted too. Looked ahead at, its kept plan starts.
|
|
1148
1259
|
for (const state of states) {
|
|
1149
1260
|
state.halted = undefined;
|
|
1150
|
-
|
|
1151
|
-
|
|
1261
|
+
state.held = undefined;
|
|
1262
|
+
state.lookedAhead = undefined;
|
|
1152
1263
|
// Asked for again: its conformance tests are written for every functional spec with scenarios, not only those conform named.
|
|
1153
|
-
|
|
1154
|
-
state.conformanceOnly = undefined;
|
|
1264
|
+
state.conformanceOnly = undefined;
|
|
1155
1265
|
}
|
|
1156
1266
|
await tick();
|
|
1157
1267
|
return [...new Set(states)].map(statusOf);
|
|
1158
|
-
};
|
|
1159
|
-
|
|
1160
|
-
|
|
1268
|
+
});
|
|
1269
|
+
},
|
|
1270
|
+
async lookAhead(plainFile, given = {}) {
|
|
1271
|
+
// Being planned, it shows so at once; what is planned is said once it is - not as being planned.
|
|
1272
|
+
const states = await preparingFor(plainFile, async () => {
|
|
1273
|
+
const files = codebasesOf(resolve(options.cwd, plainFile));
|
|
1274
|
+
for (const file of files)
|
|
1275
|
+
if (!asked.has(file))
|
|
1276
|
+
ahead.set(file, { ...ahead.get(file), ...given });
|
|
1277
|
+
// Its config pinned as an ask pins it: the plan is made, and its pulses run, with the config regenerate would use.
|
|
1278
|
+
const tracked = withParseCache(() => files.flatMap((file) => chainsFor(file).flatMap((chain) => toBuild(chain).map((entry) => track(chain.slice(0, chain.indexOf(entry) + 1), file, given, true)))));
|
|
1279
|
+
// A chain with a pulse running is being built as asked, and goes on; every other codebase is held - one asked for
|
|
1280
|
+
// earlier too, which would otherwise start the work the look ahead plans.
|
|
1281
|
+
const building = (state) => state.chain.some((entry) => modules.get(entry.buildDir)?.running !== undefined);
|
|
1282
|
+
for (const state of tracked) {
|
|
1283
|
+
if (!building(state))
|
|
1284
|
+
state.lookedAhead = true;
|
|
1285
|
+
planningAhead.add(state);
|
|
1286
|
+
}
|
|
1287
|
+
try {
|
|
1288
|
+
await tick();
|
|
1289
|
+
}
|
|
1290
|
+
finally {
|
|
1291
|
+
for (const state of tracked)
|
|
1292
|
+
planningAhead.delete(state);
|
|
1293
|
+
}
|
|
1294
|
+
return tracked;
|
|
1295
|
+
});
|
|
1296
|
+
return [...new Set(states)].map(statusOf);
|
|
1297
|
+
},
|
|
1298
|
+
async plannedPulse(rowId) {
|
|
1299
|
+
const found = rowOf(rowId);
|
|
1300
|
+
if (found === undefined)
|
|
1301
|
+
return undefined;
|
|
1302
|
+
const { state, index } = found;
|
|
1303
|
+
const { status, jobs } = describe(state);
|
|
1304
|
+
const entry = status.planned[index - 1];
|
|
1305
|
+
if (entry === undefined)
|
|
1306
|
+
return undefined;
|
|
1307
|
+
const tip = tipEntry(state);
|
|
1308
|
+
const pulse = { id: rowId, module: tip.moduleName, plainFile: tip.plainFile, title: entry.title, track: entry.track, cases: entry.cases, index, lookedAhead: state.lookedAhead === true };
|
|
1309
|
+
const job = jobs[index - 1];
|
|
1310
|
+
const why = (text) => ({ ...pulse, why: text });
|
|
1311
|
+
if (entry.planning === true)
|
|
1312
|
+
return why("It is being planned now: its prompt is built once the plan is made.");
|
|
1313
|
+
if (entry.afterCode === true || job === undefined)
|
|
1314
|
+
return why("It is not planned yet: the conformance tests are planned into pulses once the module's code is built, and their prompt is built from that code.");
|
|
1315
|
+
if (state.running !== undefined)
|
|
1316
|
+
return why(`Pulse ${state.running.jobId} is running in this codebase: what this pulse is given depends on what that one lands.`);
|
|
1317
|
+
if (index > 1)
|
|
1318
|
+
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.`);
|
|
1319
|
+
if (job.track === "conformance")
|
|
1320
|
+
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.");
|
|
1321
|
+
// The plan as kept, and only while it fits the ***plain and the steering as they are now - else regenerate would plan again.
|
|
1322
|
+
let spec;
|
|
1323
|
+
try {
|
|
1324
|
+
spec = chainSpec(state.chain);
|
|
1325
|
+
}
|
|
1326
|
+
catch (error) {
|
|
1327
|
+
return why(`Its ***plain does not parse now: ${error instanceof Error ? error.message : String(error)}`);
|
|
1328
|
+
}
|
|
1329
|
+
if (state.plan === undefined || !state.plan.jobs.includes(job) || state.plan.specKey !== keyOf(spec) || state.plan.steeringKey !== steeringKeyOf(state)) {
|
|
1330
|
+
return why("The ***plain or the steering changed since it was planned: regenerate would plan it again. Look ahead again to see the new plan.");
|
|
1331
|
+
}
|
|
1332
|
+
const task = await withModuleConfig(state, () => promptOf({ plainFile: tip.plainFile, spec: { ...spec, tree: job.step.tree }, planned: job }));
|
|
1333
|
+
return task !== undefined ? { ...pulse, task } : why("It has no prompt to show.");
|
|
1161
1334
|
},
|
|
1162
1335
|
async regenerateAgain(plainFile, given, request = {}) {
|
|
1163
1336
|
return preparingFor(plainFile, async () => {
|
|
@@ -1215,7 +1388,7 @@ export function createWorkLoop(options) {
|
|
|
1215
1388
|
const tip = tipOf(codebase);
|
|
1216
1389
|
// The codebase as the loop knows it, or - never asked for - as its records have it.
|
|
1217
1390
|
const state = modules.get(tip.buildDir) ?? { chain: codebase, askedFile: file, guidance: [] };
|
|
1218
|
-
return
|
|
1391
|
+
return withModuleConfig(state, () => {
|
|
1219
1392
|
const report = { module: tip.moduleName, plainFile: tip.plainFile, code: undefined, conformance: undefined, ...(conformanceTestsOn(tip.plainFile) ? {} : { conformanceOff: true }) };
|
|
1220
1393
|
let spec;
|
|
1221
1394
|
try {
|
|
@@ -1271,7 +1444,8 @@ export function createWorkLoop(options) {
|
|
|
1271
1444
|
},
|
|
1272
1445
|
async conformance(plainFile, request = {}) {
|
|
1273
1446
|
const file = resolve(options.cwd, plainFile);
|
|
1274
|
-
asked.set(file, { ...asked.get(file), ...(request.model !== undefined ? { model: request.model } : {}) });
|
|
1447
|
+
asked.set(file, { ...ahead.get(file), ...asked.get(file), ...(request.model !== undefined ? { model: request.model } : {}) });
|
|
1448
|
+
ahead.delete(file);
|
|
1275
1449
|
const own = resolveRequiresChain(file, [], undefined, { allowNoFunctionalities: true });
|
|
1276
1450
|
const self = tipOf(own);
|
|
1277
1451
|
// What the person asks for comes first. Its tests are written in its own codebase, before anything is built on it:
|
|
@@ -1280,14 +1454,24 @@ export function createWorkLoop(options) {
|
|
|
1280
1454
|
// it has, nothing is touched.
|
|
1281
1455
|
if (!conformanceTestsOn(self.plainFile)) {
|
|
1282
1456
|
throw new Error(`Conformance tests are off for ${self.moduleName} (conformance-tests: false, or unset): nothing is conformance tested. ` +
|
|
1283
|
-
"
|
|
1457
|
+
"/conform in the chat turns them on, or conformance-tests: true in config.turri.yaml. Nothing was started.");
|
|
1284
1458
|
}
|
|
1285
1459
|
// Refused before anything is touched: a functional spec not there, nothing to test, or a step of adding tests skipped.
|
|
1286
1460
|
const { named, spec: ownSpec, withScenarios } = conformanceAskedIn(own, request.funcIds);
|
|
1461
|
+
const scratch = request.fromScratch;
|
|
1462
|
+
if (scratch !== undefined && named !== undefined && named.length > 0) {
|
|
1463
|
+
throw new Error("Name functional specs or ask for the conformance tests from scratch, not both: from scratch writes every one of them again. Nothing was started.");
|
|
1464
|
+
}
|
|
1465
|
+
// Written already, and asked for again: the named ones written anew where they are tested; from scratch, the module's
|
|
1466
|
+
// tests folder taken out - and started again from the module it requires, unless the whole chain's are asked for.
|
|
1467
|
+
const again = named !== undefined && named.length > 0 ? conformAgain(file, self, named) : [];
|
|
1468
|
+
if (scratch !== undefined)
|
|
1469
|
+
testsFromScratch(file, scratch === "module");
|
|
1287
1470
|
const tested = new Set((readRecord(conformanceDirFor(self.moduleName, modulesRoot(projectDirOf(self.plainFile))))?.[FUNCTIONAL_REQUIREMENTS] ?? []).map((item) => item.id));
|
|
1288
1471
|
const toWrite = (named !== undefined && named.length > 0 ? named : withScenarios).some((funcId) => !tested.has(funcId));
|
|
1289
1472
|
let wentBack = false;
|
|
1290
|
-
|
|
1473
|
+
// From scratch, the tests are written again at the tips, where they were: nothing built on the module is touched.
|
|
1474
|
+
if (scratch === undefined && readRecord(self.buildDir) !== null && toWrite) {
|
|
1291
1475
|
const why = `${self.moduleName}'s conformance tests were asked for, and they come before anything is built on it`;
|
|
1292
1476
|
for (const chain of builtTips(file)) {
|
|
1293
1477
|
const above = chain.slice(chain.findIndex((entry) => entry.buildDir === self.buildDir) + 1);
|
|
@@ -1311,14 +1495,17 @@ export function createWorkLoop(options) {
|
|
|
1311
1495
|
}
|
|
1312
1496
|
}
|
|
1313
1497
|
}
|
|
1314
|
-
const tracked = withParseCache(() => (wentBack ? [own] : chainsFor(file)).flatMap((chain) => toBuild(chain).map((entry) => track(chain.slice(0, chain.indexOf(entry) + 1), file, request,
|
|
1498
|
+
const tracked = withParseCache(() => (wentBack ? [own] : chainsFor(file)).flatMap((chain) => toBuild(chain).map((entry) => track(chain.slice(0, chain.indexOf(entry) + 1), file, request, true))));
|
|
1315
1499
|
// The module asked for, in its own codebase - and those below it: never the codebases built on it.
|
|
1316
1500
|
const asking = tracked.find((state) => tipEntry(state).buildDir === self.buildDir);
|
|
1317
1501
|
const states = asking !== undefined ? tracked.filter((state) => own.some((entry) => entry.buildDir === tipEntry(state).buildDir)) : tracked;
|
|
1318
1502
|
const tip = asking ?? states.at(-1);
|
|
1503
|
+
// Asked for: what a look ahead held here goes on - the modules below with it, or the module waits for them for ever.
|
|
1504
|
+
for (const state of tracked)
|
|
1505
|
+
state.lookedAhead = undefined;
|
|
1319
1506
|
const asks = named !== undefined && named.length > 0 ? named : undefined;
|
|
1320
1507
|
// Its tests are written already, and a codebase built on it holds its code: nothing to write, nothing touched.
|
|
1321
|
-
if (asking === undefined && asks !== undefined && tip !== undefined) {
|
|
1508
|
+
if (asking === undefined && asks !== undefined && tip !== undefined && again.length === 0) {
|
|
1322
1509
|
throw new Error(`${self.moduleName}'s conformance tests for ${namesOf(self.moduleName, asks)} are written already. Nothing was started.`);
|
|
1323
1510
|
}
|
|
1324
1511
|
// Only the module asked for: one job for all of its tests, or one a functional spec, as this request asks; a halt cleared.
|
|
@@ -1328,7 +1515,7 @@ export function createWorkLoop(options) {
|
|
|
1328
1515
|
state.conformancePlan = undefined;
|
|
1329
1516
|
state.conformanceSeparately = separately;
|
|
1330
1517
|
// Named: their tests alone - the others left as they are until the module is asked for again, or conform names none.
|
|
1331
|
-
state.conformanceOnly = asks !== undefined ? namedOnly(state, asks) : undefined;
|
|
1518
|
+
state.conformanceOnly = asks !== undefined ? namedOnly(state, asks, self.moduleName) : undefined;
|
|
1332
1519
|
state.conformancePlan = undefined;
|
|
1333
1520
|
state.conformanceHalted = undefined;
|
|
1334
1521
|
state.halted = undefined;
|
|
@@ -1468,12 +1655,15 @@ export function createWorkLoop(options) {
|
|
|
1468
1655
|
let before = status.running?.jobId;
|
|
1469
1656
|
if (before !== undefined)
|
|
1470
1657
|
lastOf.set(tip.moduleName, before);
|
|
1658
|
+
// Looked ahead at: every row of it says it waits for the module to be asked for.
|
|
1659
|
+
const held = state.lookedAhead === true && state.running === undefined;
|
|
1471
1660
|
const row = (id, summary, note, waitingOn, conformance = false) => ({
|
|
1472
1661
|
id,
|
|
1473
1662
|
kind: conformance ? "conformance" : "regenerate",
|
|
1474
1663
|
summary,
|
|
1475
1664
|
module: tip.moduleName,
|
|
1476
|
-
note,
|
|
1665
|
+
note: held ? `${LOOKED_AHEAD_NOTE} ${note}` : note,
|
|
1666
|
+
...(held ? { lookedAhead: true } : {}),
|
|
1477
1667
|
...(state.model !== undefined ? { model: state.model } : {}),
|
|
1478
1668
|
status: "queued",
|
|
1479
1669
|
sequence: sequence--,
|
|
@@ -1509,16 +1699,9 @@ export function createWorkLoop(options) {
|
|
|
1509
1699
|
});
|
|
1510
1700
|
})];
|
|
1511
1701
|
},
|
|
1512
|
-
firsts() {
|
|
1513
|
-
return order.flatMap((key) => {
|
|
1514
|
-
const first = firsts.get(key);
|
|
1515
|
-
const tip = tipEntry(modules.get(key));
|
|
1516
|
-
return first === undefined ? [] : [{ module: tip.moduleName, plainFile: tip.plainFile, buildDir: tip.buildDir, ...first }];
|
|
1517
|
-
});
|
|
1518
|
-
},
|
|
1519
1702
|
mapPlan() {
|
|
1520
1703
|
return {
|
|
1521
|
-
files: [...asked.keys()],
|
|
1704
|
+
files: [...asked.keys(), ...[...ahead.keys()].filter((file) => !asked.has(file))],
|
|
1522
1705
|
codebases: order.map((key) => {
|
|
1523
1706
|
const state = modules.get(key);
|
|
1524
1707
|
const tip = tipEntry(state);
|
|
@@ -1580,6 +1763,12 @@ function oldCodebases(chain) {
|
|
|
1580
1763
|
const OLD_RECORDS_WHY = (codebases) => `${codebases.join(", ")} ${codebases.length === 1 ? "was" : "were"} built when functional specs were numbered, before they had func-ids: nothing more is built on ${codebases.length === 1 ? "it" : "them"} - the whole chain is regenerated from scratch once you agree`;
|
|
1581
1764
|
/** Why nothing runs in a codebase whose code - and conformance tests, where they are wanted - is built from its spec as it is. */
|
|
1582
1765
|
export const UP_TO_DATE = "built from the ***plain as it is";
|
|
1766
|
+
/** Why nothing starts in a codebase a look ahead planned: its pulses wait for the module to be asked for. */
|
|
1767
|
+
const LOOKED_AHEAD = "looked ahead - planned, and nothing starts until regenerate, conform or /regenerate asks for it";
|
|
1768
|
+
/** What a planned row of a codebase a look ahead planned says first. */
|
|
1769
|
+
const LOOKED_AHEAD_NOTE = "Planned by a look ahead: it waits for regenerate, conform or /regenerate to start it.";
|
|
1770
|
+
/** Why a codebase held for a look ahead has no plan: its ***plain or steering moved since, and only a look ahead plans it. */
|
|
1771
|
+
const LOOK_AGAIN = "looked ahead, and the ***plain or the steering changed since - look ahead again to plan it, or regenerate it";
|
|
1583
1772
|
/** Why a codebase with work left has no plan: the planner found none. */
|
|
1584
1773
|
/** Why a codebase waits for a testing script being written in the background. */
|
|
1585
1774
|
const SCRIPT_BEING_WRITTEN = (what) => `waiting for its ${what}, which is being written`;
|
|
@@ -1625,6 +1814,7 @@ function conformanceLines(module, cases) {
|
|
|
1625
1814
|
...(spec.added.length > 0 ? [`${spec.added.length} added`] : []),
|
|
1626
1815
|
...(spec.changed.length > 0 ? [`${spec.changed.length} changed`] : []),
|
|
1627
1816
|
...(spec.removed.length > 0 ? [`${spec.removed.length} removed`] : []),
|
|
1817
|
+
...(spec.rewritten.length > 0 ? [`written again from scratch - ${spec.rewritten.length} to write anew`] : []),
|
|
1628
1818
|
...(spec.codeChanged !== undefined ? [`${why[spec.codeChanged]} - ${spec.unchanged.length} to run on it`] : []),
|
|
1629
1819
|
];
|
|
1630
1820
|
return parts.length > 0 ? parts.join(", ") : "its text changed";
|
|
@@ -1677,9 +1867,11 @@ function conformanceAskedIn(own, funcIds) {
|
|
|
1677
1867
|
const named = funcIds === undefined ? undefined : funcIdsNamed(self.moduleName, [...new Set(funcIds)]);
|
|
1678
1868
|
const spec = chainSpec(own).tree;
|
|
1679
1869
|
const withScenarios = testedFuncIds(spec);
|
|
1870
|
+
// No scenarios: the steps still to take, from the first one missing - the test reqs and the script come before them.
|
|
1871
|
+
const toScenarios = () => stepsToScenarios({ moduleName: self.moduleName, plainFile: self.plainFile, tree: spec, buildDir: self.buildDir });
|
|
1680
1872
|
if (withScenarios.length === 0) {
|
|
1681
|
-
throw new Error(`No functional spec of ${self.moduleName} has scenarios - none has a test plain file - so there is nothing to test
|
|
1682
|
-
"
|
|
1873
|
+
throw new Error(`No functional spec of ${self.moduleName} has scenarios - none has a test plain file - so there is nothing to test. ${toScenarios()} ` +
|
|
1874
|
+
"Their tests are written once the code is built. Nothing was started.");
|
|
1683
1875
|
}
|
|
1684
1876
|
if (named !== undefined && named.length > 0) {
|
|
1685
1877
|
const items = spec[FUNCTIONAL_REQUIREMENTS] ?? [];
|
|
@@ -1688,11 +1880,11 @@ function conformanceAskedIn(own, funcIds) {
|
|
|
1688
1880
|
throw new Error(`${self.moduleName} has no functional spec ${namesOf(self.moduleName, unknown)}. Nothing was started.`);
|
|
1689
1881
|
const untested = named.filter((funcId) => !hasScenarios(items.find((item) => item.id === funcId)));
|
|
1690
1882
|
if (untested.length > 0) {
|
|
1691
|
-
throw new Error(`${namesOf(self.moduleName, untested)} ${untested.length === 1 ? "has" : "have"} no scenarios - no test plain file - so there is nothing to test
|
|
1692
|
-
"
|
|
1883
|
+
throw new Error(`${namesOf(self.moduleName, untested)} ${untested.length === 1 ? "has" : "have"} no scenarios - no test plain file - so there is nothing to test. ${toScenarios()} ` +
|
|
1884
|
+
"Their tests are written once the code is built. Nothing was started.");
|
|
1693
1885
|
}
|
|
1694
1886
|
}
|
|
1695
|
-
// A step of adding tests skipped - its test reqs, or the conformance testing script
|
|
1887
|
+
// A step of adding tests skipped - its test reqs, or the conformance testing script: refused, naming it.
|
|
1696
1888
|
const gap = testingGap({ moduleName: self.moduleName, plainFile: self.plainFile, tree: spec, buildDir: self.buildDir });
|
|
1697
1889
|
if (gap !== undefined)
|
|
1698
1890
|
throw new Error(`${gap.text} Nothing was started.`);
|
|
@@ -1723,54 +1915,24 @@ function casesText(cases) {
|
|
|
1723
1915
|
];
|
|
1724
1916
|
return parts.length > 0 ? parts.join(", ") : "no functional spec - reqs or definitions only";
|
|
1725
1917
|
}
|
|
1726
|
-
/** The codebases the loop looks after, as the person reads them: what runs, what is planned after it, and why nothing does. */
|
|
1727
1918
|
/**
|
|
1728
|
-
* The coding agent's task for a
|
|
1729
|
-
* a conformance
|
|
1919
|
+
* The coding agent's task for a planned code pulse, built as the pulse builds it - with `spec` the ***plain the pulse
|
|
1920
|
+
* would be given - and all it did rolled back. Not for a conformance pulse: its prompt is built from what the code holds
|
|
1921
|
+
* once it is built.
|
|
1730
1922
|
*/
|
|
1731
|
-
|
|
1732
|
-
if (
|
|
1923
|
+
async function promptOf(next) {
|
|
1924
|
+
if (next.planned.track !== "code")
|
|
1733
1925
|
return undefined;
|
|
1734
1926
|
const result = await renderSpecDiff({
|
|
1735
|
-
plainFile:
|
|
1736
|
-
diff:
|
|
1927
|
+
plainFile: next.plainFile,
|
|
1928
|
+
diff: next.planned.step.textDiff,
|
|
1737
1929
|
applied: "already applied",
|
|
1738
|
-
spec:
|
|
1739
|
-
cases:
|
|
1930
|
+
spec: next.spec,
|
|
1931
|
+
cases: next.planned.cases,
|
|
1740
1932
|
dryRun: true,
|
|
1741
1933
|
});
|
|
1742
1934
|
return result.task;
|
|
1743
1935
|
}
|
|
1744
|
-
/**
|
|
1745
|
-
* What bringing a spec's module up would start, in each codebase, and the prompt of each - planned on a loop of its own
|
|
1746
|
-
* that starts nothing. A codebase `busy` says is running a job is left out: a dry run starts from its last commit, and
|
|
1747
|
-
* what the next job there is given depends on what the running one lands.
|
|
1748
|
-
*/
|
|
1749
|
-
export async function previewJobs(options) {
|
|
1750
|
-
const loop = createWorkLoop({
|
|
1751
|
-
registry: createJobRegistry(),
|
|
1752
|
-
cwd: options.cwd,
|
|
1753
|
-
dryRun: true,
|
|
1754
|
-
...(options.model !== undefined ? { modelFor: () => options.model } : {}),
|
|
1755
|
-
...(options.plannerModel !== undefined ? { plannerModel: options.plannerModel } : {}),
|
|
1756
|
-
...(options.steering !== undefined ? { steering: options.steering } : {}),
|
|
1757
|
-
});
|
|
1758
|
-
const statuses = await loop.bringUp(options.plainFile, options.model !== undefined ? { model: options.model } : {});
|
|
1759
|
-
const previews = [];
|
|
1760
|
-
const busy = [];
|
|
1761
|
-
for (const first of loop.firsts()) {
|
|
1762
|
-
if (options.busy?.(first.module) === true) {
|
|
1763
|
-
busy.push(first.module);
|
|
1764
|
-
continue;
|
|
1765
|
-
}
|
|
1766
|
-
const preview = { module: first.module, title: first.planned.title, track: first.planned.track, cases: first.planned.cases };
|
|
1767
|
-
const task = await promptOf(first);
|
|
1768
|
-
if (task !== undefined)
|
|
1769
|
-
preview.task = task;
|
|
1770
|
-
previews.push(preview);
|
|
1771
|
-
}
|
|
1772
|
-
return { statuses, previews, busy };
|
|
1773
|
-
}
|
|
1774
1936
|
/** Nothing runs, is planned or is waiting there, as its code is built from its spec as it is. */
|
|
1775
1937
|
export function isUpToDate(status) {
|
|
1776
1938
|
return status.why === UP_TO_DATE && status.running === undefined && status.planned.length === 0 && status.startOver === undefined;
|
|
@@ -1806,7 +1968,7 @@ export function describeModules(statuses, options = {}) {
|
|
|
1806
1968
|
// Nothing to do there: said in a sentence, not as a status.
|
|
1807
1969
|
if (isUpToDate(status))
|
|
1808
1970
|
return `${status.module} is up to date: its code is built from the ***plain as it is now in ${basename(status.plainFile)}, so there is nothing to regenerate.`;
|
|
1809
|
-
const lines = [`${status.module} (${basename(status.plainFile)}${status.
|
|
1971
|
+
const lines = [`${status.module} (${basename(status.plainFile)}${status.configModule !== undefined ? `, built with ${moduleConfigFile(status.configModule)}` : ""}):`];
|
|
1810
1972
|
if (status.running !== undefined) {
|
|
1811
1973
|
lines.push(` running: pulse ${status.running.jobId} - ${status.running.title}`);
|
|
1812
1974
|
// Steered, not stopped or planned again: what changed went to its agent.
|
|
@@ -1822,8 +1984,11 @@ export function describeModules(statuses, options = {}) {
|
|
|
1822
1984
|
: ` ${index + 1}. ${job.track === "conformance" ? "conformance tests: " : ""}${job.title} - ${casesText(job.cases)}`));
|
|
1823
1985
|
if (status.planNotes !== undefined)
|
|
1824
1986
|
lines.push(" what the plan did not do as asked:", ...status.planNotes.map((note) => ` - ${note}`));
|
|
1987
|
+
// A look ahead from the command line keeps its plan only while the process lives: the run that starts it plans again.
|
|
1825
1988
|
if (status.why !== undefined)
|
|
1826
|
-
lines.push(
|
|
1989
|
+
lines.push(options.for === "command line" && status.why === LOOKED_AHEAD
|
|
1990
|
+
? ` looked ahead - planned, nothing started: turri regenerate ${basename(status.plainFile)} runs it, planning it again as it starts`
|
|
1991
|
+
: ` ${status.why}`);
|
|
1827
1992
|
if (status.conformanceNote !== undefined)
|
|
1828
1993
|
lines.push(` ${status.conformanceNote}`);
|
|
1829
1994
|
lines.push(...startOver(status));
|