@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
package/dist/extension.js CHANGED
@@ -18,7 +18,7 @@ import { findTestScripts, scriptKindOfSkill } from "./regenerate/test-scripts.js
18
18
  import { writingScript } from "./regenerate/scripts-being-written.js";
19
19
  import { applyBedrockRegion } from "./bedrock-region.js";
20
20
  import { bannerWarnings } from "./turri-versions.js";
21
- import { conformanceBlock, conformanceTestsOnIn, CONFORMANCE_TOOLS, TURN_ON_TOOL, turnOnConformanceTests, turnOnConformanceTestsTool } from "./conformance-switch.js";
21
+ import { CONFORMANCE_OFF_REFUSAL, conformanceBlock, conformanceTestsOn, conformanceTestsOnIn, turnOnConformanceTests } from "./conformance-switch.js";
22
22
  import { BACKGROUND_NOTE, doneLine, failedTask, ownChanges, runDetails, skillRunDelivery, startedText } from "./background-skills.js";
23
23
  import { createAskUserTool } from "./tools.js";
24
24
  import { asksFromScratch, asksWholeChain, driftTool, fromWorkingDir, haltTool, loopReply, MODEL_PARAM, regenerateTool, STACK_PARAM, stopJob, WAIT_PARAM, withCallStack, WORKING_DIR_PARAM } from "./loop-tools.js";
@@ -38,10 +38,8 @@ import { checkPlainFile, formatCheckResults } from "./plain/check.js";
38
38
  import { checkPlainTool } from "./parse-tool.js";
39
39
  import { changedFiles, projectFiles } from "./plain-files.js";
40
40
  import { whyFailed } from "./regenerate/diagnose-job.js";
41
- import { createWorkLoop, describeModules, isUpToDate, previewJobs } from "./regenerate/loop.js";
42
- import { createTestAdvisor } from "./regenerate/advisor-runs.js";
43
- import { advisorDir } from "./regenerate/advisor-records.js";
44
- import { bindAdvisor, evaluateTestsTool, TEST_ADVISOR_BLOCK, verdictDelivery } from "./advisor-chat.js";
41
+ import { didNotLand } from "./regenerate/failure-reports.js";
42
+ import { conformanceRefusal, createWorkLoop, describeModules, isUpToDate } from "./regenerate/loop.js";
45
43
  import { brandNeon, brandPink, plainPaint } from "./regenerate/plain-palette.js";
46
44
  import { halfBlocks, JELLYFISH_FRAME_MS, JELLYFISH_REST, JELLYFISH_SEQUENCE, JELLYFISH_TEXT_FRAMES } from "./jellyfish.js";
47
45
  import { createJobPanel, didNotPass, keyPressed, PANEL_KEY, spinner } from "./regenerate/job-panel.js";
@@ -60,7 +58,6 @@ import { describeTurnIncident, describeUsage, JobStoppedError, onModelEvent } fr
60
58
  import { ledgerWanted, startLedger } from "./regenerate/ledger.js";
61
59
  import { describePastPulse, describeRuns, earlierPulses, ledgerProjects } from "./regenerate/ledger-view.js";
62
60
  import { doctorTool } from "./doctor-tool.js";
63
- import { ledgerTool } from "./ledger-tools.js";
64
61
  import { describeSpecConflict } from "./regenerate/stop-report.js";
65
62
  import { inheritProviders, inheritThinkingLevel } from "./pi.js";
66
63
  import { LOADING_PROVIDERS } from "./installed-providers.js";
@@ -84,7 +81,7 @@ import { currentChat } from "./chat-scope.js";
84
81
  import { registerChats } from "./chat-commands.js";
85
82
  import { turriIdentity } from "./environment.js";
86
83
  import { answerSideQuestion, askWithAsides, BTW_HOW, runningSkill, skillRunStarted, skillSessionText, transcriptOf } from "./btw.js";
87
- import { createJobRegistry, defaultParallelJobs, describeJob, firstRegeneration, formatDuration, formatElapsed, pulseName, shouldWait, STOPPED_ON_REQUEST, } from "./regenerate/jobs.js";
84
+ import { createJobRegistry, defaultParallelJobs, describeJob, formatDuration, pulseName, shouldWait, STOPPED_ON_REQUEST, } from "./regenerate/jobs.js";
88
85
  /**
89
86
  * Makes gated skills reachable from a conversation.
90
87
  *
@@ -351,30 +348,6 @@ export function createTurriCore(host = {}, options = {}) {
351
348
  setSurface(jobs, host.surface);
352
349
  // What release has shipped, module by module: release does nothing for a module whose last commit it already shipped.
353
350
  deployStates.set(jobs, createDeployState());
354
- // The test advisor watches what the work loop looks at, and picks up what it left pending when turri last quit.
355
- if (options.advisor === true) {
356
- // The conversation's own words on how the work is to be planned - AGENTS.md the advisor reads itself.
357
- const context = (plainFile) => [...steeringStore.get(EVERY_MODULE), ...steeringStore.get(moduleNameOf(plainFile))];
358
- const advisor = createTestAdvisor({
359
- context,
360
- // A verdict goes to the chat the person looks at - a host's too - which writes the scenarios on a yes.
361
- onVerdict: (verdict) => void session.advised(verdict),
362
- });
363
- advisors.set(jobs, advisor);
364
- // Where it may have left work pending: the folder turri runs in, and a project in a folder of it - ***plain kept in plain/.
365
- const projects = () => {
366
- try {
367
- return [cwd, ...readdirSync(cwd, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && existsSync(advisorDir(join(cwd, entry.name)))).map((entry) => join(cwd, entry.name))];
368
- }
369
- catch {
370
- return [cwd];
371
- }
372
- };
373
- setTimeout(() => {
374
- for (const project of projects())
375
- advisor.resume(project);
376
- }, 0).unref?.();
377
- }
378
351
  // What this session does, as facts, in the project's .turri/ledger - a pulse's own in its project. Said once, in the
379
352
  // chat shown, when it cannot be written.
380
353
  if (ledgerWanted()) {
@@ -546,8 +519,6 @@ function turriExtension(api, session, link) {
546
519
  void pi.sendMessage({ customType: "turri_job_landed", content: landedNote(job, runningDeployed(job.module), { shown }), display: false, details: { jobId: job.id, status: job.status } }, shown ? { triggerTurn: false } : { triggerTurn: true, deliverAs: "followUp" });
547
520
  };
548
521
  const notices = noticeDialogs(pi, session, link, contextNow);
549
- // The test advisor's verdicts, once the chat is idle: a yes starts a turn that writes its scenarios, a no is a line.
550
- const verdicts = verdictDelivery(pi, link, contextNow);
551
522
  link.live({
552
523
  announce,
553
524
  landed,
@@ -556,14 +527,12 @@ function turriExtension(api, session, link) {
556
527
  notice: notices.put,
557
528
  noticeOver: notices.over,
558
529
  concluded: notices.concluded,
559
- advised: verdicts.put,
560
530
  act: (task) => {
561
531
  void pi.sendMessage({ customType: "turri_notice_answer", content: task, display: false }, { triggerTurn: true, deliverAs: "followUp" });
562
532
  },
563
533
  jobsChanged: () => panel.refresh(),
564
534
  thinkingLevel: () => pi.getThinkingLevel(),
565
535
  context: contextNow,
566
- conformanceSwitched: () => conformanceTools(),
567
536
  });
568
537
  pi.on("session_start", (_event, ctx) => {
569
538
  lastContext = ctx;
@@ -616,8 +585,6 @@ function turriExtension(api, session, link) {
616
585
  pulseEndsBlock(session.sentinelOn()),
617
586
  // Conformance tests - what they are, whether they are on here, and how they are turned on: every turn, read afresh.
618
587
  conformanceBlock(conformanceTestsOnIn(cwd)),
619
- // The test advisor, and that the chat alone writes scenarios - while the session has one the project wants.
620
- ...(sessionAdvisor(session) !== undefined && conformanceTestsOnIn(cwd) && readProjectConfig(cwd).testAdvisor !== false ? [TEST_ADVISOR_BLOCK] : []),
621
588
  projectConfigBlock(cwd),
622
589
  machineBlock(cwd, machine.now()),
623
590
  rulesBlock(),
@@ -737,40 +704,12 @@ function turriExtension(api, session, link) {
737
704
  });
738
705
  registerRegenerate(pi, cwd, jobs);
739
706
  registerDrift(pi, cwd, jobs);
740
- registerGlimpse(pi, cwd, jobs);
741
- registerBind(pi, cwd, jobs);
707
+ registerBind(pi, cwd, jobs, (plainFile) => turnOnConformance(session, plainFile));
742
708
  registerRenderModels(pi);
743
709
  registerDeploy(pi, cwd, jobs, deployStates.get(jobs) ?? createDeployState());
744
710
  registerSteering(pi, cwd);
745
711
  registerSideQuestions(pi, cwd, jobs);
746
712
  registerStacks(pi, cwd);
747
- // The chat's own way to the test advisor, while the session has one - whatever test-advisor says.
748
- if (sessionAdvisor(session) !== undefined)
749
- pi.registerTool(evaluateTestsTool({ cwd, advisor: () => sessionAdvisor(session) }));
750
- // Conformance tests on or off: conform and evaluate_tests are the chat's while they are on, the tool that turns them on
751
- // while they are off - set as each turn starts, and at once when the chat turns them on. Not the sentinel's: it has its own.
752
- const conformanceTools = () => {
753
- if (isSentinel)
754
- return;
755
- try {
756
- const on = conformanceTestsOnIn(cwd);
757
- const registered = new Set(pi.getAllTools().map((tool) => tool.name));
758
- const active = pi.getActiveTools();
759
- const wanted = [
760
- ...active.filter((name) => !CONFORMANCE_TOOLS.includes(name) && name !== TURN_ON_TOOL),
761
- ...(on ? CONFORMANCE_TOOLS : [TURN_ON_TOOL]).filter((name) => registered.has(name)),
762
- ];
763
- if (wanted.length !== active.length || wanted.some((name) => !active.includes(name)))
764
- pi.setActiveTools(wanted);
765
- }
766
- catch {
767
- /* not bound to a session yet: the next turn sets them */
768
- }
769
- };
770
- if (!isSentinel)
771
- pi.registerTool(turnOnConformanceTestsTool({ turnOn: (plainFile) => turnOnConformance(session, plainFile) }));
772
- pi.on("session_start", () => conformanceTools());
773
- pi.on("before_agent_start", () => conformanceTools());
774
713
  // More chats beside this one, in the terminal: /chat, alt+n, alt+1…9 (chat-commands.ts).
775
714
  if (session.terminal)
776
715
  registerChats(pi, session);
@@ -818,7 +757,7 @@ function turriExtension(api, session, link) {
818
757
  .filter((part) => part !== undefined && part.trim() !== "")
819
758
  .join("\n\n");
820
759
  const filesBefore = projectFiles(cwd);
821
- const writes = ["write", "edit", "bash", "change_plain"].some((tool) => skill.allowedTools.includes(tool));
760
+ const writes = ["write", "edit", "bash"].some((tool) => skill.allowedTools.includes(tool));
822
761
  const quiet = { step: () => { }, artifact: () => { }, gate: () => { }, judge: () => { }, outcome: () => { } };
823
762
  const about = runDetails(kind, shown);
824
763
  const end = (ended) => skillRunEnds.put(ended.ok
@@ -913,7 +852,7 @@ function turriExtension(api, session, link) {
913
852
  // The conformance testing script is for conformance tests: none is written while they are off.
914
853
  if (scriptKindOfSkill(skill.name) === "conformance" && !conformanceTestsOnIn(cwd)) {
915
854
  return {
916
- content: [{ type: "text", text: `${skill.name} writes the conformance testing script, and conformance tests are off for this project (conformance-tests: false, or unset). Turn them on first - with ${TURN_ON_TOOL}, once the person asked for them or agreed - then run it. Nothing was started.` }],
855
+ content: [{ type: "text", text: `${skill.name} writes the conformance testing script, for conformance tests. ${CONFORMANCE_OFF_REFUSAL}` }],
917
856
  details: { notStarted: true },
918
857
  };
919
858
  }
@@ -1048,8 +987,6 @@ function turriExtension(api, session, link) {
1048
987
  const filesBefore = projectFiles(cwd);
1049
988
  // A side question asked while it runs is told what it has done so far.
1050
989
  const ended = skillRunStarted({ skill: skill.name, dir: skill.dir, step: () => live.step, trace: () => [...trace], runDir });
1051
- // From here the time to first regeneration is counted, for a skill that writes spec diffs: its first pulse started.
1052
- const began = Date.now();
1053
990
  const ran = await captureConsole(() => runSkill({
1054
991
  skillDir: skill.dir,
1055
992
  // The chat's turn stopped - ctrl+c, esc - stops the run with it.
@@ -1126,7 +1063,7 @@ function turriExtension(api, session, link) {
1126
1063
  push(noise);
1127
1064
  const changes = changedFiles(filesBefore, projectFiles(cwd, filesBefore.keys()));
1128
1065
  // A skill that only reads and reports - an analysis - changes nothing, and its result is its verdict.
1129
- const writes = ["write", "edit", "bash", "change_plain"].some((tool) => skill.allowedTools.includes(tool));
1066
+ const writes = ["write", "edit", "bash"].some((tool) => skill.allowedTools.includes(tool));
1130
1067
  const changed = changes.length > 0
1131
1068
  ? `It changed ${changes.length} file${changes.length === 1 ? "" : "s"} in the project: ${changes.join(", ")}.`
1132
1069
  : writes
@@ -1139,22 +1076,16 @@ function turriExtension(api, session, link) {
1139
1076
  const owner = moduleOfTestPlainFile(resolve(cwd, path));
1140
1077
  return owner === undefined ? path : `${path} (a test plain file of ${owner.plainFile !== undefined ? relative(cwd, owner.plainFile) : owner.module})`;
1141
1078
  });
1142
- const unrendered = specsChanged.length > 0 && !skill.allowedTools.includes("change_plain")
1079
+ const unrendered = specsChanged.length > 0
1143
1080
  ? `${named.join(", ")} changed, and nothing is regenerated from that yet: call regenerate for ${named.length === 1 ? "its module" : "their modules"}, and the code and its conformance tests are brought up to the spec.`
1144
1081
  : "";
1145
1082
  const gated = skill.steps.some((step) => step.gate !== undefined);
1146
- const first = skill.allowedTools.includes("change_plain") ? firstRegeneration(jobs.list(), began) : {};
1147
- const ttfr = first.started === undefined
1148
- ? ""
1149
- : `Time to first regeneration: ${formatElapsed(first.started)} - its first pulse started that long after ${skill.name} began` +
1150
- (first.landed !== undefined ? `, and landed after ${formatElapsed(first.landed)}.` : ".");
1151
1083
  const said = heard.length > 0 ? ["", `While it ran, the person said to it - its agent read and acted on each:`, ...heard.map((text) => `- ${text.replace(/\s+/g, " ").trim()}`)] : [];
1152
1084
  const text = result.ok
1153
1085
  ? [
1154
1086
  gated ? `${skill.name}: passed all gates.` : `${skill.name}: finished. It has no review gates, so nothing checked its work: read what it changed before you report it.`,
1155
1087
  changed,
1156
1088
  ...(unrendered !== "" ? [unrendered] : []),
1157
- ...(ttfr !== "" ? [ttfr] : []),
1158
1089
  ...said,
1159
1090
  "",
1160
1091
  "<artifact>",
@@ -1187,41 +1118,13 @@ function registerRegenerate(pi, cwd, jobs) {
1187
1118
  const command = `/regenerate ${args.trim()}`.trim();
1188
1119
  await echoCommand(pi, command);
1189
1120
  const say = (text, level) => shownAfterCommand(pi, ctx, command, text, level, true);
1190
- const all = args.trim().split(/\s+/).filter((word) => word !== "");
1191
- const [first = ""] = all;
1192
- const { named, rest } = moduleNamedFirst(cwd, all);
1193
- if (named === undefined && first.endsWith(".plain")) {
1194
- say(`There is no ${first} here.`, "error");
1121
+ const picked = await commandModule(cwd, ctx, args, say, { verb: "regenerate", outcome: "regenerated" });
1122
+ if (picked === undefined)
1195
1123
  return;
1196
- }
1124
+ const { plainFile } = picked;
1197
1125
  // Functional specs named first, each as module:func-id, as on the command line; what follows them is guidance.
1198
- const words = rest;
1199
- const again = [];
1200
- while (words.length > 0 && /^[^\s:]+:[a-z0-9-]+,?$/.test(words[0]))
1201
- again.push(words.shift().replace(/,$/, ""));
1126
+ const { funcIds: again, rest: words } = funcIdsNamedFirst(picked.rest);
1202
1127
  const guidance = words.join(" ").trim();
1203
- let plainFile = named;
1204
- if (plainFile === undefined) {
1205
- const modules = defaultMapFiles(cwd);
1206
- if (modules.length === 0) {
1207
- say("No .plain file to regenerate: name one - /regenerate app.plain - or set module: in config.turri.yaml.", "warning");
1208
- return;
1209
- }
1210
- if (modules.length === 1 || !ctx.hasUI)
1211
- plainFile = modules[0];
1212
- else {
1213
- const label = (file) => relative(cwd, file) || basename(file);
1214
- const picked = await ctx.ui.select("Regenerate which module?", modules.map(label));
1215
- plainFile = modules.find((file) => label(file) === picked);
1216
- if (plainFile === undefined)
1217
- return;
1218
- }
1219
- }
1220
- const check = checkPlainFile(plainFile);
1221
- if (!check.ok) {
1222
- say(`${relative(cwd, plainFile) || plainFile} does not parse, so nothing can be regenerated from it yet:\n${formatCheckResults([check])}`, "error");
1223
- return;
1224
- }
1225
1128
  // From scratch - started over, its code deleted - asked in the person's words: started at once, as asked.
1226
1129
  const scratch = asksFromScratch(guidance);
1227
1130
  // The whole chain with it - "from scratch, the whole chain" - every module it requires built again from the bottom.
@@ -1270,6 +1173,55 @@ function registerRegenerate(pi, cwd, jobs) {
1270
1173
  },
1271
1174
  });
1272
1175
  }
1176
+ /**
1177
+ * The module a /regenerate or /conform is for, and the words after it: the one its first words name, else the one
1178
+ * `module:` names, else the folder's top modules to pick from - checked to parse. Undefined, said why, when there is
1179
+ * none to take, or the person picked none.
1180
+ */
1181
+ async function commandModule(cwd, ctx, args, say, words) {
1182
+ const all = args.trim().split(/\s+/).filter((word) => word !== "");
1183
+ const [first = ""] = all;
1184
+ const { named, rest } = moduleNamedFirst(cwd, all);
1185
+ if (named === undefined && first.endsWith(".plain")) {
1186
+ say(`There is no ${first} here.`, "error");
1187
+ return undefined;
1188
+ }
1189
+ let plainFile = named;
1190
+ if (plainFile === undefined) {
1191
+ const modules = defaultMapFiles(cwd);
1192
+ if (modules.length === 0) {
1193
+ say(`No .plain file to ${words.verb}: name one - /${words.verb} app.plain - or set module: in config.turri.yaml.`, "warning");
1194
+ return undefined;
1195
+ }
1196
+ if (modules.length === 1 || !ctx.hasUI)
1197
+ plainFile = modules[0];
1198
+ else {
1199
+ const label = (file) => relative(cwd, file) || basename(file);
1200
+ const picked = await ctx.ui.select(`${words.verb === "regenerate" ? "Regenerate" : "Conform"} which module?`, modules.map(label));
1201
+ plainFile = modules.find((file) => label(file) === picked);
1202
+ if (plainFile === undefined)
1203
+ return undefined;
1204
+ }
1205
+ }
1206
+ const check = checkPlainFile(plainFile);
1207
+ if (!check.ok) {
1208
+ say(`${relative(cwd, plainFile) || plainFile} does not parse, so nothing can be ${words.outcome} from it yet:\n${formatCheckResults([check])}`, "error");
1209
+ return undefined;
1210
+ }
1211
+ return { plainFile, rest };
1212
+ }
1213
+ /** The functional specs a command's words name first, each as module:func-id - a comma after one allowed - and the words after them. */
1214
+ export function funcIdsNamedFirst(words) {
1215
+ const rest = [...words];
1216
+ const funcIds = [];
1217
+ while (rest.length > 0 && /^[^\s:]+:[a-z0-9-]+,?$/.test(rest[0]))
1218
+ funcIds.push(rest.shift().replace(/,$/, ""));
1219
+ return { funcIds, rest };
1220
+ }
1221
+ /** Whether a /conform's words after its functional specs ask for a pulse a functional spec - "one by one", "separately". */
1222
+ export function asksOneByOne(words) {
1223
+ return /\b(one[\s-]+(by|at)[\s-]+(one|a[\s-]+time)|separately|each[\s-]+(on[\s-]+its[\s-]+own|alone))\b/i.test(words);
1224
+ }
1273
1225
  /**
1274
1226
  * What a slash command showed the person: kept in the chat, where they read it, and put in the conversation as well -
1275
1227
  * unseen there - so that when they speak of it next ("fix it"), the agent knows what they saw. A command runs outside
@@ -1294,12 +1246,24 @@ echoed = false, react) {
1294
1246
  void pi.sendMessage({ customType: COMMAND_OUTCOME, content, display: false }, { triggerTurn: true, deliverAs: "followUp" });
1295
1247
  }
1296
1248
  /**
1297
- * What the agent does once /regenerate has started pulses: a command's output alone leaves the chat silent, and the
1298
- * person wondering whether to wait. It says what runs, and that they need not - and starts nothing itself.
1249
+ * What the agent does once /regenerate or /conform has started pulses: a command's output alone leaves the chat silent,
1250
+ * and the person wondering whether to wait. It says what runs, and that they need not - and starts nothing itself.
1299
1251
  */
1300
- export const COMMAND_STARTED_REACTION = "My pulses are regenerating from the person's /regenerate, in the background. Tell the person, in a line or two, what " +
1252
+ export const COMMAND_STARTED_REACTION = "My pulses are running from the person's command, in the background. Tell the person, in a line or two, what " +
1301
1253
  "runs and what is planned - and that the two of us can go on with the ***plain, or anything else, meanwhile: they need " +
1302
1254
  "not wait for it. Start nothing for it: no regenerate, no check, no release - its end is told when it comes.";
1255
+ /**
1256
+ * What the agent does when /conform started nothing: answers it at once - why, and what would let it start - and offers
1257
+ * to do that, rather than leave the person with a refusal and a silent chat.
1258
+ */
1259
+ export const CONFORM_REFUSED_REACTION = "Nothing was started from the person's /conform, for the reason shown - and their /conform is their yes to conformance " +
1260
+ "tests here. Where what is missing is yours to write - the test reqs, the conformance testing script, the scenarios - " +
1261
+ "write it now, in that order and only what is missing, asking nothing: the scenarios of the functional specs they named, " +
1262
+ "or, naming none, of each functional spec that needs them by the rules on test plain files. Then call regenerate for the " +
1263
+ "module: the work loop writes and runs their tests once the code is built. Say in a line or two what you wrote, and for " +
1264
+ "each functional spec why it needs scenarios - or, when none does, that and why. Where it is not yours to settle - a " +
1265
+ "functional spec they named that is not there, ***plain that would have to change its meaning to be tested - tell them " +
1266
+ "why nothing started and what would let it, and start nothing.";
1303
1267
  export const COMMAND_OUTCOME = "turri_command_outcome";
1304
1268
  /** Longer than a frame of the TUI's (16ms): an entry appended before it is drawn by its end. */
1305
1269
  const ONE_FRAME_MS = 20;
@@ -1346,13 +1310,89 @@ function plainFileNamed(cwd, word) {
1346
1310
  function registerDrift(pi, cwd, jobs) {
1347
1311
  pi.registerTool(driftTool({ cwd, jobs, loop: (ctx) => workLoopFor(jobs, cwd, ctx) }));
1348
1312
  }
1349
- function registerBind(pi, cwd, jobs) {
1313
+ function registerBind(pi, cwd, jobs, turnOn) {
1350
1314
  pi.registerTool(conformTool({
1351
1315
  cwd,
1352
1316
  loop: (ctx) => workLoopFor(jobs, cwd, ctx),
1353
1317
  model: (ctx, plainFile, named) => jobModel(ctx, "spec_changes", named, plainFile),
1354
1318
  wait: (ctx, asked) => shouldWait(ctx.mode, asked),
1355
1319
  }));
1320
+ // /conform: the same as the tool, from the person - a module's conformance tests written and run now, for the
1321
+ // functional specs named or every one with scenarios, in one pulse unless asked for one a functional spec. Asking for
1322
+ // them is asking for them on: off, they are turned on first. What would start nothing is found before anything is
1323
+ // said, and the chat's agent answers it at once.
1324
+ pi.registerCommand("conform", {
1325
+ description: "Write and run a module's conformance tests now - the functional specs named, or every one with scenarios - in one pulse, or one a functional spec when asked; turned on first when they are off: /conform [module | file.plain] [module:func-id ...] [one by one]",
1326
+ handler: async (args, ctx) => {
1327
+ const command = `/conform ${args.trim()}`.trim();
1328
+ await echoCommand(pi, command);
1329
+ /** Nothing started: shown, and the agent told to answer it now. */
1330
+ const refuse = (text) => shownAfterCommand(pi, ctx, command, text, "error", true, CONFORM_REFUSED_REACTION);
1331
+ const picked = await commandModule(cwd, ctx, args, (text, level) => (level === "info" ? shownAfterCommand(pi, ctx, command, text, level, true) : refuse(text)), {
1332
+ verb: "conform",
1333
+ outcome: "conformance tested",
1334
+ });
1335
+ if (picked === undefined)
1336
+ return;
1337
+ const { plainFile } = picked;
1338
+ const { funcIds, rest } = funcIdsNamedFirst(picked.rest);
1339
+ const words = rest.join(" ").trim();
1340
+ const separately = asksOneByOne(words);
1341
+ // Nothing but the functional specs and one by one: no planner reads guidance here, so other words are not dropped unsaid.
1342
+ if (words !== "" && !separately) {
1343
+ refuse(`/conform takes functional specs, each as module:func-id, and "one by one" - not "${words}". Nothing was started.`);
1344
+ return;
1345
+ }
1346
+ // Off: turned on - written where the module's value comes from, every chat's tools switched - and said with what follows.
1347
+ let turnedOn;
1348
+ try {
1349
+ if (!conformanceTestsOn(plainFile))
1350
+ turnedOn = `Conformance tests are on now - conformance-tests: true, written in ${turnOn(plainFile)}.`;
1351
+ }
1352
+ catch (error) {
1353
+ refuse(`Conformance tests could not be turned on: ${error instanceof Error ? error.message : String(error)}. Nothing was started.`);
1354
+ return;
1355
+ }
1356
+ const withTurnedOn = (text) => (turnedOn !== undefined ? `${turnedOn}\n${text}` : text);
1357
+ // What would start nothing - no scenarios, a functional spec not there, a step of adding tests skipped - read from the
1358
+ // ***plain alone, before anything is said.
1359
+ let refusal;
1360
+ try {
1361
+ refusal = withCallStack(plainFile, undefined, () => conformanceRefusal(plainFile, funcIds.length > 0 ? funcIds : undefined));
1362
+ }
1363
+ catch (error) {
1364
+ refusal = error instanceof Error ? error.message : String(error);
1365
+ }
1366
+ if (refusal !== undefined) {
1367
+ refuse(withTurnedOn(refusal));
1368
+ return;
1369
+ }
1370
+ const module = basename(plainFile).replace(/\.plain$/, "");
1371
+ const model = jobModel(ctx, "spec_changes", undefined, plainFile);
1372
+ shownAfterCommand(pi, ctx, command, withTurnedOn(`Starting ${funcIds.length > 0 ? `the conformance tests of ${funcIds.join(", ")}` : `${module}'s conformance tests`}…`), "info", true);
1373
+ await nextFrame();
1374
+ // In the background, as /regenerate: a codebase built on the module may be stopped and deleted first.
1375
+ void (async () => {
1376
+ try {
1377
+ const statuses = await withCallStack(plainFile, undefined, () => workLoopFor(jobs, cwd, ctx).conformance(plainFile, {
1378
+ ...(funcIds.length > 0 ? { funcIds } : {}),
1379
+ ...(model !== undefined ? { model } : {}),
1380
+ ...(separately ? { separately: true } : {}),
1381
+ }));
1382
+ // Nothing to write: said in the loop's words - "up to date" alone speaks of the code, not its tests.
1383
+ const upToDate = statuses.length > 0 && statuses.every(isUpToDate);
1384
+ const note = statuses.find((status) => status.conformanceNote !== undefined)?.conformanceNote;
1385
+ const text = upToDate ? `${(note ?? `the conformance tests of ${module} are written for it as built: there is nothing to write`).replace(/^./, (c) => c.toUpperCase())}.` : describeModules(statuses);
1386
+ shownAfterCommand(pi, ctx, command, text, "info", true, upToDate ? undefined : COMMAND_STARTED_REACTION);
1387
+ }
1388
+ catch (error) {
1389
+ refuse(error instanceof Error ? error.message : String(error));
1390
+ }
1391
+ })().catch(() => {
1392
+ // The chat let go meanwhile: there is nobody to say it to.
1393
+ });
1394
+ },
1395
+ });
1356
1396
  }
1357
1397
  /**
1358
1398
  * conform, for the conversation and for a skill that names it in its allowed-tools - the skill's on the conversation's
@@ -1372,10 +1412,12 @@ function conformTool(options) {
1372
1412
  "tests are behind, once the module's code is built; conform starts them now, or for the functional specs named - those alone: the module's others stay behind until conform names none, or the module is regenerated. A " +
1373
1413
  "functional spec with no scenarios - no test plain file - is refused: there is nothing to test until scenarios " +
1374
1414
  "are written. So is one the spec does not have, and a module with scenarios that skipped a step of adding tests - " +
1375
- "no test reqs, or no conformance testing script for its stack: the refusal names the next step.",
1415
+ "no test reqs, or no conformance testing script for its stack: the refusal names the next step. While conformance tests " +
1416
+ "are off it is refused too: they make each change take about twice as long, and turning them on is the person's - " +
1417
+ "with /conform - never yours.",
1376
1418
  promptSnippet: "conform: write and run the conformance tests of functional specs with scenarios",
1377
1419
  promptGuidelines: [
1378
- "What is tested is the scenarios: a functional spec's conformance and acceptance scenarios, in its test plain file, tests/<module>/<func-id>.plain. When the user asks for conformance tests, decide in a sentence or two which scenarios to write, and write them with change_plain - a test plain file's ***conformance tests*** and ***acceptance tests***, each scenario a # <scenario-id> heading and its text. Every scenario written is tested once the code is built: the loop starts the conformance pulse by itself. Never edit config.turri.yaml for it, and never regenerate a functionality to get them.",
1420
+ "What is tested is the scenarios: a functional spec's conformance and acceptance scenarios, in its test plain file, tests/<module>/<func-id>.plain. When the user asks for conformance tests, decide in a sentence or two which scenarios to write, write them with the file tools - a test plain file's ***conformance tests*** and ***acceptance tests***, each scenario a # <scenario-id> heading and its text - then call regenerate for the module. Every scenario written is tested once the code is built: the loop starts the conformance pulse by itself. Never edit config.turri.yaml for it, and never name a functionality in funcIds to get them.",
1379
1421
  "Call conform when the user asks for the conformance tests to be written or run now, for a module or some of its functional specs with scenarios.",
1380
1422
  "What the user asks for comes first: for a module already regenerated, while a module built on it is being regenerated, conform stops that pulse, deletes the codebase built on it, writes the tests, and the module above is regenerated from it after - say so. For a module not regenerated yet, its tests are written once its code is built, before anything is built on it.",
1381
1423
  "Conformance tests go in one pulse for all the functional specs tested. Set one_by_one only when the user asks for a pulse a functional spec - one at a time, separately, or the like.",
@@ -1394,6 +1436,9 @@ function conformTool(options) {
1394
1436
  const plainFile = resolve(params.base, params.plain_file);
1395
1437
  refuseTestPlainFile(plainFile);
1396
1438
  return withCallStack(plainFile, params.stack, async () => {
1439
+ // Off: the person's to turn on, never the chat's - it is told to say why it wants them, and they decide.
1440
+ if (!conformanceTestsOn(plainFile))
1441
+ return { content: [{ type: "text", text: CONFORMANCE_OFF_REFUSAL }], details: { refused: true } };
1397
1442
  const model = options.model(ctx, plainFile, params.model);
1398
1443
  const loop = options.loop(ctx);
1399
1444
  const statuses = await loop.conformance(plainFile, {
@@ -1406,55 +1451,6 @@ function conformTool(options) {
1406
1451
  },
1407
1452
  });
1408
1453
  }
1409
- function registerGlimpse(pi, cwd, jobs) {
1410
- pi.registerTool({
1411
- name: "glimpse",
1412
- label: "Glimpse the next pulse",
1413
- description: "Plan the work of a module as regenerate would, and show the pulse each codebase would start next and the whole " +
1414
- "prompt its coding agent would get - starting nothing. A codebase with a pulse running is left out: what its next pulse " +
1415
- "is given depends on what the running one lands.",
1416
- promptSnippet: "glimpse: the next pulse of a module and its coding agent's whole prompt, starting nothing",
1417
- promptGuidelines: [
1418
- "Use glimpse when the user wants to see what a pulse will be told before it runs, or to check a plan before steering it with steer.",
1419
- ],
1420
- parameters: Type.Object({
1421
- plain_file: Type.String({ description: "Path to the .plain file" }),
1422
- working_dir: WORKING_DIR_PARAM,
1423
- stack: STACK_PARAM,
1424
- }),
1425
- async execute(_id, given, _signal, _onUpdate, ctx) {
1426
- const params = fromWorkingDir(cwd, given);
1427
- const plainFile = resolve(params.base, params.plain_file);
1428
- refuseTestPlainFile(plainFile);
1429
- return withCallStack(plainFile, params.stack, async () => {
1430
- const running = new Set(workLoopFor(jobs, cwd, ctx).status().filter((status) => status.running !== undefined).map((status) => status.module));
1431
- const planner = chatModelOf(ctx);
1432
- const model = modelFor(chosenModels, "spec_changes", projectModel(ctx, plainFile) ?? planner);
1433
- const { statuses, previews, busy } = await previewJobs({
1434
- plainFile,
1435
- cwd,
1436
- ...(model !== undefined ? { model } : {}),
1437
- ...(planner !== undefined ? { plannerModel: planner } : {}),
1438
- steering: (file) => steeringFor(file, cwd, steeringStore),
1439
- busy: (module) => running.has(module),
1440
- });
1441
- const text = [
1442
- describeModules(statuses),
1443
- ...busy.map((module) => `\n${module} has a pulse running: its next pulse is planned from what that one lands - preview it once it has.`),
1444
- ...previews.map((preview) => [
1445
- "",
1446
- `<next pulse module="${preview.module}" track="${preview.track}" title="${preview.title}">`,
1447
- preview.task ?? "A conformance pulse's prompt is built from what the code it tests holds once it is built: it is not shown before.",
1448
- "</next pulse>",
1449
- ].join("\n")),
1450
- "",
1451
- "Nothing was started. Tell the user what the next pulse is and what it will be told - the parts they are likely to care about, not the whole prompt unless they ask.",
1452
- ].join("\n");
1453
- return { content: [{ type: "text", text }], details: {} };
1454
- });
1455
- },
1456
- });
1457
- }
1458
1454
  /** The config a spec is built with - its project's, with the chosen stack's over it - or, with no spec, the session folder's. */
1459
1455
  function configOf(plainFile) {
1460
1456
  return plainFile !== undefined ? configForSpec(resolve(process.cwd(), plainFile)) : readProjectConfig(process.cwd(), stackOf(process.cwd()));
@@ -1574,7 +1570,7 @@ export function projectConfigBlock(root) {
1574
1570
  return [
1575
1571
  ...settings(readProjectConfig(dir), withStack(undefined, () => findTestScripts(dir)), dir === root ? `${projectConfigFile(dir)}, for the specs here:` : `${relative(root, dir)}/${projectConfigFile(dir)}, for the specs in ${relative(root, dir)}/ - built in ${relative(root, dir)}/plain_modules:`, where, stacks.length > 0 ? "project of stacks" : "project"),
1576
1572
  ...(stacks.length > 0
1577
- ? ["", `Stacks: ${stacks.join(", ")} - chosen now: ${chosen ?? "none, so the project's file alone"}. Each module is built with the stack of its part, pinned to its pulses whatever is chosen after: a stack named after the module is its own - backend.plain is built with config.turri.backend.yaml - with nothing to choose. For a module whose stack has another name, pass it as stack to regenerate, conform, glimpse and change_plain. Choose one for this chat with the stack tool only when the user asks.`]
1573
+ ? ["", `Stacks: ${stacks.join(", ")} - chosen now: ${chosen ?? "none, so the project's file alone"}. Each module is built with the stack of its part, pinned to its pulses whatever is chosen after: a stack named after the module is its own - backend.plain is built with config.turri.backend.yaml - with nothing to choose. For a module whose stack has another name, pass it as stack to regenerate, conform and pulses. Choose one for this chat with the stack tool only when the user asks.`]
1578
1574
  : []),
1579
1575
  // A stack: its file over the project's, for everything built while it is chosen.
1580
1576
  ...stacks.flatMap((stack) => [
@@ -1592,7 +1588,7 @@ export function projectConfigBlock(root) {
1592
1588
  ...[
1593
1589
  config.module !== undefined && of !== "stack" ? `- module: ${config.module}${where} - the module to build when the user does not name one.` : undefined,
1594
1590
  of !== "stack"
1595
- ? "- conformance tests: written for every functional spec with scenarios - the conformance and acceptance scenarios of its test plain file - once the module's code is built, before anything is built on it. A functional spec with an empty test plain file is not tested. To have one tested, write its scenarios with change_plain."
1591
+ ? "- conformance tests: written for every functional spec with scenarios - the conformance and acceptance scenarios of its test plain file - once the module's code is built, before anything is built on it. A functional spec with an empty test plain file is not tested. To have one tested, write its scenarios with the file tools, then call regenerate."
1596
1592
  : undefined,
1597
1593
  config.review === true
1598
1594
  ? "- review: true - the code and its tests are reviewed once they pass: two reviews at most, the arbiter weighing the second."
@@ -1672,21 +1668,12 @@ function chatModelOf(ctx) {
1672
1668
  let lastChatModel;
1673
1669
  /**
1674
1670
  * Conformance tests turned on, for the session: `conformance-tests: true` written where the module's value comes from
1675
- * (conformance-switch.ts), and every open chat's tools switched to match - what the chat's turn_on_conformance_tests and a
1676
- * host's turnOnConformanceTests both do. `plainFile`, absolute or from the project, picks the module whose stack's file
1671
+ * (conformance-switch.ts) - what /conform does when they are off, and a host's turnOnConformance. Every chat is told at
1672
+ * its next turn. `plainFile`, absolute or from the project, picks the module whose stack's file
1677
1673
  * is written when that names the key. Returns the file written, from the project. Starts no conformance pulse.
1678
1674
  */
1679
1675
  export function turnOnConformance(core, plainFile) {
1680
1676
  const file = turnOnConformanceTests(core.cwd, plainFile !== undefined && plainFile.trim() !== "" ? resolve(core.cwd, plainFile) : undefined);
1681
- for (const chat of core.chats()) {
1682
- const live = core.session(chat.id);
1683
- try {
1684
- (live !== undefined ? core.chatOfSession(live) : undefined)?.instance?.conformanceSwitched?.();
1685
- }
1686
- catch {
1687
- /* a chat let go: its next turn sets its tools */
1688
- }
1689
- }
1690
1677
  return file;
1691
1678
  }
1692
1679
  /** The skills running in the background, by project and skill - one at a time each, whichever chat started it - with what stops them. */
@@ -1778,9 +1765,8 @@ function setRenderModelTool(pi, conversation) {
1778
1765
  name: "engine",
1779
1766
  label: "Engine",
1780
1767
  description: "The engine: which model the agents that regenerate the code run on. With no model, say which it is. With one, choose it " +
1781
- "for the rest of this session: for spec changes " +
1782
- "(render spec diff pulses, and the ones change_plain queues), for functionalities (render, module, " +
1783
- "regenerate with functionalities named, conformance), or for everything. By default " +
1768
+ "for the rest of this session: for spec changes (every pulse the work loop plans, conformance tests included), for " +
1769
+ "functionalities (regenerate with funcIds named), or for everything. By default " +
1784
1770
  "each runs on the model the project's config.turri.yaml names, or else the conversation's model. The model may be given as provider/model-id or by name as " +
1785
1771
  "the user said it; a name that fits more than one model, or none with credentials, comes back as a " +
1786
1772
  "list - ask the user which they meant, never pick one yourself. Pulses already queued keep their model.",
@@ -1788,7 +1774,7 @@ function setRenderModelTool(pi, conversation) {
1788
1774
  promptGuidelines: [
1789
1775
  "When the user says which model should regenerate or build something, call engine with it - once; it holds for the rest of the session. To say which one it is, call engine with no model.",
1790
1776
  "If engine returns several candidates, ask the user which one with ask_user or in your reply, then call it again with the exact provider/model-id.",
1791
- "Say which model a render will run on when you start one on something other than the conversation's model.",
1777
+ "Say which model a pulse will run on when you start one on something other than the conversation's model.",
1792
1778
  ],
1793
1779
  parameters: Type.Object({
1794
1780
  work: Type.Optional(Type.Union([Type.Literal("spec_changes"), Type.Literal("functionalities"), Type.Literal("all")], {
@@ -1871,12 +1857,6 @@ const workLoops = new WeakMap();
1871
1857
  const steeringStore = createSteeringStore();
1872
1858
  /** What release has shipped in a conversation, by its jobs: shared by the chat's release and a pulse's own. */
1873
1859
  const deployStates = new WeakMap();
1874
- /** A session's test advisor, by its jobs - only a chat's or a host's has one. */
1875
- const advisors = new WeakMap();
1876
- /** The session's test advisor, when it has one: the chat's and a host's - never pi's print, json and rpc modes'. */
1877
- export function sessionAdvisor(session) {
1878
- return advisors.get(session.jobs);
1879
- }
1880
1860
  function workLoopFor(jobs, cwd, ctx) {
1881
1861
  let shared = workLoops.get(jobs);
1882
1862
  if (shared === undefined) {
@@ -1889,8 +1869,6 @@ function workLoopFor(jobs, cwd, ctx) {
1889
1869
  plannerModel: () => chatModelOf(from.ctx),
1890
1870
  // How the work is to be planned: the conversation's steering, and AGENTS.md's - read afresh each plan.
1891
1871
  steering: (plainFile) => steeringFor(plainFile, cwd, steeringStore),
1892
- // What the loop looks at, the test advisor sees - in a session that has one.
1893
- onSpec: (seen) => advisors.get(jobs)?.seen(seen),
1894
1872
  // Under release-after-pulse, a pulse releases what it landed itself, before the next starts - on the model that
1895
1873
  // regenerated it: a release follows steps, and a small model thinking little does that well.
1896
1874
  release: ({ plainFile, moduleName, title, onDelta }) => {
@@ -1905,7 +1883,6 @@ function workLoopFor(jobs, cwd, ctx) {
1905
1883
  });
1906
1884
  },
1907
1885
  });
1908
- bindAdvisor(loop, () => advisors.get(jobs));
1909
1886
  shared = { loop, from };
1910
1887
  workLoops.set(jobs, shared);
1911
1888
  }
@@ -1973,53 +1950,59 @@ const needsLooking = new WeakMap();
1973
1950
  const pastPulseNote = "A pulse of an earlier session, as the ledger recorded it - facts, not its transcript. Its whole log is the file it names, " +
1974
1951
  "for the read tool.";
1975
1952
  function registerJobTools(pi, jobs, cwd) {
1976
- pi.registerTool({
1977
- name: "diagnose",
1978
- label: "Diagnose a pulse",
1979
- description: "Why a pulse did not land, from its whole transcript: how it ended and its diagnosis, the stages that went wrong, the " +
1980
- "last failing test run with its output, the last review that sent the work back, and the tool calls that failed - " +
1981
- "and where the whole log is. A pulse of an earlier session is told from the ledger - what it recorded of it, as facts.",
1982
- promptSnippet: "diagnose: why a pulse did not land, from its transcript",
1983
- promptGuidelines: ["When a pulse failed or did not land, call diagnose before you explain it or change the spec: go by what happened, not by the report alone."],
1984
- parameters: Type.Object({ job_id: Type.String({ description: "The pulse's id" }) }),
1985
- async execute(_id, params) {
1986
- const job = jobs.get(params.job_id);
1987
- if (job === undefined) {
1988
- const past = describePastPulse(ledgerProjects(cwd), params.job_id);
1989
- if (past !== undefined)
1990
- return { content: [{ type: "text", text: `${pastPulseNote}\n\n${past}` }], details: { status: "earlier" } };
1991
- return { content: [{ type: "text", text: `No pulse ${params.job_id} has run in this session, and the ledger has none by that id.` }], details: { status: "unknown" } };
1992
- }
1993
- // What the ledger recorded of it besides: its rounds, test runs, healers and commits, as facts.
1994
- const facts = describePastPulse(ledgerProjects(cwd), job.id);
1995
- const text = facts !== undefined ? `${whyFailed(job)}\n\nWhat the ledger recorded of it:\n${facts}` : whyFailed(job);
1996
- return { content: [{ type: "text", text }], details: { status: job.status } };
1997
- },
1998
- });
1999
- pi.registerTool(ledgerTool({ cwd }));
2000
1953
  pi.registerTool(doctorTool({ cwd }));
2001
1954
  pi.registerTool({
2002
1955
  name: "pulses",
2003
1956
  label: "Pulses",
2004
- description: "What is regenerating: with no pulse, every pulse of this session - running, planned and finished - and what deploy started; " +
2005
- "with a pulse's id, that pulse - whether it is still running, its latest output, and its report once it has finished. " +
2006
- "A pulse of an earlier session is told from the ledger.",
2007
- promptSnippet: "pulses: every pulse, or one - what is regenerating and how it is going",
1957
+ description: "Pulses in every tense - earlier sessions', this session's, running now and what runs next. With no parameter: every pulse of " +
1958
+ "this session - finished, running, and planned, those of a look ahead marked as waiting for regenerate - what activate started, " +
1959
+ "and the last runs of earlier sessions, a line a pulse - how each ended, how long, what it cost. With job_id, one pulse: " +
1960
+ "running, whether it still is and its latest output; finished, its report and what the ledger recorded of it - its rounds " +
1961
+ "and test runs (how many failed the same way), the verdicts, the healers, the model provider's trouble, what turri refused, " +
1962
+ "what it committed - and, one that did not land, why, from its whole transcript: its diagnosis, the stages that went wrong, " +
1963
+ "the last failing test run with its output, the last review that sent the work back, the tool calls that failed, and where " +
1964
+ "the whole log is; of an earlier session, told from the ledger; planned (planned-<module>-N), its cases and - the next pulse " +
1965
+ "of its codebase - the whole prompt its coding agent will get, from the plan regenerate runs. With plain_file, a look " +
1966
+ "ahead: that module's work planned as regenerate plans it, steering and all, and kept - nothing started, its pulses waiting " +
1967
+ "for regenerate, which then runs this plan unless the ***plain or the steering changed - and what is planned listed. " +
1968
+ "What is left to regenerate, without a plan, is drift's.",
1969
+ promptSnippet: "pulses: every pulse or one - earlier, running or planned - why one did not land, and with plain_file what will run next and its prompt",
1970
+ promptGuidelines: [
1971
+ "When a pulse failed or did not land, call pulses with its id before you explain it or change the spec: go by what happened, not by the report alone.",
1972
+ "Call pulses with plain_file when the user wants to see or check what will run before it does, then with a planned row's id for its prompt. To change the plan, use steer or change the ***plain, then look again.",
1973
+ ],
2008
1974
  parameters: Type.Object({
2009
- job_id: Type.Optional(Type.String({ description: "The id returned when the pulse started. Omitted: every pulse" })),
2010
- wait: Type.Optional(Type.Boolean({ description: "With a pulse: block until it finishes instead of reporting its current state" })),
1975
+ job_id: Type.Optional(Type.String({
1976
+ description: "One pulse: the id returned when it started, an earlier session's, or a planned row's (planned-<module>-N). Omitted: every pulse",
1977
+ })),
1978
+ plain_file: Type.Optional(Type.String({ description: "A look ahead: the .plain file of the module to plan, starting nothing. Not with job_id. Omitted: no look ahead" })),
1979
+ working_dir: WORKING_DIR_PARAM,
1980
+ stack: STACK_PARAM,
1981
+ wait: Type.Optional(Type.Boolean({ description: "With a pulse started: block until it finishes instead of reporting its current state (default false)" })),
1982
+ runs: Type.Optional(Type.Number({ description: `With no parameter: how many runs of earlier sessions to list (default ${EARLIER_RUNS})` })),
2011
1983
  }),
2012
- async execute(_id, params) {
1984
+ async execute(_id, params, _signal, _onUpdate, ctx) {
1985
+ if (params.plain_file !== undefined) {
1986
+ if (params.job_id !== undefined)
1987
+ return { content: [{ type: "text", text: "Pass job_id or plain_file, not both: plain_file looks ahead at a module, job_id tells one pulse." }], details: { status: "refused" } };
1988
+ const given = fromWorkingDir(cwd, params);
1989
+ const plainFile = resolve(given.base, given.plain_file);
1990
+ refuseTestPlainFile(plainFile);
1991
+ return withCallStack(plainFile, params.stack, async () => {
1992
+ const loop = workLoopFor(jobs, cwd, ctx);
1993
+ const statuses = await loop.lookAhead(plainFile);
1994
+ return { content: [{ type: "text", text: describeLookAhead(loop, statuses) }], details: { status: "looked ahead" } };
1995
+ });
1996
+ }
2013
1997
  if (params.job_id === undefined) {
2014
- return { content: [{ type: "text", text: listJobs(jobs, cwd) }], details: { status: "all" } };
1998
+ const runs = params.runs !== undefined && Number.isFinite(params.runs) ? Math.max(1, Math.floor(params.runs)) : EARLIER_RUNS;
1999
+ return { content: [{ type: "text", text: listJobs(jobs, cwd, runs) }], details: { status: "all" } };
2015
2000
  }
2016
2001
  const existing = jobs.get(params.job_id);
2017
2002
  const planned = shownJobs(jobs).find((job) => job.id === params.job_id && jobs.get(job.id) === undefined);
2018
2003
  if (planned !== undefined) {
2019
- return {
2020
- content: [{ type: "text", text: `${planned.id} · ${pulseName(planned)}: ${planned.note ?? "planned, not started"}${planned.waitingOn.length > 0 ? ` It runs after ${planned.waitingOn.join(", ")}.` : ""}` }],
2021
- details: { status: "planned" },
2022
- };
2004
+ const pulse = await workLoops.get(jobs)?.loop.plannedPulse(planned.id);
2005
+ return { content: [{ type: "text", text: describePlannedRow(planned, pulse) }], details: { status: "planned" } };
2023
2006
  }
2024
2007
  if (existing === undefined) {
2025
2008
  const past = describePastPulse(ledgerProjects(cwd), params.job_id);
@@ -2037,10 +2020,14 @@ function registerJobTools(pi, jobs, cwd) {
2037
2020
  };
2038
2021
  }
2039
2022
  const job = params.wait === true ? await jobs.wait(params.job_id) : existing;
2040
- return {
2041
- content: [{ type: "text", text: describeJob(job) }],
2042
- details: { status: job.status },
2043
- };
2023
+ if (job.status === "running" || job.status === "queued")
2024
+ return { content: [{ type: "text", text: describeJob(job) }], details: { status: job.status } };
2025
+ // Ended: how it went - why, for one that did not land - and what the ledger recorded of it besides: its rounds, test
2026
+ // runs, verdicts, healers and commits, as facts. A pulse that landed after a struggle shows it there.
2027
+ const told = didNotLand(job) ? whyFailed(job) : describeJob(job);
2028
+ const facts = describePastPulse(ledgerProjects(cwd), job.id, { report: false });
2029
+ const text = facts !== undefined ? `${told}\n\nWhat the ledger recorded of it:\n${facts}` : told;
2030
+ return { content: [{ type: "text", text }], details: { status: job.status } };
2044
2031
  },
2045
2032
  });
2046
2033
  // The panel is compact and ctrl+o only lasts as long as the work does. This is the whole
@@ -2547,28 +2534,49 @@ function deployedLabel(name, what) {
2547
2534
  function shownJobs(jobs) {
2548
2535
  return [...(workLoops.get(jobs)?.loop.planned() ?? []), ...jobs.list()];
2549
2536
  }
2550
- function listJobs(jobs, cwd) {
2537
+ function listJobs(jobs, cwd, runs = EARLIER_RUNS) {
2551
2538
  const all = [...shownJobs(jobs)].reverse().filter((job) => job.replacedBy === undefined);
2552
2539
  const deployed = runningDeployed().map((item) => `deploy ${item.name} running ${item.moduleName}: ${item.url ?? item.command} (pid ${item.pid}, output in ${relative(process.cwd(), item.log) || item.log})`);
2553
2540
  const listed = deployed.length > 0 ? `\n\nActivated from dist - /halt activated <name> halts one:\n${deployed.join("\n")}` : "";
2554
- const before = earlierRuns(jobs, cwd);
2541
+ const before = earlierRuns(jobs, cwd, runs);
2555
2542
  if (all.length === 0)
2556
2543
  return `No pulses have been started in this session.${listed}${before}`;
2557
2544
  return `${jobLines(all)}${listed}${before}`;
2558
2545
  }
2546
+ /** How many runs of earlier sessions `pulses` lists when it is asked for none. */
2547
+ const EARLIER_RUNS = 3;
2559
2548
  /** Earlier sessions' last runs and their pulses, from the ledger - nothing when it has none. */
2560
- function earlierRuns(jobs, cwd) {
2549
+ function earlierRuns(jobs, cwd, runs) {
2561
2550
  try {
2562
- const found = earlierPulses(ledgerProjects(cwd), new Set(jobs.list().map((job) => job.id)));
2551
+ const found = earlierPulses(ledgerProjects(cwd), new Set(jobs.list().map((job) => job.id)), runs);
2563
2552
  if (found.runs.length === 0)
2564
2553
  return "";
2565
- const more = found.more > 0 ? `\n\n${found.more} earlier run${found.more === 1 ? "" : "s"} beyond these are in the ledger.` : "";
2566
- return `\n\nEarlier sessions, from the ledger - pulses or diagnose with a pulse's id tells one:\n${describeRuns(found.runs)}${more}`;
2554
+ const more = found.more > 0 ? `\n\n${found.more} earlier run${found.more === 1 ? "" : "s"} beyond these: ask with runs for more.` : "";
2555
+ return `\n\nEarlier sessions, from the ledger - pulses with a pulse's id tells one:\n${describeRuns(found.runs)}${more}`;
2567
2556
  }
2568
2557
  catch {
2569
2558
  return "";
2570
2559
  }
2571
2560
  }
2561
+ /** A look ahead, for the chat: what is planned in each codebase, each row by its id, and what happens next. */
2562
+ function describeLookAhead(loop, statuses) {
2563
+ const modules = new Set(statuses.map((status) => status.module));
2564
+ const rows = loop.planned().filter((row) => row.module !== undefined && modules.has(row.module));
2565
+ const listed = rows.length > 0 ? `\n\nThe planned pulses - pulses with a row's id tells its cases and, for the next pulse of a codebase, the whole prompt its coding agent will get:\n${rows.map((row) => `${row.id} ${row.summary}`).join("\n")}` : "";
2566
+ return (`${describeModules(statuses)}${listed}\n\n` +
2567
+ "Nothing was started. What is planned here waits for regenerate, conform or /regenerate, which runs this plan as it is - unless " +
2568
+ "the ***plain or the steering changes first, when it is planned again. To change the plan, use steer or change the ***plain, then " +
2569
+ "look again. Tell the user what will run and in what order - the parts they are likely to care about.");
2570
+ }
2571
+ /** A planned row, for the chat: what it is, and its prompt when it is the next pulse of its codebase. */
2572
+ function describePlannedRow(row, pulse) {
2573
+ const head = `${row.id} · ${pulseName(row)}: ${row.note ?? "planned, not started"}${row.waitingOn.length > 0 ? ` It runs after ${row.waitingOn.join(", ")}.` : ""}`;
2574
+ if (pulse?.task !== undefined) {
2575
+ return (`${head}\n\nThe whole prompt its coding agent will get - built from the plan kept, the one regenerate runs:\n<prompt>\n${pulse.task}\n</prompt>\n\n` +
2576
+ "Tell the user what the pulse is and what it will be told - the parts they are likely to care about, not the whole prompt unless they ask.");
2577
+ }
2578
+ return pulse?.why !== undefined ? `${head}\n\nNo prompt shown: ${pulse.why}` : head;
2579
+ }
2572
2580
  function jobLines(all) {
2573
2581
  return all
2574
2582
  .map((job) => {
@@ -2578,7 +2586,8 @@ function jobLines(all) {
2578
2586
  const after = job.status === "queued" && job.waitingOn.length > 0 ? ` (after ${job.waitingOn.join(", ")})` : "";
2579
2587
  const spent = describeUsage(job.usage);
2580
2588
  const model = job.model ? ` · ${job.model}` : "";
2581
- return `${job.id} ${(planned ? "planned" : job.status).padEnd(9)} ${time.padStart(7)} ${pulseName(job)}${model}${after}${spent ? ` · ${spent}` : ""}`;
2589
+ const held = job.lookedAhead === true ? " · looked ahead: waits for regenerate" : "";
2590
+ return `${job.id} ${(planned ? "planned" : job.status).padEnd(9)} ${time.padStart(7)} ${pulseName(job)}${model}${after}${held}${spent ? ` · ${spent}` : ""}`;
2582
2591
  })
2583
2592
  .join("\n");
2584
2593
  }