@turri-dev/cli 0.1.3-next.26f08c5 → 0.1.3-next.420ce7e

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 (42) hide show
  1. package/README.md +1 -1
  2. package/dist/config.js +3 -2
  3. package/dist/extension.js +167 -51
  4. package/dist/identity.js +1 -1
  5. package/dist/loop-cli.js +1 -1
  6. package/dist/loop-tools.js +1 -1
  7. package/dist/pi-launch.js +5 -0
  8. package/dist/picture-row.js +21 -0
  9. package/dist/question-dialog.js +8 -3
  10. package/dist/questioning.js +1 -1
  11. package/dist/regenerate/activity.js +2 -0
  12. package/dist/regenerate/confine.js +1 -0
  13. package/dist/regenerate/conform.js +5 -5
  14. package/dist/regenerate/conformance-agents.js +220 -11
  15. package/dist/regenerate/conformance.js +91 -35
  16. package/dist/regenerate/debugger.js +27 -3
  17. package/dist/regenerate/environment-error.js +63 -9
  18. package/dist/regenerate/loop.js +22 -4
  19. package/dist/regenerate/notes.js +66 -17
  20. package/dist/regenerate/panel-dock.js +86 -0
  21. package/dist/regenerate/prompt.js +3 -1
  22. package/dist/regenerate/regenerate.js +35 -14
  23. package/dist/regenerate/regression.js +2 -1
  24. package/dist/regenerate/requires.js +55 -2
  25. package/dist/regenerate/side-panel.js +14 -4
  26. package/dist/regenerate/stop-report.js +13 -0
  27. package/dist/regenerate/test-scripts.js +45 -9
  28. package/dist/regenerate/unit-review.js +11 -0
  29. package/dist/regenerate-cli.js +1 -1
  30. package/dist/resume-line.js +4 -0
  31. package/dist/spec-tools.js +8 -44
  32. package/docs/authoring-plain.md +9 -6
  33. package/docs/config.md +3 -2
  34. package/docs/development.md +1 -0
  35. package/docs/headless.md +2 -2
  36. package/docs/regenerating.md +81 -22
  37. package/docs/skills-and-gates.md +2 -2
  38. package/docs/using.md +12 -3
  39. package/genome/skills/bud/SKILL.md +67 -36
  40. package/genome/skills/bud/references/intent.md +4 -0
  41. package/package.json +3 -3
  42. package/genome/skills/bud/references/checklist.md +0 -44
@@ -1,5 +1,5 @@
1
1
  import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
- import { basename, dirname, join } from "node:path";
2
+ import { basename, dirname, join, resolve } from "node:path";
3
3
  import { defineTool } from "@earendil-works/pi-coding-agent";
4
4
  import { Type } from "typebox";
5
5
  import { reportActivity } from "./activity.js";
@@ -40,7 +40,6 @@ export const SECTIONS = {
40
40
  where: "Where things are",
41
41
  run: "How to build, run and test",
42
42
  assumptions: "Assumptions",
43
- gaps: "Spec gaps",
44
43
  pitfalls: "Pitfalls",
45
44
  pulses: "Pulses",
46
45
  };
@@ -53,8 +52,13 @@ export function notesPath(buildDir) {
53
52
  return join(buildDir, NOTES_FILE);
54
53
  }
55
54
  function empty() {
56
- return { where: [], run: [], assumptions: [], gaps: [], pitfalls: [], pulses: [] };
55
+ return { where: [], run: [], assumptions: [], pitfalls: [], pulses: [] };
57
56
  }
57
+ /**
58
+ * Sections the notes no longer have, their lines dropped as they are read: the spec gaps are the person's, reported
59
+ * with report_spec_gap - the choice made meanwhile is an assumption, which stays.
60
+ */
61
+ const DROPPED = new Set(["spec gaps"]);
58
62
  /** The notes, as lines per section. Lines under no known heading go to pitfalls, not lost. */
59
63
  export function parseNotes(text) {
60
64
  const notes = empty();
@@ -63,11 +67,12 @@ export function parseNotes(text) {
63
67
  const line = raw.trim();
64
68
  const heading = /^##\s+(.+)$/.exec(line);
65
69
  if (heading) {
66
- section = ORDER.find((key) => SECTIONS[key].toLowerCase() === heading[1].trim().toLowerCase()) ?? section;
70
+ const named = heading[1].trim().toLowerCase();
71
+ section = DROPPED.has(named) ? undefined : (ORDER.find((key) => SECTIONS[key].toLowerCase() === named) ?? section ?? "pitfalls");
67
72
  continue;
68
73
  }
69
74
  const item = /^[-*]\s+(.+)$/.exec(line);
70
- if (item)
75
+ if (item && section !== undefined)
71
76
  notes[section].push(item[1].trim());
72
77
  }
73
78
  return notes;
@@ -93,14 +98,14 @@ const GUIDANCE = [
93
98
  `- ${SECTIONS.where}: entry points, layout, where each functionality and its tests live.`,
94
99
  `- ${SECTIONS.run}: the commands that build, run and test it, and what had to be installed for them.`,
95
100
  `- ${SECTIONS.assumptions}: what you assumed where the specification is silent - a format, a default, a`,
96
- " choice it leaves open. Build on the assumptions already there; change or remove one the moment the code",
97
- " or the specification shows it wrong.",
98
- `- ${SECTIONS.gaps}: what the specification should say and does not - a behaviour you had to decide that the`,
99
- " person would want to decide, not a detail of how. Each is put to the person, to be written into the",
100
- " specification. One a line, as the question it leaves: \"What happens to a contact archived in HubSpot after it",
101
- " was synced?\"",
101
+ " choice it leaves open - and the tests that assert it, when any do: \"A Dash drains Pulses at 1/s - asserted in",
102
+ " predators.test.ts, The Dash\". One no test asserts is written down all the same. Build on the assumptions",
103
+ " already there; change or remove one the moment the code or the specification shows it wrong - and the tests",
104
+ " it names with it.",
102
105
  `- ${SECTIONS.pitfalls}: what went wrong and what fixed it, approaches that did not work.`,
103
106
  `- ${SECTIONS.pulses}: written by turri as each pulse ends - read them, never write them.`,
107
+ "A behaviour you had to decide that the person would want to decide - not a detail of how - is not a note: report",
108
+ "it with report_spec_gap, with the assumption you made meanwhile.",
104
109
  "Each line stands on its own, for someone who never saw your work. When and where it came from is added",
105
110
  "to it for you - do not write it. Where two lines disagree, the later one is right: change the older one",
106
111
  'rather than add a contradicting line. Leave a section with nothing new alone: "none" is not a note.',
@@ -232,7 +237,7 @@ export function createNotesTool(buildDir, onWrite, before = () => { }, source) {
232
237
  label: "Update notes",
233
238
  description: "Update the working notes on this codebase for the next agent - add a line, change one that is no longer " +
234
239
  "true, remove one that is wrong - in its sections: where things are, how to build, run and test, " +
235
- "assumptions made where the specification is silent, spec gaps the person should decide, and pitfalls. Never " +
240
+ "assumptions made where the specification is silent, and pitfalls. Never " +
236
241
  "requirements: the specification is never an assumption.",
237
242
  promptSnippet: "leave the next agent what you learned and assumed about this codebase",
238
243
  parameters: Type.Object({
@@ -283,7 +288,7 @@ export function sectionNamed(name) {
283
288
  /** How many times an agent that finishes without update_notes is asked to call it. */
284
289
  export const NOTES_ASKS = 3;
285
290
  /** The turn that asks for the notes: update_notes is the only tool it may use - the work it follows is done. */
286
- export const NOTES_TURN = { onlyTools: ["update_notes"] };
291
+ export const NOTES_TURN = { onlyTools: ["update_notes", "report_spec_gap"] };
287
292
  /** What the notes turn says first, once the harness's own run of `script` has passed on the work. */
288
293
  export function passedOutcome(script) {
289
294
  return (`The harness ran the project's ${script} on your work itself, and it passed: your work is done and accepted. ` +
@@ -327,10 +332,53 @@ export function recordPulse(buildDir, text, source) {
327
332
  // The notes are a help, not the work.
328
333
  }
329
334
  }
330
- /** The lines of a section added since `before` - a pulse's new spec gaps, say - without when and where they came from. */
331
- export function linesAddedSince(before, buildDir, section) {
332
- const known = new Set(before[section]);
333
- return readNotes(buildDir)[section].filter((line) => !known.has(line)).map((line) => line.replace(/^\[[^\]]*\]\s*/, ""));
335
+ /** Every spec gap reported in this process, with the codebase it was met in: a pulse reads those since it started. */
336
+ const reportedGaps = [];
337
+ /** Where the spec gaps stand now: what `gapsSince` reads from. */
338
+ export function gapMark() {
339
+ return reportedGaps.length;
340
+ }
341
+ /** The spec gaps reported in these codebases since `mark`. */
342
+ export function gapsSince(mark, dirs) {
343
+ const wanted = new Set(dirs.map((dir) => resolve(dir)));
344
+ return reportedGaps.slice(mark).filter((entry) => wanted.has(entry.dir)).map((entry) => entry.gap);
345
+ }
346
+ /**
347
+ * `report_spec_gap`: a behaviour the specification leaves open that the person would want to decide, put to them as
348
+ * the pulse ends - never into the notes, which are the next agent's. What the agent decided meanwhile goes into the
349
+ * notes' assumptions, so the code built on it is known for what it is until the specification settles it.
350
+ */
351
+ export function createSpecGapTool(buildDir, source) {
352
+ return defineTool({
353
+ name: "report_spec_gap",
354
+ label: "Report a spec gap",
355
+ description: "Report a spec gap: a behaviour the specification leaves open that the person would want to decide - not a detail " +
356
+ "of how. Decide it meanwhile and carry on: the person is asked once the work ends, and what they decide is " +
357
+ "written into the specification. The assumption you made is added to the notes' assumptions for you.",
358
+ promptSnippet: "tell the person about a behaviour the specification leaves open, and what you decided meanwhile",
359
+ parameters: Type.Object({
360
+ question: Type.String({ description: 'The question it leaves the person, one line: "What happens to a contact archived in HubSpot after it was synced?"' }),
361
+ assumption: Type.String({
362
+ description: "What you decided meanwhile, as its line in the notes' assumptions - with the tests that assert it, when any do: " +
363
+ '"An archived contact is left as synced - asserted in sync.test.ts, archived contacts".',
364
+ }),
365
+ }),
366
+ async execute(_id, params) {
367
+ const question = params.question.replace(/\s+/g, " ").trim();
368
+ const assumption = params.assumption.replace(/\s+/g, " ").trim();
369
+ if (question === "" || assumption === "")
370
+ throw new Error("Nothing reported - a spec gap needs both the question it leaves and the assumption you made meanwhile.");
371
+ // However many there are, spec gaps are put to the person - never a reason to stop the pulse.
372
+ reportedGaps.push({ dir: resolve(buildDir), gap: { question, assumption } });
373
+ const known = readNotes(buildDir).assumptions.some((line) => body(line) === assumption);
374
+ if (!known)
375
+ recordNote(buildDir, "assumptions", assumption, source ?? "spec gap");
376
+ return {
377
+ content: [{ type: "text", text: `Reported. The assumption is in the notes' assumptions${known ? " already" : " now"} - do not add it again.` }],
378
+ details: { question, assumption },
379
+ };
380
+ },
381
+ });
334
382
  }
335
383
  /** The notes, for an agent that reads them but leaves none - a judge. Empty when there are none. */
336
384
  export function notesToRead(buildDir) {
@@ -367,6 +415,7 @@ export function notesForSession(buildDir, source) {
367
415
  return true;
368
416
  };
369
417
  return {
418
+ gapTool: createSpecGapTool(buildDir, source),
370
419
  tool: createNotesTool(buildDir, (text) => {
371
420
  written = true;
372
421
  knownNotes.set(file, text);
@@ -0,0 +1,86 @@
1
+ import { HStack } from "@earendil-works/pi-tui";
2
+ /**
3
+ * The side panel beside the chat rather than over it: the chat drawn on the left in what the panel leaves it, the panel
4
+ * laid over the columns on the right.
5
+ *
6
+ * pi draws its screen one of two ways, and the chat is narrowed in each as it is drawn: full screen (pi's default), a
7
+ * layout - its root put in a row beside a filler as wide as the panel; the regular screen, the lines its render gives -
8
+ * asked for in fewer columns.
9
+ */
10
+ /** Narrower than this, the chat and the panel have no room side by side: the panel takes the whole screen. */
11
+ const SHARED_FROM = 100;
12
+ /** The columns the panel takes beside the chat: half the screen, the rule between them in the middle - 0 when the terminal is too narrow to share. */
13
+ export function dockedWidth(columns) {
14
+ return columns < SHARED_FROM ? 0 : Math.floor(columns / 2);
15
+ }
16
+ /**
17
+ * The chat narrowed by `panelWidth()` columns, read at each frame - 0 gives it the whole width. Returns what gives it the
18
+ * whole width back for good.
19
+ */
20
+ export function narrowChat(tui, panelWidth) {
21
+ const screen = tui;
22
+ if (typeof screen.setLayoutRoot === "function" && screen.layoutRoot !== undefined) {
23
+ const root = screen.layoutRoot;
24
+ // A line as wide as the panel: the row gives the filler what it measures, the chat the rest.
25
+ const filler = { render: () => [" ".repeat(panelWidth())], invalidate() { } };
26
+ screen.setLayoutRoot(new HStack([{ component: root, basis: 0, grow: 1 }, { component: filler }]));
27
+ return () => screen.setLayoutRoot(root);
28
+ }
29
+ // Read from the prototype: the screen's own render, not one laid over it.
30
+ const render = Object.getPrototypeOf(tui).render;
31
+ screen.render = function (width) {
32
+ return render.call(this, Math.max(1, width - panelWidth()));
33
+ };
34
+ return () => {
35
+ screen.render = render;
36
+ };
37
+ }
38
+ /**
39
+ * A press of a mouse button, as pi's full screen takes it - `side` told whether it was in the chat, left of `chatWidth()`
40
+ * columns, or in the panel - before the press goes on as it would have. Motion and the wheel are not presses. pi's
41
+ * regular screen reads no mouse: nothing is done there. Returns what takes the watch off.
42
+ */
43
+ export function clickToFocus(tui, chatWidth, side) {
44
+ const screen = tui;
45
+ const handle = screen.handleMouseEvent;
46
+ if (typeof handle !== "function")
47
+ return () => { };
48
+ screen.handleMouseEvent = function (raw) {
49
+ // 32: motion; 64: the wheel.
50
+ if (raw.release !== true && (raw.button & (32 | 64)) === 0)
51
+ side(raw.x < chatWidth() ? "chat" : "panel");
52
+ return handle.call(this, raw);
53
+ };
54
+ return () => {
55
+ screen.handleMouseEvent = handle;
56
+ };
57
+ }
58
+ /**
59
+ * A line drawn faint - the side that does not have the keys, in the shade. Faint (SGR 2) holds through a line's colours;
60
+ * only a reset - SGR 0, or 22 - ends it, so it is set again after each one. A line holding an image is left as it is.
61
+ */
62
+ export function shade(line) {
63
+ // Kitty's image escape, or iTerm2's.
64
+ if (line.includes("\x1b_G") || line.includes("\x1b]1337;File="))
65
+ return line;
66
+ const again = line.replace(/\x1b\[([\d;]*)m/g, (sgr, params) => (params.split(";").some((param) => param === "" || param === "0" || param === "22") ? `${sgr}${FAINT}` : sgr));
67
+ return `${FAINT}${again}${NOT_FAINT}`;
68
+ }
69
+ const FAINT = "\x1b[2m";
70
+ const NOT_FAINT = "\x1b[22m";
71
+ /**
72
+ * The chat in the shade while `shaded()`: each of its rows drawn faint as the screen lays the overlays over it - the
73
+ * docked panel the last of them, which covers its own columns. Returns what takes the shade off.
74
+ */
75
+ export function shadeChat(tui, shaded) {
76
+ const screen = tui;
77
+ const composite = screen.compositeLineAt;
78
+ if (typeof composite !== "function")
79
+ return () => { };
80
+ screen.compositeLineAt = function (base, overlay, col, width, total) {
81
+ return composite.call(this, shaded() ? shade(base) : base, overlay, col, width, total);
82
+ };
83
+ return () => {
84
+ screen.compositeLineAt = composite;
85
+ };
86
+ }
@@ -278,8 +278,10 @@ function itemText(serialized) {
278
278
  return item;
279
279
  const { markdown, [ACCEPTANCE_TESTS]: tests } = (item ?? {});
280
280
  const lines = [markdown ?? JSON.stringify(item)];
281
+ // Each test is an item of the tree, its text in its markdown - as spec-steps.ts `itemText` reads it.
282
+ const testText = (test) => (typeof test === "string" ? test : (test?.markdown ?? JSON.stringify(test)));
281
283
  if (Array.isArray(tests) && tests.length > 0)
282
- lines.push(" <acceptance tests>", ...tests.map((test) => ` ${String(test)}`), " </acceptance tests>");
284
+ lines.push(" <acceptance tests>", ...tests.map((test) => ` ${testText(test).replace(/\n/g, "\n ")}`), " </acceptance tests>");
283
285
  return lines.join("\n");
284
286
  }
285
287
  const indent = (text, by) => text.split("\n").map((line) => `${by}${line}`).join("\n");
@@ -14,13 +14,13 @@ import { buildSpecDiffPrompt, describeSpecChange, reviewedSpec, sectionModules }
14
14
  import { abandonWork, recordHistory, startWork } from "./lineage.js";
15
15
  import { createWorkLedger, SUBMIT_WORK_NOTE } from "./submit-work.js";
16
16
  import { CODER_COMPACTION } from "./compaction.js";
17
- import { linesAddedSince, NOTES_TURN, notesForSession, passedOutcome, readNotes, recordNote, withNotes } from "./notes.js";
17
+ import { gapMark, gapsSince, NOTES_TURN, notesForSession, passedOutcome, recordNote, withNotes } from "./notes.js";
18
18
  import { createLoopWatch, createScriptTool, failureSignature, findTestScripts, projectRootFor, requireTestScripts, runUnitScript, STUCK_ROUNDS, withoutConformance, withTestingScripts, } from "./test-scripts.js";
19
19
  import { createWebTools, WEB_TOOLS } from "./web.js";
20
20
  import { createCanItFailTool, createMyDiffTool, selfCheckNote } from "./self-check.js";
21
21
  import { createServiceTools } from "./services.js";
22
22
  import { createUnitGate } from "./unit-gate.js";
23
- import { toolchainError } from "./environment-error.js";
23
+ import { timeLimitError, toolchainError } from "./environment-error.js";
24
24
  import { workspaceBlock } from "./workspace.js";
25
25
  import { ATTEMPTS, describeStop } from "./stop-report.js";
26
26
  import { summarizeDiff } from "./job-panel.js";
@@ -268,8 +268,8 @@ export async function renderSpecDiff(options) {
268
268
  ...(options.cases !== undefined ? { cases: options.cases } : {}),
269
269
  });
270
270
  const digestsBefore = digestFiles(buildDir);
271
- // The notes as the agent finds them: what it adds - a spec gap above all - is told with the result.
272
- const notesBefore = readNotes(buildDir);
271
+ // The spec gaps its agents report from here on are told with the result.
272
+ const gapsFrom = gapMark();
273
273
  /** What the debugger found, each time it was asked: the pulse's line in the notes says it. */
274
274
  const diagnosed = [];
275
275
  const runs = [];
@@ -305,6 +305,7 @@ export async function renderSpecDiff(options) {
305
305
  cwd: buildDir,
306
306
  customTools: [
307
307
  notes.tool,
308
+ notes.gapTool,
308
309
  work.tool,
309
310
  ...createWebTools(),
310
311
  createScriptTool({ kind: "unit", script: scripts.unit, run: () => runUnitScript(buildDir, scripts.unit), runs, watch: loop }),
@@ -313,7 +314,7 @@ export async function renderSpecDiff(options) {
313
314
  ...fence.tools,
314
315
  createCopyResourceTool({ resources: linkedResources, dir: buildDir }),
315
316
  ],
316
- tools: [...fence.names, "run_unit_tests", ...selfChecks.map((tool) => tool.name), ...services.names, "update_notes", "submit_work", "copy_resource", ...WEB_TOOLS],
317
+ tools: [...fence.names, "run_unit_tests", ...selfChecks.map((tool) => tool.name), ...services.names, "update_notes", "report_spec_gap", "submit_work", "copy_resource", ...WEB_TOOLS],
317
318
  model: options.model,
318
319
  label: `${moduleName} spec change coding agent`,
319
320
  role: "coding",
@@ -333,6 +334,8 @@ export async function renderSpecDiff(options) {
333
334
  let draftAsks = 0;
334
335
  /** What the unit testing script needs and does not find, last run. */
335
336
  let missing;
337
+ /** The unit testing script needs more time than a test run may take - the debugger's finding: the pulse stops on it. */
338
+ let slow;
336
339
  /** The last round failed on the script's static checks alone: the unit tests passed. */
337
340
  let staticOnly = false;
338
341
  const testRemovals = [];
@@ -423,24 +426,35 @@ export async function renderSpecDiff(options) {
423
426
  seenFailures.set(key, seen);
424
427
  let prompt = verdict.prompt;
425
428
  const circling = loop.stuck;
426
- if (circling || (key !== undefined && seen >= STUCK_ROUNDS)) {
429
+ // A run the time limit stopped is looked at at once: whether something hangs, or the suite only needs more time.
430
+ const timedOut = verdict.run.timedOut === true;
431
+ if (circling || timedOut || (key !== undefined && seen >= STUCK_ROUNDS)) {
427
432
  if (key !== undefined)
428
433
  seenFailures.delete(key);
429
434
  const times = circling ? Math.max(seen, loop.failing) : seen;
430
435
  loop.reset();
431
436
  stage(circling
432
437
  ? `the coding agent is going round in circles - ${times} failing runs - a debugger looks at it with fresh eyes`
433
- : `the same failure ${seen} times - a debugger looks at it with fresh eyes`);
438
+ : timedOut && seen < STUCK_ROUNDS
439
+ ? `the unit testing script did not finish in ${Math.round(verdict.run.timeoutMs / 1000)}s - a debugger works out whether something hangs`
440
+ : `the same failure ${seen} times - a debugger looks at it with fresh eyes`);
434
441
  const found = await debugFailure({
435
442
  buildDir,
436
443
  failure: verdict.run.output,
437
444
  times,
438
445
  task: steeredChange() ?? codingText ?? changeText ?? options.diff ?? "",
439
446
  script: verdict.script,
447
+ run: verdict.run,
440
448
  label: `${moduleName} spec change`,
441
449
  ...(debuggerModel !== undefined ? { model: debuggerModel } : {}),
442
450
  onDelta: options.onDelta,
443
451
  }).catch(() => undefined);
452
+ // Nothing hangs: the suite needs more time than a test run may take, and no agent can give it that.
453
+ if (found?.tooSlow === true) {
454
+ stage(`the unit testing script needs more than the ${Math.round(verdict.run.timeoutMs / 1000)}s a test run may take - stopping`);
455
+ slow = timeLimitError(verdict.run, { moduleName, script: verdict.script, kind: "unit", reason: found.rootCause });
456
+ return false;
457
+ }
444
458
  if (found !== undefined) {
445
459
  const cause = found.rootCause.split("\n")[0].slice(0, 240);
446
460
  reportActivity(` the debugger: ${cause.slice(0, 160)}`);
@@ -486,6 +500,7 @@ export async function renderSpecDiff(options) {
486
500
  ...(options.cases !== undefined ? { cases: options.cases } : {}),
487
501
  label: `${moduleName} spec change`,
488
502
  ...(scripts.runOn === "copy" ? { unitScript: scripts.unit } : {}),
503
+ testingScript: { path: relative(root, scripts.unit), content: readFileSync(scripts.unit, "utf8") },
489
504
  model: options.judgeModel ?? modelSpec(inheritModel(configForSpec(tip.plainFile).judgeModel, modelOnly(options.model))),
490
505
  send: async (next) => {
491
506
  response = await ask(executor, next, options.onDelta);
@@ -528,8 +543,8 @@ export async function renderSpecDiff(options) {
528
543
  testRemovals,
529
544
  files,
530
545
  ...(steering !== undefined && steering.steers > 0 ? { steered: [...steering.notes] } : {}),
531
- // Read before a rollback takes the notes back: a gap the agent met is the person's to decide, whether it landed or not.
532
- specGaps: linesAddedSince(notesBefore, buildDir, "gaps"),
546
+ // A gap the agent met is the person's to decide, whether it landed or not.
547
+ specGaps: gapsSince(gapsFrom, [buildDir]),
533
548
  diagnosed,
534
549
  };
535
550
  /** The change landed: what the code is built from is now the spec with the change in, committed with it. */
@@ -543,13 +558,17 @@ export async function renderSpecDiff(options) {
543
558
  stage(unitReviewStopped ? "the unit tests pass but still leave the change untested - undoing the change" : "unit tests NOT passing - undoing the change");
544
559
  abandonWork(unit, moduleName, missing !== undefined
545
560
  ? "the unit testing script could not run"
546
- : staticOnly
547
- ? "the spec change did not pass its static checks"
548
- : "the spec change did not pass its unit tests");
561
+ : slow !== undefined
562
+ ? "the unit testing script needs more time than a test run may take"
563
+ : staticOnly
564
+ ? "the spec change did not pass its static checks"
565
+ : "the spec change did not pass its unit tests");
549
566
  // The environment lacks what the testing script needs: the pulse stops, rolled back, and the person is told.
550
567
  if (missing !== undefined) {
551
568
  throw toolchainError(missing, { moduleName, script: scripts.unit, kind: "unit" });
552
569
  }
570
+ if (slow !== undefined)
571
+ throw slow;
553
572
  return { ...base, passed: false, stoppedAt: "unit tests", ...(staticOnly && !unitReviewStopped ? { staticChecks: true } : {}) };
554
573
  }
555
574
  stage("unit tests pass - landing the change on them");
@@ -562,8 +581,10 @@ export function specGapsText(gaps) {
562
581
  return [];
563
582
  return [
564
583
  "",
565
- "Spec gaps its agents met - the spec does not say, so they decided. Put each to the user, and write the ones they decide into the spec:",
566
- ...gaps.map((gap) => `- ${gap}`),
584
+ "Spec gaps its agents met - the spec does not say, so they decided, each as an assumption in the codebase's notes. Put " +
585
+ "each to the user, and write the ones they decide into the spec - the pulse that builds it is told the assumption " +
586
+ "it replaces:",
587
+ ...gaps.map((gap) => `- ${gap.question} Meanwhile: ${gap.assumption}`),
567
588
  ];
568
589
  }
569
590
  /** What a rendered spec change did, for the agent and the person. */
@@ -21,7 +21,7 @@ import { keepingTestsUnchanged, listFiles } from "./testing.js";
21
21
  * job ends on it: tests that pass on their own are not done until the whole suite passes with them.
22
22
  */
23
23
  /** On top of the file tools, which are fenced to the build directory by `confine.ts`. */
24
- const FIX_TOOLS = ["run_unit_tests", "run_conformance_tests", "update_notes"];
24
+ const FIX_TOOLS = ["run_unit_tests", "run_conformance_tests", "update_notes", "report_spec_gap"];
25
25
  const DEFAULT_MAX_REGRESSION_ROUNDS = ATTEMPTS.regression;
26
26
  /** The module's conformance tests, when there are any: the chain's, copied up, and its own. */
27
27
  function conformanceDirs(conformanceRoot, moduleName) {
@@ -39,6 +39,7 @@ async function repairRegression(input) {
39
39
  cwd: input.buildDir,
40
40
  customTools: [
41
41
  notes.tool,
42
+ notes.gapTool,
42
43
  ...createWebTools(),
43
44
  ...fence.tools,
44
45
  createScriptTool({ kind: "unit", script: input.scripts.unit, run: () => runUnitScript(input.buildDir, input.scripts.unit), runs }),
@@ -1,6 +1,6 @@
1
- import { copyFileSync, existsSync, mkdirSync, readdirSync, rmSync } from "node:fs";
1
+ import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync } from "node:fs";
2
2
  import { basename, dirname, join, resolve } from "node:path";
3
- import { PLAIN_SOURCE_FILE_EXTENSION, plainFileParser, withParseCache } from "../plain/parser.js";
3
+ import { IMPORT_DIRECTIVE, PLAIN_SOURCE_FILE_EXTENSION, plainFileParser, readPlainSourceMetadata, withParseCache } from "../plain/parser.js";
4
4
  import { getFrids, getInheritedFunctionalSpecs } from "../plain/spec.js";
5
5
  import { buildDirUnder, modulesRoot, projectDirOf } from "./paths.js";
6
6
  import { notesPath } from "./notes.js";
@@ -54,6 +54,59 @@ options = {}) {
54
54
  visit(resolve(plainFile), []);
55
55
  return chain;
56
56
  }
57
+ /** The .plain files that import `plainFile` - read from beside it, and, kept in a `template/` folder, from the folder it is in. */
58
+ function importersOf(plainFile) {
59
+ const file = resolve(plainFile);
60
+ const dir = dirname(file);
61
+ const name = basename(file, PLAIN_SOURCE_FILE_EXTENSION);
62
+ const dirs = [dir, ...(basename(dir) === "template" ? [dirname(dir)] : [])];
63
+ return dirs.flatMap((at) => {
64
+ let names;
65
+ try {
66
+ names = readdirSync(at).filter((entry) => entry.endsWith(PLAIN_SOURCE_FILE_EXTENSION));
67
+ }
68
+ catch {
69
+ return [];
70
+ }
71
+ return names
72
+ .map((entry) => join(at, entry))
73
+ .filter((path) => {
74
+ if (path === file || !resolveTemplateDirs(path).includes(dir))
75
+ return false;
76
+ try {
77
+ return (readPlainSourceMetadata(readFileSync(path, "utf8")).metadata[IMPORT_DIRECTIVE] ?? []).includes(name);
78
+ }
79
+ catch {
80
+ return false;
81
+ }
82
+ });
83
+ });
84
+ }
85
+ /**
86
+ * Whether a .plain file is an import module - one a .plain file imports, or one kept in a `template/` folder - rather than
87
+ * a module of its own. It is no codebase: its reqs and definitions are built in the modules that import it.
88
+ */
89
+ export function isImportModule(plainFile) {
90
+ return basename(dirname(resolve(plainFile))) === "template" || importersOf(plainFile).length > 0;
91
+ }
92
+ /** The modules of their own that import an import module, through any import modules between. */
93
+ export function importingModules(plainFile) {
94
+ const found = new Set();
95
+ const seen = new Set();
96
+ const walk = (file) => {
97
+ if (seen.has(file))
98
+ return;
99
+ seen.add(file);
100
+ for (const importer of importersOf(file)) {
101
+ if (isImportModule(importer))
102
+ walk(importer);
103
+ else
104
+ found.add(importer);
105
+ }
106
+ };
107
+ walk(resolve(plainFile));
108
+ return [...found];
109
+ }
57
110
  /**
58
111
  * The codebase a change to `plainFile`'s module lands in: the furthest-built module whose
59
112
  * requires chain includes it, with that chain.
@@ -12,6 +12,12 @@ export function createSidePanel(options) {
12
12
  let drawnTree = { rows: [], rowStarts: [], lineCount: 0 };
13
13
  let drawnMap = { rows: [], rowStarts: [], lineCount: 0 };
14
14
  let pages = [];
15
+ /** The keys back to the chat - and `s`, from over the screen to beside the chat and back. */
16
+ const backKeys = () => {
17
+ if (options.dock === undefined)
18
+ return [`esc or ${options.key} back to the chat`];
19
+ return options.dock.docked() ? ["s full screen", "esc or ⌥⌘← to the chat", `${options.key} close`] : ["s beside the chat", `esc or ${options.key} back to the chat`];
20
+ };
15
21
  const waitingNote = () =>
16
22
  // A question asked while it showed waits in the chat, unanswered: the person is told it is there.
17
23
  options.waiting?.() === true ? ` ${style.warning?.("your question is waiting") ?? style.accent("your question is waiting")} - ${options.key} or esc to answer it, as you left it` : "";
@@ -59,7 +65,7 @@ export function createSidePanel(options) {
59
65
  /** The rule under the top. */
60
66
  const rule = (width) => style.muted("─".repeat(Math.max(1, width)));
61
67
  const renderPulses = (width, rows) => {
62
- const keys = ["↑↓ move", "enter open/close", "←→", "o/c all", "pgup pgdn scroll", ...(options.map !== undefined ? ["p regen"] : []), `esc or ${options.key} back to the chat`];
68
+ const keys = ["↑↓ move", "enter open/close", "←→", "o/c all", "pgup pgdn scroll", ...(options.map !== undefined ? ["p regen"] : []), ...backKeys()];
63
69
  const top = topBlock([`${style.heading("pulses")}${waitingNote()}`], keys, width);
64
70
  // Under the top: the rule, and a line of space - as the map has.
65
71
  const bodyHeight = Math.max(3, rows - top.length - 2);
@@ -77,7 +83,7 @@ export function createSidePanel(options) {
77
83
  pages = options.map();
78
84
  const now = Date.now();
79
85
  if (pages.length === 0) {
80
- const top = topBlock([`${style.heading("regen")}${waitingNote()}`], ["p pulses", `esc or ${options.key} back to the chat`], width);
86
+ const top = topBlock([`${style.heading("regen")}${waitingNote()}`], ["p pulses", ...backKeys()], width);
81
87
  lastBodyHeight = Math.max(3, rows - top.length - 1);
82
88
  drawnMap = { rows: [], rowStarts: [], lineCount: 0 };
83
89
  const body = [style.muted(" No .plain file to map: name one to regenerate, or set module: in config.turri.yaml."), ...new Array(Math.max(0, lastBodyHeight - 1)).fill("")];
@@ -87,7 +93,7 @@ export function createSidePanel(options) {
87
93
  const tabbed = pages.length > 1;
88
94
  const page = shownPage(pages, map);
89
95
  const discuss = page.stuck && options.discuss !== undefined ? [`${DISCUSS_KEY} talk it through in the chat`] : [];
90
- const keys = [...discuss, "↑↓ move", "enter open/close", ...(tabbed ? ["←→ module"] : []), "o/c all", "pgup pgdn", "p pulses", `esc or ${options.key} back to the chat`];
96
+ const keys = [...discuss, "↑↓ move", "enter open/close", ...(tabbed ? ["←→ module"] : []), "o/c all", "pgup pgdn", "p pulses", ...backKeys()];
91
97
  // The legend's box in the upper right corner, over what is under it; too narrow a panel has none.
92
98
  const box = width >= 60 ? legendBox(legendLines(page, style)) : [];
93
99
  const room = box.length > 0 ? width - visibleWidth(box[0]) - 1 : width;
@@ -210,7 +216,7 @@ export function createSidePanel(options) {
210
216
  }
211
217
  catch (error) {
212
218
  // A frame that throws is never drawn - nor is anything after it: the screen would freeze. What failed is shown instead.
213
- const top = topBlock([`${style.heading(map.view === "map" ? "regen" : "pulses")}${waitingNote()}`], [...(options.map !== undefined ? ["p the other view"] : []), `esc or ${options.key} back to the chat`], width);
219
+ const top = topBlock([`${style.heading(map.view === "map" ? "regen" : "pulses")}${waitingNote()}`], [...(options.map !== undefined ? ["p the other view"] : []), ...backKeys()], width);
214
220
  const lines = (error instanceof Error ? (error.stack ?? error.message) : String(error)).split("\n").slice(0, Math.max(1, rows - top.length - 1));
215
221
  return [
216
222
  ...top,
@@ -225,6 +231,10 @@ export function createSidePanel(options) {
225
231
  options.back();
226
232
  return;
227
233
  }
234
+ if (options.dock !== undefined && data === "s") {
235
+ options.dock.toggle();
236
+ return;
237
+ }
228
238
  if (options.map !== undefined && data === "p") {
229
239
  if (map.view === "map")
230
240
  toPulses();
@@ -89,6 +89,19 @@ export function describeStop(facts) {
89
89
  `though they were sent back for it again and again. Still missing:\n${facts.conformance.unlabelled.map((line) => ` - ${line}`).join("\n")}`;
90
90
  todo = ["If the test reqs leave open where the tests go or how they are built, say so exactly - the folder, the files, the build."];
91
91
  }
92
+ else if (facts.at === "conformance" && facts.conformance?.escalation !== undefined) {
93
+ const { error, reason, evidence, changedNothing } = facts.conformance.escalation;
94
+ why =
95
+ `its conformance tests kept failing with ${error}. The conformance agent's fix of the tests did not make it go away, so ` +
96
+ `a judge looked again and found it the code's; the coding agent ${changedNothing === true ? "changed nothing for it" : "fixed the code, and the run still failed the same way"}. ` +
97
+ `Why the judge found it the code's:\n${reason.trim().split("\n").map((line) => ` ${line}`).join("\n")}` +
98
+ (evidence.length > 0 ? `\n On the evidence:\n${evidence.map((item) => ` - ${item.source.trim()}: ${item.shows.trim().replace(/\s+/g, " ")}`).join("\n")}` : "");
99
+ todo = [
100
+ "If the code has to produce something the spec leaves open - a build output, an entry point, a module the conformance testing " +
101
+ "script runs or checks for - say exactly what in the implementation reqs: its path and how it is built.",
102
+ "If the conformance testing script expects something the spec does not ask for, change the script or the test reqs so the two agree.",
103
+ ];
104
+ }
92
105
  else if (facts.at === "conformance" && facts.conformance?.stuck !== undefined) {
93
106
  const { error, times, rounds, changedNothing } = facts.conformance.stuck;
94
107
  why =