@turri-dev/cli 0.2.3-next.fea0bd9 → 0.2.4-next.240620d

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 (94) hide show
  1. package/README.md +52 -56
  2. package/dist/chat-idle.d.ts +2 -2
  3. package/dist/chat-idle.js +2 -2
  4. package/dist/chats.d.ts +0 -10
  5. package/dist/chats.js +0 -23
  6. package/dist/cli.js +32 -5
  7. package/dist/config-edit.js +1 -3
  8. package/dist/config.d.ts +6 -21
  9. package/dist/config.js +3 -16
  10. package/dist/conformance-switch.d.ts +7 -17
  11. package/dist/conformance-switch.js +21 -46
  12. package/dist/drift-cli.js +1 -1
  13. package/dist/extension.d.ts +16 -12
  14. package/dist/extension.js +247 -238
  15. package/dist/genome.js +5 -48
  16. package/dist/graph.js +3 -5
  17. package/dist/host-session.d.ts +4 -15
  18. package/dist/host-session.js +2 -4
  19. package/dist/host.d.ts +1 -3
  20. package/dist/host.js +1 -4
  21. package/dist/identity.js +0 -1
  22. package/dist/init-config.d.ts +0 -1
  23. package/dist/init-config.js +2 -9
  24. package/dist/installed-providers.d.ts +1 -1
  25. package/dist/installed-providers.js +2 -2
  26. package/dist/loop-cli.d.ts +4 -3
  27. package/dist/loop-cli.js +13 -11
  28. package/dist/loop-tools.js +5 -10
  29. package/dist/new-project.js +2 -2
  30. package/dist/pi-launch.js +1 -1
  31. package/dist/pi.js +6 -6
  32. package/dist/plain/check.d.ts +1 -8
  33. package/dist/plain/check.js +3 -38
  34. package/dist/regenerate/activity.d.ts +0 -7
  35. package/dist/regenerate/activity.js +2 -20
  36. package/dist/regenerate/failure-reports.d.ts +28 -0
  37. package/dist/regenerate/failure-reports.js +79 -0
  38. package/dist/regenerate/jobs-tree.js +1 -1
  39. package/dist/regenerate/jobs.d.ts +2 -0
  40. package/dist/regenerate/jobs.js +4 -0
  41. package/dist/regenerate/ledger-view.d.ts +11 -24
  42. package/dist/regenerate/ledger-view.js +14 -60
  43. package/dist/regenerate/ledger.d.ts +1 -14
  44. package/dist/regenerate/ledger.js +1 -1
  45. package/dist/regenerate/loop.d.ts +40 -58
  46. package/dist/regenerate/loop.js +209 -126
  47. package/dist/regenerate/regenerate.d.ts +0 -2
  48. package/dist/regenerate/regenerate.js +0 -14
  49. package/dist/regenerate/standing.js +1 -1
  50. package/dist/regenerate/testing-steps.d.ts +11 -0
  51. package/dist/regenerate/testing-steps.js +22 -3
  52. package/dist/regenerate-cli.js +18 -9
  53. package/dist/self-invocation.js +5 -8
  54. package/dist/sentinel.js +3 -3
  55. package/dist/skill.d.ts +0 -11
  56. package/dist/skill.js +0 -9
  57. package/dist/stacks.js +1 -1
  58. package/dist/tools.js +2 -3
  59. package/docs/README.md +0 -2
  60. package/docs/authoring-plain.md +3 -3
  61. package/docs/chats.md +1 -3
  62. package/docs/claude-subscription.md +6 -6
  63. package/docs/config.md +11 -13
  64. package/docs/deploy.md +1 -1
  65. package/docs/development.md +2 -3
  66. package/docs/headless.md +4 -3
  67. package/docs/hosting.md +7 -7
  68. package/docs/installation.md +4 -0
  69. package/docs/parser.md +2 -2
  70. package/docs/regenerating.md +12 -10
  71. package/docs/sentinel.md +3 -3
  72. package/docs/skills-and-gates.md +3 -8
  73. package/docs/using.md +11 -18
  74. package/genome/rules/test-plain-files.md +15 -7
  75. package/genome/rules/turri-regeneration.md +4 -9
  76. package/genome/skills/convert-old-syntax/SKILL.md +5 -5
  77. package/package.json +1 -1
  78. package/dist/advisor-chat.d.ts +0 -63
  79. package/dist/advisor-chat.js +0 -290
  80. package/dist/change-plain-cli.d.ts +0 -1
  81. package/dist/change-plain-cli.js +0 -55
  82. package/dist/ledger-cli.d.ts +0 -1
  83. package/dist/ledger-cli.js +0 -50
  84. package/dist/ledger-tools.d.ts +0 -10
  85. package/dist/ledger-tools.js +0 -64
  86. package/dist/regenerate/advisor-records.d.ts +0 -93
  87. package/dist/regenerate/advisor-records.js +0 -110
  88. package/dist/regenerate/advisor-runs.d.ts +0 -87
  89. package/dist/regenerate/advisor-runs.js +0 -327
  90. package/dist/regenerate/test-advisor.d.ts +0 -101
  91. package/dist/regenerate/test-advisor.js +0 -379
  92. package/dist/spec-tools.d.ts +0 -36
  93. package/dist/spec-tools.js +0 -128
  94. package/docs/test-advisor.md +0 -110
@@ -9,13 +9,13 @@ 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 { createJobRegistry, formatDuration } from "./jobs.js";
12
+ import { formatDuration } from "./jobs.js";
13
13
  import { moduleLanes } from "./lanes.js";
14
14
  import { adoptDigests, chainTree, codeTree, conformanceTarget, marksRegenerateAgain, 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, stackForModule, testDirOf, withStack } from "../config.js";
19
19
  import { describeSpecChange } from "./prompt.js";
20
20
  import { resolveTemplateDirs } from "./paths.js";
21
21
  import { builtTips, copyRequiredCode, importingModules, isImportModule, newlyRequired, resolveRequiresChain, startFromScratch } from "./requires.js";
@@ -28,7 +28,7 @@ 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";
@@ -293,21 +293,6 @@ export function createWorkLoop(options) {
293
293
  const tip = tipEntry(state);
294
294
  return testingGap({ moduleName: tip.moduleName, plainFile: tip.plainFile, tree: spec.tree, buildDir: tip.buildDir });
295
295
  };
296
- /**
297
- * The functional specs conform is asked for, as the spec has them now - refused when one is not in the spec, or has no
298
- * scenarios to test.
299
- */
300
- const askedSpecs = (moduleName, spec, funcIds) => {
301
- const items = spec[FUNCTIONAL_REQUIREMENTS] ?? [];
302
- const unknown = funcIds.filter((funcId) => !items.some((item) => item.id === funcId));
303
- if (unknown.length > 0)
304
- throw new Error(`${moduleName} has no functional spec ${namesOf(moduleName, unknown)}. Nothing was started.`);
305
- const untested = funcIds.filter((funcId) => !hasScenarios(items.find((item) => item.id === funcId)));
306
- if (untested.length > 0) {
307
- throw new Error(`${namesOf(moduleName, untested)} ${untested.length === 1 ? "has" : "have"} no scenarios - no test plain file - so there is nothing to test: ` +
308
- "write the conformance or acceptance scenarios first, with change_plain, and their tests are written once the code is built. Nothing was started.");
309
- }
310
- };
311
296
  /**
312
297
  * Whether a codebase lacks a testing script of this kind that is being written in the background now: it waits for it,
313
298
  * rather than fail for want of it, and is looked at again once the run ends.
@@ -501,20 +486,18 @@ export function createWorkLoop(options) {
501
486
  options.registry.notify?.();
502
487
  }
503
488
  };
504
- /** A dry run's first jobs, by codebase: what each would start. */
505
- const firsts = new Map();
506
489
  const startJob = (state, spec, from, planned) => {
507
490
  // Halted while it was being planned: the plan is made, nothing starts.
508
491
  if (state.held !== undefined) {
509
492
  state.why = state.held.why;
510
493
  return;
511
494
  }
512
- const tip = tipEntry(state);
513
- if (options.dryRun === true) {
514
- firsts.set(tip.buildDir, { spec: planned.track === "conformance" ? spec : { ...spec, tree: planned.step.tree }, planned });
515
- state.why = `would start: ${planned.title}`;
495
+ // Looked ahead: the plan is kept, and its first pulse waits for the module to be asked for.
496
+ if (state.lookedAhead === true) {
497
+ state.why = LOOKED_AHEAD;
516
498
  return;
517
499
  }
500
+ const tip = tipEntry(state);
518
501
  const conformance = planned.track === "conformance";
519
502
  // A code job can be steered while it regenerates: its target moves with the spec, inside what it regenerates.
520
503
  const steering = conformance ? undefined : createSteering(planned.step.tree, tip.moduleName);
@@ -733,8 +716,8 @@ export function createWorkLoop(options) {
733
716
  * nothing running there - so the code is taken to be built from them, rather than everything linking one built again.
734
717
  */
735
718
  const hashResources = (state, spec) => {
736
- // A dry run only reads.
737
- if (options.dryRun === true)
719
+ // A look ahead only reads.
720
+ if (state.lookedAhead === true)
738
721
  return;
739
722
  const code = tipEntry(state).buildDir;
740
723
  for (const dir of [code, testsDirOf(state)]) {
@@ -764,11 +747,15 @@ export function createWorkLoop(options) {
764
747
  };
765
748
  // A testing script written in the background, or not: what waited for it is looked at again - started, or failed for want of it.
766
749
  onScriptRunEnded(() => {
767
- if (asked.size > 0 && options.dryRun !== true)
750
+ if (asked.size > 0 || ahead.size > 0)
768
751
  void tick();
769
752
  });
770
753
  /** The files asked for, each with how: what the loop brings up, worked out again each look. */
771
754
  const asked = new Map();
755
+ /** The files looked ahead at and not asked for since: their codebases are looked at, their pulses held. */
756
+ const ahead = new Map();
757
+ /** The codebases a look ahead is planning now: the only looks that plan a codebase held for one. */
758
+ const planningAhead = new Set();
772
759
  /**
773
760
  * The modules asked for whose plan is not made yet - their code being deleted, what is left being worked out, the
774
761
  * planner not started - by name, with since when: each shows as being planned from the moment it is asked for, not
@@ -791,10 +778,13 @@ export function createWorkLoop(options) {
791
778
  options.registry.notify?.();
792
779
  }
793
780
  };
794
- /** The codebases the requests bring up now - where each module's code lives, and what is to be built on it. */
795
- const active = () => {
781
+ /**
782
+ * The codebases the requests bring up now - where each module's code lives, and what is to be built on it - those
783
+ * asked for and, unless `requests` names others, those looked ahead at.
784
+ */
785
+ const active = (requests = [...asked, ...ahead]) => {
796
786
  const states = new Set();
797
- for (const [file, request] of asked) {
787
+ for (const [file, request] of requests) {
798
788
  let chains;
799
789
  try {
800
790
  chains = chainsFor(file);
@@ -820,6 +810,9 @@ export function createWorkLoop(options) {
820
810
  for (const file of [...asked.keys()])
821
811
  if (!existsSync(file))
822
812
  asked.delete(file);
813
+ for (const file of [...ahead.keys()])
814
+ if (!existsSync(file))
815
+ ahead.delete(file);
823
816
  for (const key of [...order]) {
824
817
  const state = modules.get(key);
825
818
  if (state.running === undefined && !existsSync(tipEntry(state).plainFile))
@@ -868,14 +861,6 @@ export function createWorkLoop(options) {
868
861
  }
869
862
  const specKey = keyOf(spec);
870
863
  state.seen = spec;
871
- if (options.onSpec !== undefined) {
872
- try {
873
- options.onSpec({ chain: state.chain, tree: spec.tree, built: builtOf(state) });
874
- }
875
- catch {
876
- /* what watches the spec never stops the loop */
877
- }
878
- }
879
864
  if (state.running !== undefined) {
880
865
  if (state.running.stopping === true)
881
866
  return;
@@ -962,8 +947,10 @@ export function createWorkLoop(options) {
962
947
  // A func-id or a scenario-id renamed, and nothing else with it: turri renames it in the records and relabels the tests
963
948
  // itself, as one unit of work - no pulse, the code untouched. Failing, it is rolled back whole, and the codebase halts
964
949
  // rather than build the functional spec anew.
965
- const renamed = options.dryRun === true || readRecord(tip.buildDir) === null ? undefined : pureRenames(readRecord(tip.buildDir), readRecord(testsDirOf(state)), spec.tree, tip.moduleName);
966
- if (renamed !== undefined && renamed.renames.length > 0) {
950
+ // Looked ahead, they are not made - a look ahead writes nothing - and the code is planned from as they would leave it.
951
+ const renamed = readRecord(tip.buildDir) === null ? undefined : pureRenames(readRecord(tip.buildDir), readRecord(testsDirOf(state)), spec.tree, tip.moduleName);
952
+ const pending = state.lookedAhead === true && renamed !== undefined && renamed.renames.length > 0 && renamed.code !== null ? renamed.code : undefined;
953
+ if (renamed !== undefined && renamed.renames.length > 0 && state.lookedAhead !== true) {
967
954
  const made = makeRenames({ buildDir: tip.buildDir, testsDir: testsDirOf(state), moduleName: tip.moduleName, renamed, place: { project: projectRootOf(tip.buildDir), module: tip.moduleName } });
968
955
  if (!made) {
969
956
  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 };
@@ -974,8 +961,10 @@ export function createWorkLoop(options) {
974
961
  }
975
962
  // The module's code first, every job of it; then its conformance tests - once, for the module as built, with one
976
963
  // explorer and one run of the whole suite - and only then is anything built on it (waitingOn).
977
- const from = builtOf(state);
964
+ const from = pending !== undefined ? codeTree(pending) : builtOf(state);
978
965
  const codeLeft = codeWork(from, spec.tree).length > 0;
966
+ // 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.
967
+ const mayPlan = state.lookedAhead !== true || planningAhead.has(state);
979
968
  if (state.conformanceHalted !== undefined && state.conformanceHalted.key !== conformanceKey(state))
980
969
  state.conformanceHalted = undefined;
981
970
  if (!codeLeft && conformanceWanted(state, spec) && state.conformanceHalted === undefined) {
@@ -986,6 +975,11 @@ export function createWorkLoop(options) {
986
975
  // Made again when the spec, the tests or the code it was planned against moved: what the tests are written for
987
976
  // follows the code, and a plan made before a code pulse landed would test it as it was.
988
977
  if (existing === undefined || existing.specKey !== specKey || existing.from !== testedKey || existing.codeKey !== codeKeyOf(state) || existing.jobs.length === 0) {
978
+ if (!mayPlan) {
979
+ state.conformancePlan = undefined;
980
+ state.why = LOOK_AGAIN;
981
+ return;
982
+ }
989
983
  state.conformancePlan = { specKey, from: testedKey, codeKey: codeKeyOf(state), jobs: (await planIdle(state, spec, tested, "conformance")).jobs };
990
984
  }
991
985
  const next = state.conformancePlan.jobs[0];
@@ -1015,6 +1009,11 @@ export function createWorkLoop(options) {
1015
1009
  const fromKey = serializeTree(from);
1016
1010
  const steeringKey = steeringKeyOf(state);
1017
1011
  if (state.plan === undefined || state.plan.specKey !== specKey || state.plan.from !== fromKey || state.plan.steeringKey !== steeringKey || state.plan.jobs.length === 0) {
1012
+ if (!mayPlan) {
1013
+ state.plan = undefined;
1014
+ state.why = LOOK_AGAIN;
1015
+ return;
1016
+ }
1018
1017
  const { jobs, notes } = await planIdle(state, spec, from, "code");
1019
1018
  state.plan = { specKey, from: fromKey, steeringKey, jobs, notes };
1020
1019
  if (jobs.length === 0) {
@@ -1030,6 +1029,17 @@ export function createWorkLoop(options) {
1030
1029
  startJob(state, spec, from, state.plan.jobs[0]);
1031
1030
  };
1032
1031
  const statusOf = (state) => describe(state).status;
1032
+ /** 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. */
1033
+ const rowOf = (rowId) => {
1034
+ const state = order
1035
+ .map((key) => modules.get(key))
1036
+ .filter((candidate) => rowId.startsWith(`planned-${tipEntry(candidate).moduleName}-`))
1037
+ .sort((a, b) => tipEntry(b).moduleName.length - tipEntry(a).moduleName.length)[0];
1038
+ if (state === undefined)
1039
+ return undefined;
1040
+ const rest = rowId.slice(`planned-${tipEntry(state).moduleName}-`.length);
1041
+ return /^[1-9]\d*$/.test(rest) ? { state, index: Number(rest) } : undefined;
1042
+ };
1033
1043
  /** The modules asked for that the loop holds nothing of yet - turri just opened, say: their code being planned all the same. */
1034
1044
  const preparingAlone = () => {
1035
1045
  const held = new Set(order.map((key) => tipEntry(modules.get(key)).moduleName));
@@ -1119,9 +1129,9 @@ export function createWorkLoop(options) {
1119
1129
  };
1120
1130
  /**
1121
1131
  * Look after a codebase - its chain up to it - from now on; says its state. `pin`: its stack is worked out again - its
1122
- * tip's (`stackForModule`) - unless `keep`, and it has one: a spec change keeps the stack it was asked for with.
1132
+ * tip's (`stackForModule`).
1123
1133
  */
1124
- const track = (chain, askedFile, request, pin) => {
1134
+ const track = (chain, askedFile, request, pin = false) => {
1125
1135
  const tip = tipOf(chain);
1126
1136
  let state = modules.get(tip.buildDir);
1127
1137
  if (state === undefined) {
@@ -1136,9 +1146,7 @@ export function createWorkLoop(options) {
1136
1146
  }
1137
1147
  state.chain = chain;
1138
1148
  state.askedFile = askedFile;
1139
- // Kept only when it is a stack: a module pinned to none - built before its stack's file was there - takes its own.
1140
- const keep = pin?.keep === true && !stackPinned() && state.stack?.name !== undefined;
1141
- if (pin !== undefined && !keep)
1149
+ if (pin)
1142
1150
  state.stack = { name: stackForModule(tip.plainFile) };
1143
1151
  // Its model as its stack has it: a stack's file can name a coding model of its own.
1144
1152
  const model = request.model ?? inStack(state, () => options.modelFor?.(tip.plainFile));
@@ -1150,29 +1158,92 @@ export function createWorkLoop(options) {
1150
1158
  };
1151
1159
  const loop = {
1152
1160
  async bringUp(plainFile, given = {}) {
1153
- const now = async () => {
1154
- const { specChange, ...request } = given;
1161
+ // Asked for, it shows as being planned at once.
1162
+ return preparingFor(plainFile, async () => {
1155
1163
  const files = codebasesOf(resolve(options.cwd, plainFile));
1156
- for (const file of files)
1157
- asked.set(file, { ...asked.get(file), ...request });
1164
+ for (const file of files) {
1165
+ asked.set(file, { ...ahead.get(file), ...asked.get(file), ...given });
1166
+ ahead.delete(file);
1167
+ }
1158
1168
  // Asked for, it is built with its stack - the one the call names, its own, or the one chosen now - pinned, whatever
1159
- // is chosen later; a spec change keeps the one it was asked for with.
1160
- const pin = { keep: specChange === true };
1161
- 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)))));
1162
- // Asked again, a halted codebase is tried again - one the person halted too, unless only its spec changed.
1169
+ // is chosen later.
1170
+ 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)))));
1171
+ // Asked again, a halted codebase is tried again - one the person halted too. Looked ahead at, its kept plan starts.
1163
1172
  for (const state of states) {
1164
1173
  state.halted = undefined;
1165
- if (specChange !== true)
1166
- state.held = undefined;
1174
+ state.held = undefined;
1175
+ state.lookedAhead = undefined;
1167
1176
  // Asked for again: its conformance tests are written for every functional spec with scenarios, not only those conform named.
1168
- if (specChange !== true)
1169
- state.conformanceOnly = undefined;
1177
+ state.conformanceOnly = undefined;
1170
1178
  }
1171
1179
  await tick();
1172
1180
  return [...new Set(states)].map(statusOf);
1173
- };
1174
- // Asked for, it shows as being planned at once; a spec change is looked at quietly, as every change is.
1175
- return given.specChange === true ? now() : preparingFor(plainFile, now);
1181
+ });
1182
+ },
1183
+ async lookAhead(plainFile, given = {}) {
1184
+ // Being planned, it shows so at once; what is planned is said once it is - not as being planned.
1185
+ const states = await preparingFor(plainFile, async () => {
1186
+ const files = codebasesOf(resolve(options.cwd, plainFile));
1187
+ for (const file of files)
1188
+ if (!asked.has(file))
1189
+ ahead.set(file, { ...ahead.get(file), ...given });
1190
+ // Its stack pinned as an ask pins it: the plan is made, and its pulses run, with the stack regenerate would use.
1191
+ 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)))));
1192
+ // A chain with a pulse running is being built as asked, and goes on; every other codebase is held - one asked for
1193
+ // earlier too, which would otherwise start the work the look ahead plans.
1194
+ const building = (state) => state.chain.some((entry) => modules.get(entry.buildDir)?.running !== undefined);
1195
+ for (const state of tracked) {
1196
+ if (!building(state))
1197
+ state.lookedAhead = true;
1198
+ planningAhead.add(state);
1199
+ }
1200
+ try {
1201
+ await tick();
1202
+ }
1203
+ finally {
1204
+ for (const state of tracked)
1205
+ planningAhead.delete(state);
1206
+ }
1207
+ return tracked;
1208
+ });
1209
+ return [...new Set(states)].map(statusOf);
1210
+ },
1211
+ async plannedPulse(rowId) {
1212
+ const found = rowOf(rowId);
1213
+ if (found === undefined)
1214
+ return undefined;
1215
+ const { state, index } = found;
1216
+ const { status, jobs } = describe(state);
1217
+ const entry = status.planned[index - 1];
1218
+ if (entry === undefined)
1219
+ return undefined;
1220
+ const tip = tipEntry(state);
1221
+ const pulse = { id: rowId, module: tip.moduleName, plainFile: tip.plainFile, title: entry.title, track: entry.track, cases: entry.cases, index, lookedAhead: state.lookedAhead === true };
1222
+ const job = jobs[index - 1];
1223
+ const why = (text) => ({ ...pulse, why: text });
1224
+ if (entry.planning === true)
1225
+ return why("It is being planned now: its prompt is built once the plan is made.");
1226
+ if (entry.afterCode === true || job === undefined)
1227
+ 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.");
1228
+ if (state.running !== undefined)
1229
+ return why(`Pulse ${state.running.jobId} is running in this codebase: what this pulse is given depends on what that one lands.`);
1230
+ if (index > 1)
1231
+ 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.`);
1232
+ if (job.track === "conformance")
1233
+ 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.");
1234
+ // The plan as kept, and only while it fits the ***plain and the steering as they are now - else regenerate would plan again.
1235
+ let spec;
1236
+ try {
1237
+ spec = chainSpec(state.chain);
1238
+ }
1239
+ catch (error) {
1240
+ return why(`Its ***plain does not parse now: ${error instanceof Error ? error.message : String(error)}`);
1241
+ }
1242
+ if (state.plan === undefined || !state.plan.jobs.includes(job) || state.plan.specKey !== keyOf(spec) || state.plan.steeringKey !== steeringKeyOf(state)) {
1243
+ 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.");
1244
+ }
1245
+ const task = await inStack(state, () => promptOf({ plainFile: tip.plainFile, spec: { ...spec, tree: job.step.tree }, planned: job }));
1246
+ return task !== undefined ? { ...pulse, task } : why("It has no prompt to show.");
1176
1247
  },
1177
1248
  async regenerateAgain(plainFile, given, request = {}) {
1178
1249
  return preparingFor(plainFile, async () => {
@@ -1286,7 +1357,8 @@ export function createWorkLoop(options) {
1286
1357
  },
1287
1358
  async conformance(plainFile, request = {}) {
1288
1359
  const file = resolve(options.cwd, plainFile);
1289
- asked.set(file, { ...asked.get(file), ...(request.model !== undefined ? { model: request.model } : {}) });
1360
+ asked.set(file, { ...ahead.get(file), ...asked.get(file), ...(request.model !== undefined ? { model: request.model } : {}) });
1361
+ ahead.delete(file);
1290
1362
  const own = resolveRequiresChain(file, [], undefined, { allowNoFunctionalities: true });
1291
1363
  const self = tipOf(own);
1292
1364
  // What the person asks for comes first. Its tests are written in its own codebase, before anything is built on it:
@@ -1295,22 +1367,10 @@ export function createWorkLoop(options) {
1295
1367
  // it has, nothing is touched.
1296
1368
  if (!conformanceTestsOn(self.plainFile)) {
1297
1369
  throw new Error(`Conformance tests are off for ${self.moduleName} (conformance-tests: false, or unset): nothing is conformance tested. ` +
1298
- "They are turned on in the chat - by asking for them - or with conformance-tests: true in config.turri.yaml. Nothing was started.");
1370
+ "/conform in the chat turns them on, or conformance-tests: true in config.turri.yaml. Nothing was started.");
1299
1371
  }
1300
- const named = request.funcIds === undefined ? undefined : funcIdsNamed(self.moduleName, [...new Set(request.funcIds)]);
1301
- const ownSpec = chainSpec(own).tree;
1302
- const withScenarios = testedFuncIds(ownSpec);
1303
- // Refused before anything is touched: nothing to test, a functional spec not there, or one with no scenarios.
1304
- if (withScenarios.length === 0) {
1305
- throw new Error(`No functional spec of ${self.moduleName} has scenarios - none has a test plain file - so there is nothing to test: ` +
1306
- "write the conformance or acceptance scenarios first, with change_plain, and their tests are written once the code is built. Nothing was started.");
1307
- }
1308
- if (named !== undefined && named.length > 0)
1309
- askedSpecs(self.moduleName, ownSpec, named);
1310
- // A step of adding tests skipped - its test reqs, or the conformance testing script for its stack: refused, naming it.
1311
- const gap = testingGap({ moduleName: self.moduleName, plainFile: self.plainFile, tree: ownSpec, buildDir: self.buildDir });
1312
- if (gap !== undefined)
1313
- throw new Error(`${gap.text} Nothing was started.`);
1372
+ // Refused before anything is touched: a functional spec not there, nothing to test, or a step of adding tests skipped.
1373
+ const { named, spec: ownSpec, withScenarios } = conformanceAskedIn(own, request.funcIds);
1314
1374
  const tested = new Set((readRecord(conformanceDirFor(self.moduleName, modulesRoot(projectDirOf(self.plainFile))))?.[FUNCTIONAL_REQUIREMENTS] ?? []).map((item) => item.id));
1315
1375
  const toWrite = (named !== undefined && named.length > 0 ? named : withScenarios).some((funcId) => !tested.has(funcId));
1316
1376
  let wentBack = false;
@@ -1338,11 +1398,14 @@ export function createWorkLoop(options) {
1338
1398
  }
1339
1399
  }
1340
1400
  }
1341
- const tracked = withParseCache(() => (wentBack ? [own] : chainsFor(file)).flatMap((chain) => toBuild(chain).map((entry) => track(chain.slice(0, chain.indexOf(entry) + 1), file, request, {}))));
1401
+ const tracked = withParseCache(() => (wentBack ? [own] : chainsFor(file)).flatMap((chain) => toBuild(chain).map((entry) => track(chain.slice(0, chain.indexOf(entry) + 1), file, request, true))));
1342
1402
  // The module asked for, in its own codebase - and those below it: never the codebases built on it.
1343
1403
  const asking = tracked.find((state) => tipEntry(state).buildDir === self.buildDir);
1344
1404
  const states = asking !== undefined ? tracked.filter((state) => own.some((entry) => entry.buildDir === tipEntry(state).buildDir)) : tracked;
1345
1405
  const tip = asking ?? states.at(-1);
1406
+ // Asked for: what a look ahead held here goes on - the modules below with it, or the module waits for them for ever.
1407
+ for (const state of tracked)
1408
+ state.lookedAhead = undefined;
1346
1409
  const asks = named !== undefined && named.length > 0 ? named : undefined;
1347
1410
  // Its tests are written already, and a codebase built on it holds its code: nothing to write, nothing touched.
1348
1411
  if (asking === undefined && asks !== undefined && tip !== undefined) {
@@ -1495,12 +1558,15 @@ export function createWorkLoop(options) {
1495
1558
  let before = status.running?.jobId;
1496
1559
  if (before !== undefined)
1497
1560
  lastOf.set(tip.moduleName, before);
1561
+ // Looked ahead at: every row of it says it waits for the module to be asked for.
1562
+ const held = state.lookedAhead === true && state.running === undefined;
1498
1563
  const row = (id, summary, note, waitingOn, conformance = false) => ({
1499
1564
  id,
1500
1565
  kind: conformance ? "conformance" : "regenerate",
1501
1566
  summary,
1502
1567
  module: tip.moduleName,
1503
- note,
1568
+ note: held ? `${LOOKED_AHEAD_NOTE} ${note}` : note,
1569
+ ...(held ? { lookedAhead: true } : {}),
1504
1570
  ...(state.model !== undefined ? { model: state.model } : {}),
1505
1571
  status: "queued",
1506
1572
  sequence: sequence--,
@@ -1536,16 +1602,9 @@ export function createWorkLoop(options) {
1536
1602
  });
1537
1603
  })];
1538
1604
  },
1539
- firsts() {
1540
- return order.flatMap((key) => {
1541
- const first = firsts.get(key);
1542
- const tip = tipEntry(modules.get(key));
1543
- return first === undefined ? [] : [{ module: tip.moduleName, plainFile: tip.plainFile, buildDir: tip.buildDir, ...first }];
1544
- });
1545
- },
1546
1605
  mapPlan() {
1547
1606
  return {
1548
- files: [...asked.keys()],
1607
+ files: [...asked.keys(), ...[...ahead.keys()].filter((file) => !asked.has(file))],
1549
1608
  codebases: order.map((key) => {
1550
1609
  const state = modules.get(key);
1551
1610
  const tip = tipEntry(state);
@@ -1607,6 +1666,12 @@ function oldCodebases(chain) {
1607
1666
  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`;
1608
1667
  /** Why nothing runs in a codebase whose code - and conformance tests, where they are wanted - is built from its spec as it is. */
1609
1668
  export const UP_TO_DATE = "built from the ***plain as it is";
1669
+ /** Why nothing starts in a codebase a look ahead planned: its pulses wait for the module to be asked for. */
1670
+ const LOOKED_AHEAD = "looked ahead - planned, and nothing starts until regenerate, conform or /regenerate asks for it";
1671
+ /** What a planned row of a codebase a look ahead planned says first. */
1672
+ const LOOKED_AHEAD_NOTE = "Planned by a look ahead: it waits for regenerate, conform or /regenerate to start it.";
1673
+ /** Why a codebase held for a look ahead has no plan: its ***plain or steering moved since, and only a look ahead plans it. */
1674
+ const LOOK_AGAIN = "looked ahead, and the ***plain or the steering changed since - look ahead again to plan it, or regenerate it";
1610
1675
  /** Why a codebase with work left has no plan: the planner found none. */
1611
1676
  /** Why a codebase waits for a testing script being written in the background. */
1612
1677
  const SCRIPT_BEING_WRITTEN = (what) => `waiting for its ${what}, which is being written`;
@@ -1692,6 +1757,54 @@ export function funcIdsNamed(module, names) {
1692
1757
  return funcId;
1693
1758
  });
1694
1759
  }
1760
+ /**
1761
+ * What conform is asked for in a module, checked from its ***plain alone - quick, before anything is said or touched: the
1762
+ * functional specs named, as func-ids, and the module's spec and those of its functional specs with scenarios. Throws,
1763
+ * saying why nothing was started, when a functional spec named is not there or has no scenarios, when none has any, or
1764
+ * when a step of adding tests is skipped - no test reqs, no conformance testing script. Conformance tests off are not
1765
+ * checked: the conform tool is refused for that, and /conform turns them on.
1766
+ */
1767
+ function conformanceAskedIn(own, funcIds) {
1768
+ const self = tipOf(own);
1769
+ const named = funcIds === undefined ? undefined : funcIdsNamed(self.moduleName, [...new Set(funcIds)]);
1770
+ const spec = chainSpec(own).tree;
1771
+ const withScenarios = testedFuncIds(spec);
1772
+ // No scenarios: the steps still to take, from the first one missing - the test reqs and the script come before them.
1773
+ const toScenarios = () => stepsToScenarios({ moduleName: self.moduleName, plainFile: self.plainFile, tree: spec, buildDir: self.buildDir });
1774
+ if (withScenarios.length === 0) {
1775
+ throw new Error(`No functional spec of ${self.moduleName} has scenarios - none has a test plain file - so there is nothing to test. ${toScenarios()} ` +
1776
+ "Their tests are written once the code is built. Nothing was started.");
1777
+ }
1778
+ if (named !== undefined && named.length > 0) {
1779
+ const items = spec[FUNCTIONAL_REQUIREMENTS] ?? [];
1780
+ const unknown = named.filter((funcId) => !items.some((item) => item.id === funcId));
1781
+ if (unknown.length > 0)
1782
+ throw new Error(`${self.moduleName} has no functional spec ${namesOf(self.moduleName, unknown)}. Nothing was started.`);
1783
+ const untested = named.filter((funcId) => !hasScenarios(items.find((item) => item.id === funcId)));
1784
+ if (untested.length > 0) {
1785
+ 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()} ` +
1786
+ "Their tests are written once the code is built. Nothing was started.");
1787
+ }
1788
+ }
1789
+ // A step of adding tests skipped - its test reqs, or the conformance testing script for its stack: refused, naming it.
1790
+ const gap = testingGap({ moduleName: self.moduleName, plainFile: self.plainFile, tree: spec, buildDir: self.buildDir });
1791
+ if (gap !== undefined)
1792
+ throw new Error(`${gap.text} Nothing was started.`);
1793
+ return { named, spec, withScenarios };
1794
+ }
1795
+ /**
1796
+ * Why conform would start nothing for a module, from its ***plain alone (`conformanceAskedIn`): undefined when it would
1797
+ * go on. What /conform checks before it says anything.
1798
+ */
1799
+ export function conformanceRefusal(plainFile, funcIds) {
1800
+ try {
1801
+ conformanceAskedIn(resolveRequiresChain(resolve(plainFile), [], undefined, { allowNoFunctionalities: true }), funcIds);
1802
+ return undefined;
1803
+ }
1804
+ catch (error) {
1805
+ return error instanceof Error ? error.message : String(error);
1806
+ }
1807
+ }
1695
1808
  /** What a job does, in a few words: its cases, each functional spec by its func-id - with its module, a module below's. */
1696
1809
  function casesText(cases) {
1697
1810
  const named = (specs) => specs.map((spec) => (spec.module !== undefined ? `${spec.module}:${spec.funcId}` : spec.funcId)).join(", ");
@@ -1704,54 +1817,24 @@ function casesText(cases) {
1704
1817
  ];
1705
1818
  return parts.length > 0 ? parts.join(", ") : "no functional spec - reqs or definitions only";
1706
1819
  }
1707
- /** The codebases the loop looks after, as the person reads them: what runs, what is planned after it, and why nothing does. */
1708
1820
  /**
1709
- * 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
1710
- * a conformance job: its prompt is built from what the code holds once it is built.
1821
+ * The coding agent's task for a planned code pulse, built as the pulse builds it - with `spec` the ***plain the pulse
1822
+ * would be given - and all it did rolled back. Not for a conformance pulse: its prompt is built from what the code holds
1823
+ * once it is built.
1711
1824
  */
1712
- export async function promptOf(first) {
1713
- if (first.planned.track !== "code")
1825
+ async function promptOf(next) {
1826
+ if (next.planned.track !== "code")
1714
1827
  return undefined;
1715
1828
  const result = await renderSpecDiff({
1716
- plainFile: first.plainFile,
1717
- diff: first.planned.step.textDiff,
1829
+ plainFile: next.plainFile,
1830
+ diff: next.planned.step.textDiff,
1718
1831
  applied: "already applied",
1719
- spec: first.spec,
1720
- cases: first.planned.cases,
1832
+ spec: next.spec,
1833
+ cases: next.planned.cases,
1721
1834
  dryRun: true,
1722
1835
  });
1723
1836
  return result.task;
1724
1837
  }
1725
- /**
1726
- * What bringing a spec's module up would start, in each codebase, and the prompt of each - planned on a loop of its own
1727
- * that starts nothing. A codebase `busy` says is running a job is left out: a dry run starts from its last commit, and
1728
- * what the next job there is given depends on what the running one lands.
1729
- */
1730
- export async function previewJobs(options) {
1731
- const loop = createWorkLoop({
1732
- registry: createJobRegistry(),
1733
- cwd: options.cwd,
1734
- dryRun: true,
1735
- ...(options.model !== undefined ? { modelFor: () => options.model } : {}),
1736
- ...(options.plannerModel !== undefined ? { plannerModel: options.plannerModel } : {}),
1737
- ...(options.steering !== undefined ? { steering: options.steering } : {}),
1738
- });
1739
- const statuses = await loop.bringUp(options.plainFile, options.model !== undefined ? { model: options.model } : {});
1740
- const previews = [];
1741
- const busy = [];
1742
- for (const first of loop.firsts()) {
1743
- if (options.busy?.(first.module) === true) {
1744
- busy.push(first.module);
1745
- continue;
1746
- }
1747
- const preview = { module: first.module, title: first.planned.title, track: first.planned.track, cases: first.planned.cases };
1748
- const task = await promptOf(first);
1749
- if (task !== undefined)
1750
- preview.task = task;
1751
- previews.push(preview);
1752
- }
1753
- return { statuses, previews, busy };
1754
- }
1755
1838
  /** Nothing runs, is planned or is waiting there, as its code is built from its spec as it is. */
1756
1839
  export function isUpToDate(status) {
1757
1840
  return status.why === UP_TO_DATE && status.running === undefined && status.planned.length === 0 && status.startOver === undefined;
@@ -10,8 +10,6 @@ import { type TestRemoval, type TestRun, type MissingToolchain } from "./testing
10
10
  * one that fits neither way is refused: rendering it would mean guessing.
11
11
  */
12
12
  export declare function applySpecDiff(diff: string, cwd: string): "applied" | "already applied";
13
- /** Undo a spec diff this process applied, when what it produced cannot be used. */
14
- export declare function revertSpecDiff(diff: string, cwd: string): void;
15
13
  /** The .plain files a diff writes to, relative to where it applies. */
16
14
  export declare function plainFilesOf(diff: string): string[];
17
15
  /** A module's .plain file and every one it imports, transitively - the files its spec is read from. */
@@ -88,20 +88,6 @@ export function applySpecDiff(diff, cwd) {
88
88
  written();
89
89
  }
90
90
  }
91
- /** Undo a spec diff this process applied, when what it produced cannot be used. */
92
- export function revertSpecDiff(diff, cwd) {
93
- const written = conversationWriting(plainFilesOf(diff).map((file) => resolve(cwd, file)));
94
- const dir = mkdtempSync(join(tmpdir(), "turri-diff-"));
95
- const patch = join(dir, "spec.diff");
96
- writeFileSync(patch, diff.endsWith("\n") ? diff : `${diff}\n`);
97
- try {
98
- spawnSync("git", ["apply", "--recount", "--reverse", patch], { cwd, encoding: "utf8" });
99
- }
100
- finally {
101
- rmSync(dir, { recursive: true, force: true });
102
- written();
103
- }
104
- }
105
91
  /** The .plain files a diff writes to, relative to where it applies. */
106
92
  export function plainFilesOf(diff) {
107
93
  const files = new Set();
@@ -7,7 +7,7 @@ import { projectPlainFiles } from "./requires.js";
7
7
  export function projectStanding(projectDir, options = {}) {
8
8
  const root = resolve(projectDir);
9
9
  const files = (options.files ?? projectPlainFiles(root)).map((file) => resolve(root, file));
10
- const loop = options.loop ?? createWorkLoop({ registry: createJobRegistry(), cwd: root, dryRun: true });
10
+ const loop = options.loop ?? createWorkLoop({ registry: createJobRegistry(), cwd: root });
11
11
  return withParseCache(() => files.map((plainFile) => {
12
12
  const standing = { plainFile, module: basename(plainFile, PLAIN_SOURCE_FILE_EXTENSION) };
13
13
  try {
@@ -39,3 +39,14 @@ export declare function testingGap(input: {
39
39
  tree: MarshalledPlainSource;
40
40
  buildDir?: string;
41
41
  }): TestingGap | undefined;
42
+ /**
43
+ * The steps of adding tests a module still has to take before it has anything to test - in their order: its test reqs,
44
+ * the conformance testing script for its stack, the scenarios - from the first one missing. What is said when conform
45
+ * finds no scenarios: the whole way there, not the last step alone.
46
+ */
47
+ export declare function stepsToScenarios(input: {
48
+ moduleName: string;
49
+ plainFile: string;
50
+ tree: MarshalledPlainSource;
51
+ buildDir?: string;
52
+ }): string;