@turri-dev/cli 0.2.3 → 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 (92) hide show
  1. package/README.md +2 -2
  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 +2 -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 +2 -10
  14. package/dist/extension.js +109 -205
  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 +1 -1
  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 +37 -60
  46. package/dist/regenerate/loop.js +165 -101
  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 +4 -7
  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/config.md +10 -12
  63. package/docs/deploy.md +1 -1
  64. package/docs/development.md +2 -3
  65. package/docs/headless.md +4 -3
  66. package/docs/hosting.md +6 -6
  67. package/docs/parser.md +2 -2
  68. package/docs/regenerating.md +12 -10
  69. package/docs/sentinel.md +3 -3
  70. package/docs/skills-and-gates.md +3 -8
  71. package/docs/using.md +10 -18
  72. package/genome/rules/test-plain-files.md +15 -7
  73. package/genome/rules/turri-regeneration.md +4 -9
  74. package/genome/skills/convert-old-syntax/SKILL.md +5 -5
  75. package/package.json +1 -1
  76. package/dist/advisor-chat.d.ts +0 -63
  77. package/dist/advisor-chat.js +0 -290
  78. package/dist/change-plain-cli.d.ts +0 -1
  79. package/dist/change-plain-cli.js +0 -55
  80. package/dist/ledger-cli.d.ts +0 -1
  81. package/dist/ledger-cli.js +0 -50
  82. package/dist/ledger-tools.d.ts +0 -10
  83. package/dist/ledger-tools.js +0 -64
  84. package/dist/regenerate/advisor-records.d.ts +0 -93
  85. package/dist/regenerate/advisor-records.js +0 -110
  86. package/dist/regenerate/advisor-runs.d.ts +0 -87
  87. package/dist/regenerate/advisor-runs.js +0 -327
  88. package/dist/regenerate/test-advisor.d.ts +0 -101
  89. package/dist/regenerate/test-advisor.js +0 -379
  90. package/dist/spec-tools.d.ts +0 -36
  91. package/dist/spec-tools.js +0 -128
  92. 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";
@@ -486,20 +486,18 @@ export function createWorkLoop(options) {
486
486
  options.registry.notify?.();
487
487
  }
488
488
  };
489
- /** A dry run's first jobs, by codebase: what each would start. */
490
- const firsts = new Map();
491
489
  const startJob = (state, spec, from, planned) => {
492
490
  // Halted while it was being planned: the plan is made, nothing starts.
493
491
  if (state.held !== undefined) {
494
492
  state.why = state.held.why;
495
493
  return;
496
494
  }
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}`;
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;
501
498
  return;
502
499
  }
500
+ const tip = tipEntry(state);
503
501
  const conformance = planned.track === "conformance";
504
502
  // A code job can be steered while it regenerates: its target moves with the spec, inside what it regenerates.
505
503
  const steering = conformance ? undefined : createSteering(planned.step.tree, tip.moduleName);
@@ -718,8 +716,8 @@ export function createWorkLoop(options) {
718
716
  * nothing running there - so the code is taken to be built from them, rather than everything linking one built again.
719
717
  */
720
718
  const hashResources = (state, spec) => {
721
- // A dry run only reads.
722
- if (options.dryRun === true)
719
+ // A look ahead only reads.
720
+ if (state.lookedAhead === true)
723
721
  return;
724
722
  const code = tipEntry(state).buildDir;
725
723
  for (const dir of [code, testsDirOf(state)]) {
@@ -749,11 +747,15 @@ export function createWorkLoop(options) {
749
747
  };
750
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.
751
749
  onScriptRunEnded(() => {
752
- if (asked.size > 0 && options.dryRun !== true)
750
+ if (asked.size > 0 || ahead.size > 0)
753
751
  void tick();
754
752
  });
755
753
  /** The files asked for, each with how: what the loop brings up, worked out again each look. */
756
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();
757
759
  /**
758
760
  * The modules asked for whose plan is not made yet - their code being deleted, what is left being worked out, the
759
761
  * planner not started - by name, with since when: each shows as being planned from the moment it is asked for, not
@@ -776,10 +778,13 @@ export function createWorkLoop(options) {
776
778
  options.registry.notify?.();
777
779
  }
778
780
  };
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 = () => {
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]) => {
781
786
  const states = new Set();
782
- for (const [file, request] of asked) {
787
+ for (const [file, request] of requests) {
783
788
  let chains;
784
789
  try {
785
790
  chains = chainsFor(file);
@@ -805,6 +810,9 @@ export function createWorkLoop(options) {
805
810
  for (const file of [...asked.keys()])
806
811
  if (!existsSync(file))
807
812
  asked.delete(file);
813
+ for (const file of [...ahead.keys()])
814
+ if (!existsSync(file))
815
+ ahead.delete(file);
808
816
  for (const key of [...order]) {
809
817
  const state = modules.get(key);
810
818
  if (state.running === undefined && !existsSync(tipEntry(state).plainFile))
@@ -853,14 +861,6 @@ export function createWorkLoop(options) {
853
861
  }
854
862
  const specKey = keyOf(spec);
855
863
  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
864
  if (state.running !== undefined) {
865
865
  if (state.running.stopping === true)
866
866
  return;
@@ -947,8 +947,10 @@ export function createWorkLoop(options) {
947
947
  // A func-id or a scenario-id renamed, and nothing else with it: turri renames it in the records and relabels the tests
948
948
  // itself, as one unit of work - no pulse, the code untouched. Failing, it is rolled back whole, and the codebase halts
949
949
  // 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) {
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) {
952
954
  const made = makeRenames({ buildDir: tip.buildDir, testsDir: testsDirOf(state), moduleName: tip.moduleName, renamed, place: { project: projectRootOf(tip.buildDir), module: tip.moduleName } });
953
955
  if (!made) {
954
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 };
@@ -959,8 +961,10 @@ export function createWorkLoop(options) {
959
961
  }
960
962
  // The module's code first, every job of it; then its conformance tests - once, for the module as built, with one
961
963
  // explorer and one run of the whole suite - and only then is anything built on it (waitingOn).
962
- const from = builtOf(state);
964
+ const from = pending !== undefined ? codeTree(pending) : builtOf(state);
963
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);
964
968
  if (state.conformanceHalted !== undefined && state.conformanceHalted.key !== conformanceKey(state))
965
969
  state.conformanceHalted = undefined;
966
970
  if (!codeLeft && conformanceWanted(state, spec) && state.conformanceHalted === undefined) {
@@ -971,6 +975,11 @@ export function createWorkLoop(options) {
971
975
  // Made again when the spec, the tests or the code it was planned against moved: what the tests are written for
972
976
  // follows the code, and a plan made before a code pulse landed would test it as it was.
973
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
+ }
974
983
  state.conformancePlan = { specKey, from: testedKey, codeKey: codeKeyOf(state), jobs: (await planIdle(state, spec, tested, "conformance")).jobs };
975
984
  }
976
985
  const next = state.conformancePlan.jobs[0];
@@ -1000,6 +1009,11 @@ export function createWorkLoop(options) {
1000
1009
  const fromKey = serializeTree(from);
1001
1010
  const steeringKey = steeringKeyOf(state);
1002
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
+ }
1003
1017
  const { jobs, notes } = await planIdle(state, spec, from, "code");
1004
1018
  state.plan = { specKey, from: fromKey, steeringKey, jobs, notes };
1005
1019
  if (jobs.length === 0) {
@@ -1015,6 +1029,17 @@ export function createWorkLoop(options) {
1015
1029
  startJob(state, spec, from, state.plan.jobs[0]);
1016
1030
  };
1017
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
+ };
1018
1043
  /** The modules asked for that the loop holds nothing of yet - turri just opened, say: their code being planned all the same. */
1019
1044
  const preparingAlone = () => {
1020
1045
  const held = new Set(order.map((key) => tipEntry(modules.get(key)).moduleName));
@@ -1104,9 +1129,9 @@ export function createWorkLoop(options) {
1104
1129
  };
1105
1130
  /**
1106
1131
  * 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.
1132
+ * tip's (`stackForModule`).
1108
1133
  */
1109
- const track = (chain, askedFile, request, pin) => {
1134
+ const track = (chain, askedFile, request, pin = false) => {
1110
1135
  const tip = tipOf(chain);
1111
1136
  let state = modules.get(tip.buildDir);
1112
1137
  if (state === undefined) {
@@ -1121,9 +1146,7 @@ export function createWorkLoop(options) {
1121
1146
  }
1122
1147
  state.chain = chain;
1123
1148
  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)
1149
+ if (pin)
1127
1150
  state.stack = { name: stackForModule(tip.plainFile) };
1128
1151
  // Its model as its stack has it: a stack's file can name a coding model of its own.
1129
1152
  const model = request.model ?? inStack(state, () => options.modelFor?.(tip.plainFile));
@@ -1135,29 +1158,92 @@ export function createWorkLoop(options) {
1135
1158
  };
1136
1159
  const loop = {
1137
1160
  async bringUp(plainFile, given = {}) {
1138
- const now = async () => {
1139
- const { specChange, ...request } = given;
1161
+ // Asked for, it shows as being planned at once.
1162
+ return preparingFor(plainFile, async () => {
1140
1163
  const files = codebasesOf(resolve(options.cwd, plainFile));
1141
- for (const file of files)
1142
- 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
+ }
1143
1168
  // 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.
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.
1148
1172
  for (const state of states) {
1149
1173
  state.halted = undefined;
1150
- if (specChange !== true)
1151
- state.held = undefined;
1174
+ state.held = undefined;
1175
+ state.lookedAhead = undefined;
1152
1176
  // 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;
1177
+ state.conformanceOnly = undefined;
1155
1178
  }
1156
1179
  await tick();
1157
1180
  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);
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.");
1161
1247
  },
1162
1248
  async regenerateAgain(plainFile, given, request = {}) {
1163
1249
  return preparingFor(plainFile, async () => {
@@ -1271,7 +1357,8 @@ export function createWorkLoop(options) {
1271
1357
  },
1272
1358
  async conformance(plainFile, request = {}) {
1273
1359
  const file = resolve(options.cwd, plainFile);
1274
- 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);
1275
1362
  const own = resolveRequiresChain(file, [], undefined, { allowNoFunctionalities: true });
1276
1363
  const self = tipOf(own);
1277
1364
  // What the person asks for comes first. Its tests are written in its own codebase, before anything is built on it:
@@ -1280,7 +1367,7 @@ export function createWorkLoop(options) {
1280
1367
  // it has, nothing is touched.
1281
1368
  if (!conformanceTestsOn(self.plainFile)) {
1282
1369
  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.");
1370
+ "/conform in the chat turns them on, or conformance-tests: true in config.turri.yaml. Nothing was started.");
1284
1371
  }
1285
1372
  // Refused before anything is touched: a functional spec not there, nothing to test, or a step of adding tests skipped.
1286
1373
  const { named, spec: ownSpec, withScenarios } = conformanceAskedIn(own, request.funcIds);
@@ -1311,11 +1398,14 @@ export function createWorkLoop(options) {
1311
1398
  }
1312
1399
  }
1313
1400
  }
1314
- 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))));
1315
1402
  // The module asked for, in its own codebase - and those below it: never the codebases built on it.
1316
1403
  const asking = tracked.find((state) => tipEntry(state).buildDir === self.buildDir);
1317
1404
  const states = asking !== undefined ? tracked.filter((state) => own.some((entry) => entry.buildDir === tipEntry(state).buildDir)) : tracked;
1318
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;
1319
1409
  const asks = named !== undefined && named.length > 0 ? named : undefined;
1320
1410
  // Its tests are written already, and a codebase built on it holds its code: nothing to write, nothing touched.
1321
1411
  if (asking === undefined && asks !== undefined && tip !== undefined) {
@@ -1468,12 +1558,15 @@ export function createWorkLoop(options) {
1468
1558
  let before = status.running?.jobId;
1469
1559
  if (before !== undefined)
1470
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;
1471
1563
  const row = (id, summary, note, waitingOn, conformance = false) => ({
1472
1564
  id,
1473
1565
  kind: conformance ? "conformance" : "regenerate",
1474
1566
  summary,
1475
1567
  module: tip.moduleName,
1476
- note,
1568
+ note: held ? `${LOOKED_AHEAD_NOTE} ${note}` : note,
1569
+ ...(held ? { lookedAhead: true } : {}),
1477
1570
  ...(state.model !== undefined ? { model: state.model } : {}),
1478
1571
  status: "queued",
1479
1572
  sequence: sequence--,
@@ -1509,16 +1602,9 @@ export function createWorkLoop(options) {
1509
1602
  });
1510
1603
  })];
1511
1604
  },
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
1605
  mapPlan() {
1520
1606
  return {
1521
- files: [...asked.keys()],
1607
+ files: [...asked.keys(), ...[...ahead.keys()].filter((file) => !asked.has(file))],
1522
1608
  codebases: order.map((key) => {
1523
1609
  const state = modules.get(key);
1524
1610
  const tip = tipEntry(state);
@@ -1580,6 +1666,12 @@ function oldCodebases(chain) {
1580
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`;
1581
1667
  /** Why nothing runs in a codebase whose code - and conformance tests, where they are wanted - is built from its spec as it is. */
1582
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";
1583
1675
  /** Why a codebase with work left has no plan: the planner found none. */
1584
1676
  /** Why a codebase waits for a testing script being written in the background. */
1585
1677
  const SCRIPT_BEING_WRITTEN = (what) => `waiting for its ${what}, which is being written`;
@@ -1677,9 +1769,11 @@ function conformanceAskedIn(own, funcIds) {
1677
1769
  const named = funcIds === undefined ? undefined : funcIdsNamed(self.moduleName, [...new Set(funcIds)]);
1678
1770
  const spec = chainSpec(own).tree;
1679
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 });
1680
1774
  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.");
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.");
1683
1777
  }
1684
1778
  if (named !== undefined && named.length > 0) {
1685
1779
  const items = spec[FUNCTIONAL_REQUIREMENTS] ?? [];
@@ -1688,8 +1782,8 @@ function conformanceAskedIn(own, funcIds) {
1688
1782
  throw new Error(`${self.moduleName} has no functional spec ${namesOf(self.moduleName, unknown)}. Nothing was started.`);
1689
1783
  const untested = named.filter((funcId) => !hasScenarios(items.find((item) => item.id === funcId)));
1690
1784
  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.");
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.");
1693
1787
  }
1694
1788
  }
1695
1789
  // A step of adding tests skipped - its test reqs, or the conformance testing script for its stack: refused, naming it.
@@ -1723,54 +1817,24 @@ function casesText(cases) {
1723
1817
  ];
1724
1818
  return parts.length > 0 ? parts.join(", ") : "no functional spec - reqs or definitions only";
1725
1819
  }
1726
- /** The codebases the loop looks after, as the person reads them: what runs, what is planned after it, and why nothing does. */
1727
1820
  /**
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.
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.
1730
1824
  */
1731
- export async function promptOf(first) {
1732
- if (first.planned.track !== "code")
1825
+ async function promptOf(next) {
1826
+ if (next.planned.track !== "code")
1733
1827
  return undefined;
1734
1828
  const result = await renderSpecDiff({
1735
- plainFile: first.plainFile,
1736
- diff: first.planned.step.textDiff,
1829
+ plainFile: next.plainFile,
1830
+ diff: next.planned.step.textDiff,
1737
1831
  applied: "already applied",
1738
- spec: first.spec,
1739
- cases: first.planned.cases,
1832
+ spec: next.spec,
1833
+ cases: next.planned.cases,
1740
1834
  dryRun: true,
1741
1835
  });
1742
1836
  return result.task;
1743
1837
  }
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
1838
  /** Nothing runs, is planned or is waiting there, as its code is built from its spec as it is. */
1775
1839
  export function isUpToDate(status) {
1776
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;
@@ -1,7 +1,7 @@
1
1
  import { existsSync, readFileSync } from "node:fs";
2
- import { dirname, join, resolve } from "node:path";
2
+ import { dirname, join, relative, resolve } from "node:path";
3
3
  import { conformanceTestsOn } from "../conformance-switch.js";
4
- import { stackForModule, stackPinned, withStack } from "../config.js";
4
+ import { stackForModule, stackPinned, testDirOf, withStack } from "../config.js";
5
5
  import { IMPORT_DIRECTIVE, readPlainSourceMetadata } from "../plain/parser.js";
6
6
  import { FUNCTIONAL_REQUIREMENTS, REQUIRED_FUNCTIONAL_SPECS, TEST_REQUIREMENTS } from "../plain/spec.js";
7
7
  import { isStdlibModule, STDLIB_ROOT } from "../plain/stdlib.js";
@@ -93,7 +93,7 @@ export function testingGap(input) {
93
93
  return {
94
94
  step: "test reqs",
95
95
  text: `${moduleName} has scenarios to test - ${named(tested)} - but no ***test reqs***, so its conformance tests cannot be written - the test reqs are ` +
96
- `the first step of adding tests. Next step: ${reqs}, with change_plain${found.script === undefined ? `; then ${scriptStep}` : ""}.`,
96
+ `the first step of adding tests. Next step: ${reqs}${found.script === undefined ? `; then ${scriptStep}` : ""}.`,
97
97
  short: "scenarios not tested: no test reqs",
98
98
  };
99
99
  }
@@ -108,3 +108,22 @@ export function testingGap(input) {
108
108
  }
109
109
  return undefined;
110
110
  }
111
+ /**
112
+ * The steps of adding tests a module still has to take before it has anything to test - in their order: its test reqs,
113
+ * the conformance testing script for its stack, the scenarios - from the first one missing. What is said when conform
114
+ * finds no scenarios: the whole way there, not the last step alone.
115
+ */
116
+ export function stepsToScenarios(input) {
117
+ const { moduleName, plainFile } = input;
118
+ const steps = [];
119
+ if ((input.tree[TEST_REQUIREMENTS] ?? []).length === 0) {
120
+ const conformance = conformanceTemplateOf(plainFile);
121
+ steps.push(conformance !== undefined ? `import the stack's conformance template, ${conformance}` : "write the module's own ***test reqs***");
122
+ }
123
+ if (conformanceScriptOf(plainFile, input.buildDir).script === undefined)
124
+ steps.push("write the conformance testing script with the implement-conformance-testing-script skill");
125
+ const testDir = relative(projectDirOf(resolve(plainFile)), testDirOf(plainFile)) || ".";
126
+ steps.push(`write the scenarios, each functional spec's in ${testDir}/${moduleName}/<func-id>.plain, then regenerate`);
127
+ const order = steps.length > 1 ? "Adding tests is three steps, in this order: the test reqs, the conformance testing script, the scenarios. " : "";
128
+ return `${order}Next step: ${steps.join("; then ")}.`;
129
+ }
@@ -16,7 +16,8 @@ build when none is given), coding-model (the agents that build) and harness-mode
16
16
  0 only when every module is complete: regenerated from the spec as it is, and its conformance tests written
17
17
  for every functional spec's scenarios.
18
18
 
19
- --dry-run plan the work and print the prompt of the first job, and run nothing (turri glimpse)
19
+ --dry-run look ahead: plan the work as regenerate would and print the prompt of each codebase's
20
+ next pulse, starting and writing nothing
20
21
  --start-over start over, without asking, a codebase regenerated without a module it now requires -
21
22
  with no terminal to ask and without it, the run stops there
22
23
  --from-scratch delete the module's code and conformance tests (its lineage keeps them) and regenerate all of it
@@ -45,23 +46,31 @@ if (!named) {
45
46
  process.exit(1);
46
47
  }
47
48
  const scratch = options["from-scratch-chain"] !== undefined ? "chain" : options["from-scratch"] !== undefined ? "module" : undefined;
48
- // A dry run starts nothing, and from scratch deletes before it plans: the two do not go together.
49
- if (scratch !== undefined && options["dry-run"] !== undefined) {
49
+ const dryRun = options["dry-run"] !== undefined;
50
+ // A dry run writes nothing: from scratch deletes the code before it plans, and functional specs named are marked in the records first.
51
+ if (scratch !== undefined && dryRun) {
50
52
  console.error(`--from-scratch${scratch === "chain" ? "-chain" : ""} deletes the code before anything is planned: it cannot be a dry run.`);
51
53
  process.exit(1);
52
54
  }
55
+ if (again.length > 0 && dryRun) {
56
+ console.error(`${again.join(", ")} would be marked to regenerate again in the code records before anything is planned: that cannot be a dry run.`);
57
+ process.exit(1);
58
+ }
53
59
  runLoop({
54
60
  plainFile: named,
55
61
  ...(buildDir !== undefined ? { buildDir } : {}),
56
62
  ...(report !== undefined ? { report } : {}),
57
63
  command: ["regenerate", ...process.argv.slice(2)],
58
- dryRun: options["dry-run"] !== undefined,
64
+ dryRun,
59
65
  startOver: options["start-over"] !== undefined,
60
- ask: (loop) => again.length > 0
61
- ? loop.regenerateAgain(named, again)
62
- : scratch !== undefined
63
- ? loop.fromScratch(named, { chain: scratch === "chain" })
64
- : loop.bringUp(named),
66
+ // A dry run is a look ahead: planned as regenerate plans it, nothing started.
67
+ ask: (loop) => dryRun
68
+ ? loop.lookAhead(named)
69
+ : again.length > 0
70
+ ? loop.regenerateAgain(named, again)
71
+ : scratch !== undefined
72
+ ? loop.fromScratch(named, { chain: scratch === "chain" })
73
+ : loop.bringUp(named),
65
74
  }).catch((error) => {
66
75
  console.error(error instanceof Error ? error.message : error);
67
76
  process.exit(1);