@turri-dev/cli 0.2.3 → 0.2.4-next.009bd0c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/README.md +7 -8
  2. package/dist/bedrock-region.js +3 -3
  3. package/dist/chat-idle.d.ts +2 -2
  4. package/dist/chat-idle.js +2 -2
  5. package/dist/chat-models.d.ts +1 -1
  6. package/dist/chat-models.js +1 -1
  7. package/dist/chat-scope.d.ts +1 -3
  8. package/dist/chat-skills.d.ts +1 -1
  9. package/dist/chat-skills.js +1 -1
  10. package/dist/chats.d.ts +44 -20
  11. package/dist/chats.js +125 -64
  12. package/dist/cli.js +12 -31
  13. package/dist/config-edit.d.ts +20 -8
  14. package/dist/config-edit.js +32 -26
  15. package/dist/config.d.ts +106 -78
  16. package/dist/config.js +267 -133
  17. package/dist/conform-cli.js +14 -3
  18. package/dist/conformance-switch.d.ts +13 -22
  19. package/dist/conformance-switch.js +37 -59
  20. package/dist/drift-cli.js +1 -1
  21. package/dist/extension.d.ts +17 -10
  22. package/dist/extension.js +425 -531
  23. package/dist/genome.js +10 -49
  24. package/dist/graph.js +3 -5
  25. package/dist/host-session.d.ts +11 -21
  26. package/dist/host-session.js +6 -8
  27. package/dist/host.d.ts +4 -4
  28. package/dist/host.js +4 -7
  29. package/dist/identity.js +2 -3
  30. package/dist/init-config.d.ts +1 -2
  31. package/dist/init-config.js +10 -17
  32. package/dist/installed-providers.d.ts +1 -1
  33. package/dist/installed-providers.js +1 -1
  34. package/dist/launch-agent.d.ts +41 -0
  35. package/dist/launch-agent.js +219 -0
  36. package/dist/{release-cli.js → launch-cli.js} +41 -24
  37. package/dist/launch-session.d.ts +58 -0
  38. package/dist/launch-session.js +195 -0
  39. package/dist/launch-tools.d.ts +28 -0
  40. package/dist/launch-tools.js +69 -0
  41. package/dist/launch-track.d.ts +120 -0
  42. package/dist/launch-track.js +298 -0
  43. package/dist/loop-cli.d.ts +4 -3
  44. package/dist/loop-cli.js +17 -15
  45. package/dist/loop-tools.d.ts +45 -21
  46. package/dist/loop-tools.js +155 -90
  47. package/dist/new-project.js +2 -2
  48. package/dist/notice.d.ts +7 -6
  49. package/dist/parse-cli.js +2 -2
  50. package/dist/pi-launch.js +4 -1
  51. package/dist/pi-settings.d.ts +4 -0
  52. package/dist/pi-settings.js +39 -0
  53. package/dist/pi.js +12 -9
  54. package/dist/plain/check.d.ts +2 -9
  55. package/dist/plain/check.js +6 -39
  56. package/dist/plain-files.d.ts +2 -2
  57. package/dist/plain-files.js +7 -7
  58. package/dist/regenerate/activity.d.ts +0 -7
  59. package/dist/regenerate/activity.js +2 -20
  60. package/dist/regenerate/agent-env.d.ts +1 -1
  61. package/dist/regenerate/agent-env.js +3 -3
  62. package/dist/regenerate/agent-shell.js +5 -3
  63. package/dist/regenerate/audit.js +9 -0
  64. package/dist/regenerate/base-folder.d.ts +2 -2
  65. package/dist/regenerate/base-folder.js +1 -1
  66. package/dist/regenerate/cases.js +7 -0
  67. package/dist/regenerate/chunk-plan.d.ts +5 -0
  68. package/dist/regenerate/chunk-plan.js +16 -1
  69. package/dist/regenerate/command-check.d.ts +1 -1
  70. package/dist/regenerate/command-check.js +1 -1
  71. package/dist/regenerate/delivery.d.ts +1 -1
  72. package/dist/regenerate/delivery.js +3 -3
  73. package/dist/regenerate/drift.d.ts +4 -0
  74. package/dist/regenerate/drift.js +26 -6
  75. package/dist/regenerate/failure-reports.d.ts +28 -0
  76. package/dist/regenerate/failure-reports.js +79 -0
  77. package/dist/regenerate/job-panel.js +3 -1
  78. package/dist/regenerate/jobs-tree.js +1 -1
  79. package/dist/regenerate/jobs.d.ts +4 -2
  80. package/dist/regenerate/jobs.js +14 -10
  81. package/dist/regenerate/launch.d.ts +126 -0
  82. package/dist/regenerate/{release.js → launch.js} +60 -48
  83. package/dist/regenerate/ledger-view.d.ts +11 -24
  84. package/dist/regenerate/ledger-view.js +14 -60
  85. package/dist/regenerate/ledger.d.ts +26 -16
  86. package/dist/regenerate/ledger.js +1 -1
  87. package/dist/regenerate/lineage.d.ts +2 -0
  88. package/dist/regenerate/lineage.js +8 -0
  89. package/dist/regenerate/loop.d.ts +54 -67
  90. package/dist/regenerate/loop.js +312 -148
  91. package/dist/regenerate/model-names.d.ts +33 -0
  92. package/dist/regenerate/{engine.js → model-names.js} +2 -28
  93. package/dist/regenerate/paths.d.ts +3 -3
  94. package/dist/regenerate/paths.js +4 -4
  95. package/dist/regenerate/records.d.ts +11 -0
  96. package/dist/regenerate/records.js +15 -0
  97. package/dist/regenerate/regenerate.d.ts +0 -2
  98. package/dist/regenerate/regenerate.js +4 -15
  99. package/dist/regenerate/renames.js +4 -4
  100. package/dist/regenerate/requires.d.ts +7 -0
  101. package/dist/regenerate/requires.js +24 -18
  102. package/dist/regenerate/scripts-being-written.d.ts +4 -4
  103. package/dist/regenerate/scripts-being-written.js +3 -3
  104. package/dist/regenerate/spec-map.js +3 -3
  105. package/dist/regenerate/standing.js +1 -1
  106. package/dist/regenerate/submit-work.d.ts +2 -0
  107. package/dist/regenerate/submit-work.js +8 -3
  108. package/dist/regenerate/test-scripts.d.ts +2 -1
  109. package/dist/regenerate/test-scripts.js +33 -23
  110. package/dist/regenerate/testing-steps.d.ts +16 -5
  111. package/dist/regenerate/testing-steps.js +28 -9
  112. package/dist/regenerate-cli.js +18 -9
  113. package/dist/self-invocation.d.ts +11 -0
  114. package/dist/self-invocation.js +36 -10
  115. package/dist/sentinel-check.d.ts +3 -3
  116. package/dist/sentinel-check.js +3 -3
  117. package/dist/sentinel.d.ts +17 -12
  118. package/dist/sentinel.js +75 -46
  119. package/dist/{config-command.d.ts → settings.d.ts} +13 -8
  120. package/dist/{config-command.js → settings.js} +155 -24
  121. package/dist/setup.d.ts +2 -2
  122. package/dist/setup.js +7 -7
  123. package/dist/skill.d.ts +0 -11
  124. package/dist/skill.js +0 -9
  125. package/dist/tools.js +2 -3
  126. package/dist/turri-versions.js +2 -1
  127. package/docs/README.md +4 -6
  128. package/docs/authoring-plain.md +3 -3
  129. package/docs/chats.md +6 -9
  130. package/docs/claude-subscription.md +2 -2
  131. package/docs/config.md +61 -51
  132. package/docs/development.md +4 -5
  133. package/docs/headless.md +7 -6
  134. package/docs/hosting.md +24 -23
  135. package/docs/launch.md +63 -0
  136. package/docs/parser.md +3 -3
  137. package/docs/regenerating.md +30 -22
  138. package/docs/sandbox.md +3 -3
  139. package/docs/sentinel.md +27 -16
  140. package/docs/skills-and-gates.md +6 -11
  141. package/docs/using.md +25 -42
  142. package/genome/rules/project-model.md +2 -1
  143. package/genome/rules/test-plain-files.md +15 -7
  144. package/genome/rules/turri-regeneration.md +7 -10
  145. package/genome/skills/convert-old-syntax/SKILL.md +5 -5
  146. package/genome/skills/implement-conformance-testing-script/SKILL.md +2 -2
  147. package/genome/skills/implement-unit-testing-script/SKILL.md +3 -3
  148. package/package.json +1 -1
  149. package/dist/advisor-chat.d.ts +0 -63
  150. package/dist/advisor-chat.js +0 -290
  151. package/dist/change-plain-cli.js +0 -55
  152. package/dist/ledger-cli.d.ts +0 -1
  153. package/dist/ledger-cli.js +0 -50
  154. package/dist/ledger-tools.d.ts +0 -10
  155. package/dist/ledger-tools.js +0 -64
  156. package/dist/regenerate/advisor-records.d.ts +0 -93
  157. package/dist/regenerate/advisor-records.js +0 -110
  158. package/dist/regenerate/advisor-runs.d.ts +0 -87
  159. package/dist/regenerate/advisor-runs.js +0 -327
  160. package/dist/regenerate/engine.d.ts +0 -52
  161. package/dist/regenerate/release.d.ts +0 -121
  162. package/dist/regenerate/test-advisor.d.ts +0 -101
  163. package/dist/regenerate/test-advisor.js +0 -379
  164. package/dist/release-agent.d.ts +0 -43
  165. package/dist/release-agent.js +0 -130
  166. package/dist/release-cli.d.ts +0 -1
  167. package/dist/release-tools.d.ts +0 -44
  168. package/dist/release-tools.js +0 -170
  169. package/dist/spec-tools.d.ts +0 -36
  170. package/dist/spec-tools.js +0 -128
  171. package/dist/stacks.d.ts +0 -13
  172. package/dist/stacks.js +0 -96
  173. package/docs/deploy.md +0 -48
  174. package/docs/test-advisor.md +0 -110
  175. /package/dist/{change-plain-cli.d.ts → launch-cli.d.ts} +0 -0
@@ -6,19 +6,19 @@ import { ACCEPTANCE_TESTS, CONFORMANCE_TESTS, FUNCTIONAL_REQUIREMENTS, REQUIRED_
6
6
  import { testPlainFilesOf } from "../test-plain-files.js";
7
7
  import { reportActivity, reportStage } from "./activity.js";
8
8
  import { llmChunkAgents, MAX_LINES_PER_JOB, MAX_SPECS_PER_JOB, planChunks, stepsOf } from "./chunk-plan.js";
9
- import { commitNotes, landWork, recordHistory, resetToLastCommit } from "./lineage.js";
9
+ import { commitNotes, landWork, lastCommit, recordHistory, resetToLastCommit } from "./lineage.js";
10
10
  import { firstLine, record } from "./ledger.js";
11
11
  import { NOTES_FILE, recordPulse } from "./notes.js";
12
- import { createJobRegistry, formatDuration } from "./jobs.js";
12
+ import { formatDuration } from "./jobs.js";
13
13
  import { moduleLanes } from "./lanes.js";
14
- import { adoptDigests, chainTree, codeTree, conformanceTarget, marksRegenerateAgain, REGENERATE_AGAIN, inheritedRecord, isOldRecord, notBuilt, readRecord, RECORD_FILE, withResourceDigests, writeCodeRecord, writeTestsRecord, hasScenarios, identityOf, testedFuncIds, } from "./records.js";
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, stackForModule, stackPinned, testDirOf, withStack } from "../config.js";
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 { findTestScripts, projectRootFor } from "./test-scripts.js";
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: not conformance tested until rewritten.
212
- const tested = ownItems(testsRecord ?? undefined, entry.moduleName, entry.moduleName === tip.moduleName).filter((item) => item.id !== undefined && !marksRegenerateAgain(item) && reads(item) === specText(entry.moduleName, item.id));
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 stack chosen - the one it was asked for with - when it has one pinned. */
244
- const inStack = (state, work) => (state.stack !== undefined ? withStack(state.stack.name, work) : work());
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 for its stack: no conformance pulse of it starts, in the loop or from conform, and it
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 codebase lacks a testing script of this kind that is being written in the background now: it waits for it,
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
- return scriptBeingWritten(root, kind, stackForModule(tip.plainFile)) && findTestScripts(root, tip.plainFile, tip.buildDir)[kind] === undefined;
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
- /** The functional specs conform named - its own module's func-ids - and every functional spec as it reads now, to tell a change to one after. */
357
- const namedOnly = (state, funcIds) => {
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
- return { specs: new Set(funcIds.map((id) => identityOf({ id }))), read };
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
- const tip = tipEntry(state);
498
- if (options.dryRun === true) {
499
- firsts.set(tip.buildDir, { spec: planned.track === "conformance" ? spec : { ...spec, tree: planned.step.tree }, planned });
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
- inStack(state, () => seedFromBaseFolder(tip.buildDir, tip.plainFile, tip.moduleName));
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,
@@ -561,26 +642,11 @@ export function createWorkLoop(options) {
561
642
  cwd: options.cwd,
562
643
  ...(steering !== undefined ? { steering } : {}),
563
644
  }, onDelta);
564
- const report = result.report;
565
- // Released as its last stage, when the config says so: the module's next pulse starts on what is released.
566
- let released;
567
- if (result.landed && options.release !== undefined && configForSpec(tip.plainFile).releaseAfterPulse === true) {
568
- reportStage(`module ${tip.moduleName}: releasing what this pulse landed (release-after-pulse)`);
569
- try {
570
- released = `Released after the pulse: ${(await options.release({ plainFile: tip.plainFile, moduleName: tip.moduleName, title: planned.title, onDelta })).trim()}`;
571
- }
572
- catch (error) {
573
- // What landed stays landed: a release that fails is said, and the next pulse goes on.
574
- released = `The release after the pulse failed: ${error instanceof Error ? error.message : String(error)}`;
575
- }
576
- reportActivity(` ${released.split("\n")[0]}`);
577
- }
578
645
  return {
579
- report: released !== undefined ? `${report}\n\n${released}` : report,
646
+ report: result.report,
580
647
  details: {
581
648
  passed: result.landed,
582
649
  landed: result.landed,
583
- ...(released !== undefined ? { released: true } : {}),
584
650
  ...(result.story !== undefined ? { story: result.story } : {}),
585
651
  // The spec gaps its agents met, for a headless run to say - in the chat the report puts them to the person.
586
652
  ...(result.specGaps !== undefined && result.specGaps.length > 0 ? { specGaps: result.specGaps } : {}),
@@ -688,6 +754,20 @@ export function createWorkLoop(options) {
688
754
  // What it did, in the notes every agent after reads - once anything it did not land is rolled back, so the line stays.
689
755
  if (running !== undefined)
690
756
  notePulse(state, running, settled, landed);
757
+ // Landed: the commit it ends on, its line in the notes amended in - told before the codebase's next pulse starts.
758
+ if (running !== undefined && settled !== undefined && landed) {
759
+ const tip = tipEntry(state);
760
+ const commit = lastCommit(tip.buildDir);
761
+ if (commit !== undefined) {
762
+ settled.details = { ...settled.details, commit };
763
+ try {
764
+ options.landed?.({ job: settled, plainFile: tip.plainFile, moduleName: tip.moduleName, commit, title: running.planned.title });
765
+ }
766
+ catch {
767
+ /* what is done with a landing is not the loop's to fail on */
768
+ }
769
+ }
770
+ }
691
771
  void tick();
692
772
  };
693
773
  /**
@@ -718,8 +798,8 @@ export function createWorkLoop(options) {
718
798
  * nothing running there - so the code is taken to be built from them, rather than everything linking one built again.
719
799
  */
720
800
  const hashResources = (state, spec) => {
721
- // A dry run only reads.
722
- if (options.dryRun === true)
801
+ // A look ahead only reads.
802
+ if (state.lookedAhead === true)
723
803
  return;
724
804
  const code = tipEntry(state).buildDir;
725
805
  for (const dir of [code, testsDirOf(state)]) {
@@ -749,11 +829,15 @@ export function createWorkLoop(options) {
749
829
  };
750
830
  // 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
831
  onScriptRunEnded(() => {
752
- if (asked.size > 0 && options.dryRun !== true)
832
+ if (asked.size > 0 || ahead.size > 0)
753
833
  void tick();
754
834
  });
755
835
  /** The files asked for, each with how: what the loop brings up, worked out again each look. */
756
836
  const asked = new Map();
837
+ /** The files looked ahead at and not asked for since: their codebases are looked at, their pulses held. */
838
+ const ahead = new Map();
839
+ /** The codebases a look ahead is planning now: the only looks that plan a codebase held for one. */
840
+ const planningAhead = new Set();
757
841
  /**
758
842
  * The modules asked for whose plan is not made yet - their code being deleted, what is left being worked out, the
759
843
  * planner not started - by name, with since when: each shows as being planned from the moment it is asked for, not
@@ -776,10 +860,13 @@ export function createWorkLoop(options) {
776
860
  options.registry.notify?.();
777
861
  }
778
862
  };
779
- /** The codebases the requests bring up now - where each module's code lives, and what is to be built on it. */
780
- const active = () => {
863
+ /**
864
+ * The codebases the requests bring up now - where each module's code lives, and what is to be built on it - those
865
+ * asked for and, unless `requests` names others, those looked ahead at.
866
+ */
867
+ const active = (requests = [...asked, ...ahead]) => {
781
868
  const states = new Set();
782
- for (const [file, request] of asked) {
869
+ for (const [file, request] of requests) {
783
870
  let chains;
784
871
  try {
785
872
  chains = chainsFor(file);
@@ -805,6 +892,9 @@ export function createWorkLoop(options) {
805
892
  for (const file of [...asked.keys()])
806
893
  if (!existsSync(file))
807
894
  asked.delete(file);
895
+ for (const file of [...ahead.keys()])
896
+ if (!existsSync(file))
897
+ ahead.delete(file);
808
898
  for (const key of [...order]) {
809
899
  const state = modules.get(key);
810
900
  if (state.running === undefined && !existsSync(tipEntry(state).plainFile))
@@ -821,7 +911,7 @@ export function createWorkLoop(options) {
821
911
  // A codebase left behind - built on since - is not looked at, unless a job of it is still running; what it had
822
912
  // planned, or waited for, is no longer shown.
823
913
  if (now.has(state) || state.running !== undefined)
824
- await inStack(state, () => look(state));
914
+ await withModuleConfig(state, () => look(state));
825
915
  else {
826
916
  state.why = "left behind: the code is built on further up the chain, where changes to it are made";
827
917
  state.waitsFor = undefined;
@@ -853,14 +943,6 @@ export function createWorkLoop(options) {
853
943
  }
854
944
  const specKey = keyOf(spec);
855
945
  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
946
  if (state.running !== undefined) {
865
947
  if (state.running.stopping === true)
866
948
  return;
@@ -947,8 +1029,10 @@ export function createWorkLoop(options) {
947
1029
  // A func-id or a scenario-id renamed, and nothing else with it: turri renames it in the records and relabels the tests
948
1030
  // itself, as one unit of work - no pulse, the code untouched. Failing, it is rolled back whole, and the codebase halts
949
1031
  // rather than build the functional spec anew.
950
- const renamed = options.dryRun === true || readRecord(tip.buildDir) === null ? undefined : pureRenames(readRecord(tip.buildDir), readRecord(testsDirOf(state)), spec.tree, tip.moduleName);
951
- if (renamed !== undefined && renamed.renames.length > 0) {
1032
+ // Looked ahead, they are not made - a look ahead writes nothing - and the code is planned from as they would leave it.
1033
+ const renamed = readRecord(tip.buildDir) === null ? undefined : pureRenames(readRecord(tip.buildDir), readRecord(testsDirOf(state)), spec.tree, tip.moduleName);
1034
+ const pending = state.lookedAhead === true && renamed !== undefined && renamed.renames.length > 0 && renamed.code !== null ? renamed.code : undefined;
1035
+ if (renamed !== undefined && renamed.renames.length > 0 && state.lookedAhead !== true) {
952
1036
  const made = makeRenames({ buildDir: tip.buildDir, testsDir: testsDirOf(state), moduleName: tip.moduleName, renamed, place: { project: projectRootOf(tip.buildDir), module: tip.moduleName } });
953
1037
  if (!made) {
954
1038
  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 +1043,10 @@ export function createWorkLoop(options) {
959
1043
  }
960
1044
  // The module's code first, every job of it; then its conformance tests - once, for the module as built, with one
961
1045
  // explorer and one run of the whole suite - and only then is anything built on it (waitingOn).
962
- const from = builtOf(state);
1046
+ const from = pending !== undefined ? codeTree(pending) : builtOf(state);
963
1047
  const codeLeft = codeWork(from, spec.tree).length > 0;
1048
+ // 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.
1049
+ const mayPlan = state.lookedAhead !== true || planningAhead.has(state);
964
1050
  if (state.conformanceHalted !== undefined && state.conformanceHalted.key !== conformanceKey(state))
965
1051
  state.conformanceHalted = undefined;
966
1052
  if (!codeLeft && conformanceWanted(state, spec) && state.conformanceHalted === undefined) {
@@ -971,6 +1057,11 @@ export function createWorkLoop(options) {
971
1057
  // Made again when the spec, the tests or the code it was planned against moved: what the tests are written for
972
1058
  // follows the code, and a plan made before a code pulse landed would test it as it was.
973
1059
  if (existing === undefined || existing.specKey !== specKey || existing.from !== testedKey || existing.codeKey !== codeKeyOf(state) || existing.jobs.length === 0) {
1060
+ if (!mayPlan) {
1061
+ state.conformancePlan = undefined;
1062
+ state.why = LOOK_AGAIN;
1063
+ return;
1064
+ }
974
1065
  state.conformancePlan = { specKey, from: testedKey, codeKey: codeKeyOf(state), jobs: (await planIdle(state, spec, tested, "conformance")).jobs };
975
1066
  }
976
1067
  const next = state.conformancePlan.jobs[0];
@@ -1000,6 +1091,11 @@ export function createWorkLoop(options) {
1000
1091
  const fromKey = serializeTree(from);
1001
1092
  const steeringKey = steeringKeyOf(state);
1002
1093
  if (state.plan === undefined || state.plan.specKey !== specKey || state.plan.from !== fromKey || state.plan.steeringKey !== steeringKey || state.plan.jobs.length === 0) {
1094
+ if (!mayPlan) {
1095
+ state.plan = undefined;
1096
+ state.why = LOOK_AGAIN;
1097
+ return;
1098
+ }
1003
1099
  const { jobs, notes } = await planIdle(state, spec, from, "code");
1004
1100
  state.plan = { specKey, from: fromKey, steeringKey, jobs, notes };
1005
1101
  if (jobs.length === 0) {
@@ -1015,6 +1111,17 @@ export function createWorkLoop(options) {
1015
1111
  startJob(state, spec, from, state.plan.jobs[0]);
1016
1112
  };
1017
1113
  const statusOf = (state) => describe(state).status;
1114
+ /** 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. */
1115
+ const rowOf = (rowId) => {
1116
+ const state = order
1117
+ .map((key) => modules.get(key))
1118
+ .filter((candidate) => rowId.startsWith(`planned-${tipEntry(candidate).moduleName}-`))
1119
+ .sort((a, b) => tipEntry(b).moduleName.length - tipEntry(a).moduleName.length)[0];
1120
+ if (state === undefined)
1121
+ return undefined;
1122
+ const rest = rowId.slice(`planned-${tipEntry(state).moduleName}-`.length);
1123
+ return /^[1-9]\d*$/.test(rest) ? { state, index: Number(rest) } : undefined;
1124
+ };
1018
1125
  /** The modules asked for that the loop holds nothing of yet - turri just opened, say: their code being planned all the same. */
1019
1126
  const preparingAlone = () => {
1020
1127
  const held = new Set(order.map((key) => tipEntry(modules.get(key)).moduleName));
@@ -1028,7 +1135,7 @@ export function createWorkLoop(options) {
1028
1135
  }));
1029
1136
  };
1030
1137
  /** 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) => inStack(state, () => describeIn(state));
1138
+ const describe = (state) => withModuleConfig(state, () => describeIn(state));
1032
1139
  const describeIn = (state) => {
1033
1140
  // What runs next: the code's jobs, then the conformance tests' - the module's, once its code is built - the running job first.
1034
1141
  const running = state.running?.planned;
@@ -1084,7 +1191,7 @@ export function createWorkLoop(options) {
1084
1191
  plainFile: tip.plainFile,
1085
1192
  ...(base !== undefined ? { base } : {}),
1086
1193
  ...(renames.length > 0 ? { renames: renames.map(renameText) } : {}),
1087
- ...(state.stack?.name !== undefined ? { stack: state.stack.name } : {}),
1194
+ ...(state.configModule?.name !== undefined ? { configModule: state.configModule.name } : {}),
1088
1195
  ...(state.running !== undefined
1089
1196
  ? {
1090
1197
  running: {
@@ -1103,10 +1210,10 @@ export function createWorkLoop(options) {
1103
1210
  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
1211
  };
1105
1212
  /**
1106
- * Look after a codebase - its chain up to it - from now on; says its state. `pin`: its stack is worked out again - its
1107
- * tip's (`stackForModule`) - unless `keep`, and it has one: a spec change keeps the stack it was asked for with.
1213
+ * 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
+ * (`configModuleFor`): `asked`, one that cannot be told refuses the ask; otherwise it keeps the one it had.
1108
1215
  */
1109
- const track = (chain, askedFile, request, pin) => {
1216
+ const track = (chain, askedFile, request, asked = false) => {
1110
1217
  const tip = tipOf(chain);
1111
1218
  let state = modules.get(tip.buildDir);
1112
1219
  if (state === undefined) {
@@ -1121,12 +1228,15 @@ export function createWorkLoop(options) {
1121
1228
  }
1122
1229
  state.chain = chain;
1123
1230
  state.askedFile = askedFile;
1124
- // Kept only when it is a stack: a module pinned to none - built before its stack's file was there - takes its own.
1125
- const keep = pin?.keep === true && !stackPinned() && state.stack?.name !== undefined;
1126
- if (pin !== undefined && !keep)
1127
- state.stack = { name: stackForModule(tip.plainFile) };
1128
- // Its model as its stack has it: a stack's file can name a coding model of its own.
1129
- const model = request.model ?? inStack(state, () => options.modelFor?.(tip.plainFile));
1231
+ try {
1232
+ state.configModule = { name: configModuleFor(tip.plainFile) };
1233
+ }
1234
+ catch (error) {
1235
+ if (asked)
1236
+ throw error;
1237
+ }
1238
+ // Its model as its config has it: a module's own file can name a coding model of its own.
1239
+ const model = request.model ?? withModuleConfig(state, () => options.modelFor?.(tip.plainFile));
1130
1240
  if (model !== undefined)
1131
1241
  state.model = model;
1132
1242
  if (request.guidance !== undefined && !state.guidance.includes(request.guidance))
@@ -1135,29 +1245,91 @@ export function createWorkLoop(options) {
1135
1245
  };
1136
1246
  const loop = {
1137
1247
  async bringUp(plainFile, given = {}) {
1138
- const now = async () => {
1139
- const { specChange, ...request } = given;
1248
+ // Asked for, it shows as being planned at once.
1249
+ return preparingFor(plainFile, async () => {
1140
1250
  const files = codebasesOf(resolve(options.cwd, plainFile));
1141
- for (const file of files)
1142
- asked.set(file, { ...asked.get(file), ...request });
1143
- // Asked for, it is built with its stack - the one the call names, its own, or the one chosen now - pinned, whatever
1144
- // is chosen later; a spec change keeps the one it was asked for with.
1145
- const pin = { keep: specChange === true };
1146
- const states = withParseCache(() => files.flatMap((file) => chainsFor(file).flatMap((chain) => toBuild(chain).map((entry) => track(chain.slice(0, chain.indexOf(entry) + 1), file, request, pin)))));
1147
- // Asked again, a halted codebase is tried again - one the person halted too, unless only its spec changed.
1251
+ for (const file of files) {
1252
+ asked.set(file, { ...ahead.get(file), ...asked.get(file), ...given });
1253
+ ahead.delete(file);
1254
+ }
1255
+ // 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), file, given, true)))));
1257
+ // Asked again, a halted codebase is tried again - one the person halted too. Looked ahead at, its kept plan starts.
1148
1258
  for (const state of states) {
1149
1259
  state.halted = undefined;
1150
- if (specChange !== true)
1151
- state.held = undefined;
1260
+ state.held = undefined;
1261
+ state.lookedAhead = undefined;
1152
1262
  // Asked for again: its conformance tests are written for every functional spec with scenarios, not only those conform named.
1153
- if (specChange !== true)
1154
- state.conformanceOnly = undefined;
1263
+ state.conformanceOnly = undefined;
1155
1264
  }
1156
1265
  await tick();
1157
1266
  return [...new Set(states)].map(statusOf);
1158
- };
1159
- // Asked for, it shows as being planned at once; a spec change is looked at quietly, as every change is.
1160
- return given.specChange === true ? now() : preparingFor(plainFile, now);
1267
+ });
1268
+ },
1269
+ async lookAhead(plainFile, given = {}) {
1270
+ // Being planned, it shows so at once; what is planned is said once it is - not as being planned.
1271
+ const states = await preparingFor(plainFile, async () => {
1272
+ const files = codebasesOf(resolve(options.cwd, plainFile));
1273
+ for (const file of files)
1274
+ if (!asked.has(file))
1275
+ ahead.set(file, { ...ahead.get(file), ...given });
1276
+ // 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), file, given, true)))));
1278
+ // A chain with a pulse running is being built as asked, and goes on; every other codebase is held - one asked for
1279
+ // earlier too, which would otherwise start the work the look ahead plans.
1280
+ const building = (state) => state.chain.some((entry) => modules.get(entry.buildDir)?.running !== undefined);
1281
+ for (const state of tracked) {
1282
+ if (!building(state))
1283
+ state.lookedAhead = true;
1284
+ planningAhead.add(state);
1285
+ }
1286
+ try {
1287
+ await tick();
1288
+ }
1289
+ finally {
1290
+ for (const state of tracked)
1291
+ planningAhead.delete(state);
1292
+ }
1293
+ return tracked;
1294
+ });
1295
+ return [...new Set(states)].map(statusOf);
1296
+ },
1297
+ async plannedPulse(rowId) {
1298
+ const found = rowOf(rowId);
1299
+ if (found === undefined)
1300
+ return undefined;
1301
+ const { state, index } = found;
1302
+ const { status, jobs } = describe(state);
1303
+ const entry = status.planned[index - 1];
1304
+ if (entry === undefined)
1305
+ return undefined;
1306
+ const tip = tipEntry(state);
1307
+ const pulse = { id: rowId, module: tip.moduleName, plainFile: tip.plainFile, title: entry.title, track: entry.track, cases: entry.cases, index, lookedAhead: state.lookedAhead === true };
1308
+ const job = jobs[index - 1];
1309
+ const why = (text) => ({ ...pulse, why: text });
1310
+ if (entry.planning === true)
1311
+ return why("It is being planned now: its prompt is built once the plan is made.");
1312
+ if (entry.afterCode === true || job === undefined)
1313
+ 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.");
1314
+ if (state.running !== undefined)
1315
+ return why(`Pulse ${state.running.jobId} is running in this codebase: what this pulse is given depends on what that one lands.`);
1316
+ if (index > 1)
1317
+ 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
+ if (job.track === "conformance")
1319
+ 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 and the steering as they are now - else regenerate would plan again.
1321
+ let spec;
1322
+ try {
1323
+ spec = chainSpec(state.chain);
1324
+ }
1325
+ catch (error) {
1326
+ return why(`Its ***plain does not parse now: ${error instanceof Error ? error.message : String(error)}`);
1327
+ }
1328
+ if (state.plan === undefined || !state.plan.jobs.includes(job) || state.plan.specKey !== keyOf(spec) || state.plan.steeringKey !== steeringKeyOf(state)) {
1329
+ 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.");
1330
+ }
1331
+ const task = await withModuleConfig(state, () => promptOf({ plainFile: tip.plainFile, spec: { ...spec, tree: job.step.tree }, planned: job }));
1332
+ return task !== undefined ? { ...pulse, task } : why("It has no prompt to show.");
1161
1333
  },
1162
1334
  async regenerateAgain(plainFile, given, request = {}) {
1163
1335
  return preparingFor(plainFile, async () => {
@@ -1215,7 +1387,7 @@ export function createWorkLoop(options) {
1215
1387
  const tip = tipOf(codebase);
1216
1388
  // The codebase as the loop knows it, or - never asked for - as its records have it.
1217
1389
  const state = modules.get(tip.buildDir) ?? { chain: codebase, askedFile: file, guidance: [] };
1218
- return inStack(state, () => {
1390
+ return withModuleConfig(state, () => {
1219
1391
  const report = { module: tip.moduleName, plainFile: tip.plainFile, code: undefined, conformance: undefined, ...(conformanceTestsOn(tip.plainFile) ? {} : { conformanceOff: true }) };
1220
1392
  let spec;
1221
1393
  try {
@@ -1271,7 +1443,8 @@ export function createWorkLoop(options) {
1271
1443
  },
1272
1444
  async conformance(plainFile, request = {}) {
1273
1445
  const file = resolve(options.cwd, plainFile);
1274
- asked.set(file, { ...asked.get(file), ...(request.model !== undefined ? { model: request.model } : {}) });
1446
+ asked.set(file, { ...ahead.get(file), ...asked.get(file), ...(request.model !== undefined ? { model: request.model } : {}) });
1447
+ ahead.delete(file);
1275
1448
  const own = resolveRequiresChain(file, [], undefined, { allowNoFunctionalities: true });
1276
1449
  const self = tipOf(own);
1277
1450
  // What the person asks for comes first. Its tests are written in its own codebase, before anything is built on it:
@@ -1280,14 +1453,24 @@ export function createWorkLoop(options) {
1280
1453
  // it has, nothing is touched.
1281
1454
  if (!conformanceTestsOn(self.plainFile)) {
1282
1455
  throw new Error(`Conformance tests are off for ${self.moduleName} (conformance-tests: false, or unset): nothing is conformance tested. ` +
1283
- "They are turned on in the chat - by asking for them - or with conformance-tests: true in config.turri.yaml. Nothing was started.");
1456
+ "/conform in the chat turns them on, or conformance-tests: true in config.turri.yaml. Nothing was started.");
1284
1457
  }
1285
1458
  // Refused before anything is touched: a functional spec not there, nothing to test, or a step of adding tests skipped.
1286
1459
  const { named, spec: ownSpec, withScenarios } = conformanceAskedIn(own, request.funcIds);
1460
+ const scratch = request.fromScratch;
1461
+ if (scratch !== undefined && named !== undefined && named.length > 0) {
1462
+ 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.");
1463
+ }
1464
+ // Written already, and asked for again: the named ones written anew where they are tested; from scratch, the module's
1465
+ // tests folder taken out - and started again from the module it requires, unless the whole chain's are asked for.
1466
+ const again = named !== undefined && named.length > 0 ? conformAgain(file, self, named) : [];
1467
+ if (scratch !== undefined)
1468
+ testsFromScratch(file, scratch === "module");
1287
1469
  const tested = new Set((readRecord(conformanceDirFor(self.moduleName, modulesRoot(projectDirOf(self.plainFile))))?.[FUNCTIONAL_REQUIREMENTS] ?? []).map((item) => item.id));
1288
1470
  const toWrite = (named !== undefined && named.length > 0 ? named : withScenarios).some((funcId) => !tested.has(funcId));
1289
1471
  let wentBack = false;
1290
- if (readRecord(self.buildDir) !== null && toWrite) {
1472
+ // From scratch, the tests are written again at the tips, where they were: nothing built on the module is touched.
1473
+ if (scratch === undefined && readRecord(self.buildDir) !== null && toWrite) {
1291
1474
  const why = `${self.moduleName}'s conformance tests were asked for, and they come before anything is built on it`;
1292
1475
  for (const chain of builtTips(file)) {
1293
1476
  const above = chain.slice(chain.findIndex((entry) => entry.buildDir === self.buildDir) + 1);
@@ -1311,14 +1494,17 @@ export function createWorkLoop(options) {
1311
1494
  }
1312
1495
  }
1313
1496
  }
1314
- const tracked = withParseCache(() => (wentBack ? [own] : chainsFor(file)).flatMap((chain) => toBuild(chain).map((entry) => track(chain.slice(0, chain.indexOf(entry) + 1), file, request, {}))));
1497
+ 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
1498
  // The module asked for, in its own codebase - and those below it: never the codebases built on it.
1316
1499
  const asking = tracked.find((state) => tipEntry(state).buildDir === self.buildDir);
1317
1500
  const states = asking !== undefined ? tracked.filter((state) => own.some((entry) => entry.buildDir === tipEntry(state).buildDir)) : tracked;
1318
1501
  const tip = asking ?? states.at(-1);
1502
+ // Asked for: what a look ahead held here goes on - the modules below with it, or the module waits for them for ever.
1503
+ for (const state of tracked)
1504
+ state.lookedAhead = undefined;
1319
1505
  const asks = named !== undefined && named.length > 0 ? named : undefined;
1320
1506
  // 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) {
1507
+ if (asking === undefined && asks !== undefined && tip !== undefined && again.length === 0) {
1322
1508
  throw new Error(`${self.moduleName}'s conformance tests for ${namesOf(self.moduleName, asks)} are written already. Nothing was started.`);
1323
1509
  }
1324
1510
  // 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 +1514,7 @@ export function createWorkLoop(options) {
1328
1514
  state.conformancePlan = undefined;
1329
1515
  state.conformanceSeparately = separately;
1330
1516
  // 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;
1517
+ state.conformanceOnly = asks !== undefined ? namedOnly(state, asks, self.moduleName) : undefined;
1332
1518
  state.conformancePlan = undefined;
1333
1519
  state.conformanceHalted = undefined;
1334
1520
  state.halted = undefined;
@@ -1468,12 +1654,15 @@ export function createWorkLoop(options) {
1468
1654
  let before = status.running?.jobId;
1469
1655
  if (before !== undefined)
1470
1656
  lastOf.set(tip.moduleName, before);
1657
+ // Looked ahead at: every row of it says it waits for the module to be asked for.
1658
+ const held = state.lookedAhead === true && state.running === undefined;
1471
1659
  const row = (id, summary, note, waitingOn, conformance = false) => ({
1472
1660
  id,
1473
1661
  kind: conformance ? "conformance" : "regenerate",
1474
1662
  summary,
1475
1663
  module: tip.moduleName,
1476
- note,
1664
+ note: held ? `${LOOKED_AHEAD_NOTE} ${note}` : note,
1665
+ ...(held ? { lookedAhead: true } : {}),
1477
1666
  ...(state.model !== undefined ? { model: state.model } : {}),
1478
1667
  status: "queued",
1479
1668
  sequence: sequence--,
@@ -1509,16 +1698,9 @@ export function createWorkLoop(options) {
1509
1698
  });
1510
1699
  })];
1511
1700
  },
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
1701
  mapPlan() {
1520
1702
  return {
1521
- files: [...asked.keys()],
1703
+ files: [...asked.keys(), ...[...ahead.keys()].filter((file) => !asked.has(file))],
1522
1704
  codebases: order.map((key) => {
1523
1705
  const state = modules.get(key);
1524
1706
  const tip = tipEntry(state);
@@ -1580,6 +1762,12 @@ function oldCodebases(chain) {
1580
1762
  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
1763
  /** Why nothing runs in a codebase whose code - and conformance tests, where they are wanted - is built from its spec as it is. */
1582
1764
  export const UP_TO_DATE = "built from the ***plain as it is";
1765
+ /** Why nothing starts in a codebase a look ahead planned: its pulses wait for the module to be asked for. */
1766
+ const LOOKED_AHEAD = "looked ahead - planned, and nothing starts until regenerate, conform or /regenerate asks for it";
1767
+ /** What a planned row of a codebase a look ahead planned says first. */
1768
+ 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 or steering moved since, and only a look ahead plans it. */
1770
+ const LOOK_AGAIN = "looked ahead, and the ***plain or the steering changed since - look ahead again to plan it, or regenerate it";
1583
1771
  /** Why a codebase with work left has no plan: the planner found none. */
1584
1772
  /** Why a codebase waits for a testing script being written in the background. */
1585
1773
  const SCRIPT_BEING_WRITTEN = (what) => `waiting for its ${what}, which is being written`;
@@ -1625,6 +1813,7 @@ function conformanceLines(module, cases) {
1625
1813
  ...(spec.added.length > 0 ? [`${spec.added.length} added`] : []),
1626
1814
  ...(spec.changed.length > 0 ? [`${spec.changed.length} changed`] : []),
1627
1815
  ...(spec.removed.length > 0 ? [`${spec.removed.length} removed`] : []),
1816
+ ...(spec.rewritten.length > 0 ? [`written again from scratch - ${spec.rewritten.length} to write anew`] : []),
1628
1817
  ...(spec.codeChanged !== undefined ? [`${why[spec.codeChanged]} - ${spec.unchanged.length} to run on it`] : []),
1629
1818
  ];
1630
1819
  return parts.length > 0 ? parts.join(", ") : "its text changed";
@@ -1677,9 +1866,11 @@ function conformanceAskedIn(own, funcIds) {
1677
1866
  const named = funcIds === undefined ? undefined : funcIdsNamed(self.moduleName, [...new Set(funcIds)]);
1678
1867
  const spec = chainSpec(own).tree;
1679
1868
  const withScenarios = testedFuncIds(spec);
1869
+ // No scenarios: the steps still to take, from the first one missing - the test reqs and the script come before them.
1870
+ const toScenarios = () => stepsToScenarios({ moduleName: self.moduleName, plainFile: self.plainFile, tree: spec, buildDir: self.buildDir });
1680
1871
  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
- "write the conformance or acceptance scenarios first, with change_plain, and their tests are written once the code is built. Nothing was started.");
1872
+ throw new Error(`No functional spec of ${self.moduleName} has scenarios - none has a test plain file - so there is nothing to test. ${toScenarios()} ` +
1873
+ "Their tests are written once the code is built. Nothing was started.");
1683
1874
  }
1684
1875
  if (named !== undefined && named.length > 0) {
1685
1876
  const items = spec[FUNCTIONAL_REQUIREMENTS] ?? [];
@@ -1688,11 +1879,11 @@ function conformanceAskedIn(own, funcIds) {
1688
1879
  throw new Error(`${self.moduleName} has no functional spec ${namesOf(self.moduleName, unknown)}. Nothing was started.`);
1689
1880
  const untested = named.filter((funcId) => !hasScenarios(items.find((item) => item.id === funcId)));
1690
1881
  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
- "write the conformance or acceptance scenarios first, with change_plain, and their tests are written once the code is built. Nothing was started.");
1882
+ 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()} ` +
1883
+ "Their tests are written once the code is built. Nothing was started.");
1693
1884
  }
1694
1885
  }
1695
- // A step of adding tests skipped - its test reqs, or the conformance testing script for its stack: refused, naming it.
1886
+ // A step of adding tests skipped - its test reqs, or the conformance testing script: refused, naming it.
1696
1887
  const gap = testingGap({ moduleName: self.moduleName, plainFile: self.plainFile, tree: spec, buildDir: self.buildDir });
1697
1888
  if (gap !== undefined)
1698
1889
  throw new Error(`${gap.text} Nothing was started.`);
@@ -1723,54 +1914,24 @@ function casesText(cases) {
1723
1914
  ];
1724
1915
  return parts.length > 0 ? parts.join(", ") : "no functional spec - reqs or definitions only";
1725
1916
  }
1726
- /** The codebases the loop looks after, as the person reads them: what runs, what is planned after it, and why nothing does. */
1727
1917
  /**
1728
- * The coding agent's task for a dry run's first job, built as the render builds it - and all it did rolled back. Not for
1729
- * a conformance job: its prompt is built from what the code holds once it is built.
1918
+ * The coding agent's task for a planned code pulse, built as the pulse builds it - with `spec` the ***plain the pulse
1919
+ * would be given - and all it did rolled back. Not for a conformance pulse: its prompt is built from what the code holds
1920
+ * once it is built.
1730
1921
  */
1731
- export async function promptOf(first) {
1732
- if (first.planned.track !== "code")
1922
+ async function promptOf(next) {
1923
+ if (next.planned.track !== "code")
1733
1924
  return undefined;
1734
1925
  const result = await renderSpecDiff({
1735
- plainFile: first.plainFile,
1736
- diff: first.planned.step.textDiff,
1926
+ plainFile: next.plainFile,
1927
+ diff: next.planned.step.textDiff,
1737
1928
  applied: "already applied",
1738
- spec: first.spec,
1739
- cases: first.planned.cases,
1929
+ spec: next.spec,
1930
+ cases: next.planned.cases,
1740
1931
  dryRun: true,
1741
1932
  });
1742
1933
  return result.task;
1743
1934
  }
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
1935
  /** Nothing runs, is planned or is waiting there, as its code is built from its spec as it is. */
1775
1936
  export function isUpToDate(status) {
1776
1937
  return status.why === UP_TO_DATE && status.running === undefined && status.planned.length === 0 && status.startOver === undefined;
@@ -1806,7 +1967,7 @@ export function describeModules(statuses, options = {}) {
1806
1967
  // Nothing to do there: said in a sentence, not as a status.
1807
1968
  if (isUpToDate(status))
1808
1969
  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.stack !== undefined ? `, stack ${status.stack}` : ""}):`];
1970
+ const lines = [`${status.module} (${basename(status.plainFile)}${status.configModule !== undefined ? `, built with ${moduleConfigFile(status.configModule)}` : ""}):`];
1810
1971
  if (status.running !== undefined) {
1811
1972
  lines.push(` running: pulse ${status.running.jobId} - ${status.running.title}`);
1812
1973
  // Steered, not stopped or planned again: what changed went to its agent.
@@ -1822,8 +1983,11 @@ export function describeModules(statuses, options = {}) {
1822
1983
  : ` ${index + 1}. ${job.track === "conformance" ? "conformance tests: " : ""}${job.title} - ${casesText(job.cases)}`));
1823
1984
  if (status.planNotes !== undefined)
1824
1985
  lines.push(" what the plan did not do as asked:", ...status.planNotes.map((note) => ` - ${note}`));
1986
+ // A look ahead from the command line keeps its plan only while the process lives: the run that starts it plans again.
1825
1987
  if (status.why !== undefined)
1826
- lines.push(` ${status.why}`);
1988
+ lines.push(options.for === "command line" && status.why === LOOKED_AHEAD
1989
+ ? ` looked ahead - planned, nothing started: turri regenerate ${basename(status.plainFile)} runs it, planning it again as it starts`
1990
+ : ` ${status.why}`);
1827
1991
  if (status.conformanceNote !== undefined)
1828
1992
  lines.push(` ${status.conformanceNote}`);
1829
1993
  lines.push(...startOver(status));