@turri-dev/cli 0.1.4-next.fa9223b → 0.1.5-next.6df6879

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 (108) hide show
  1. package/.pi/themes/turri-dark.json +67 -66
  2. package/.pi/themes/turri-light.json +71 -73
  3. package/README.md +41 -127
  4. package/assets/jellyfish/dark-00.png +0 -0
  5. package/assets/jellyfish/dark-01.png +0 -0
  6. package/assets/jellyfish/dark-02.png +0 -0
  7. package/assets/jellyfish/dark-03.png +0 -0
  8. package/assets/jellyfish/dark-04.png +0 -0
  9. package/assets/jellyfish/dark-05.png +0 -0
  10. package/assets/jellyfish/dark-06.png +0 -0
  11. package/assets/jellyfish/dark-07.png +0 -0
  12. package/assets/jellyfish/dark-08.png +0 -0
  13. package/assets/jellyfish/dark-09.png +0 -0
  14. package/assets/jellyfish/dark-10.png +0 -0
  15. package/assets/jellyfish/dark-11.png +0 -0
  16. package/assets/jellyfish/light-00.png +0 -0
  17. package/assets/jellyfish/light-01.png +0 -0
  18. package/assets/jellyfish/light-02.png +0 -0
  19. package/assets/jellyfish/light-03.png +0 -0
  20. package/assets/jellyfish/light-04.png +0 -0
  21. package/assets/jellyfish/light-05.png +0 -0
  22. package/assets/jellyfish/light-06.png +0 -0
  23. package/assets/jellyfish/light-07.png +0 -0
  24. package/assets/jellyfish/light-08.png +0 -0
  25. package/assets/jellyfish/light-09.png +0 -0
  26. package/assets/jellyfish/light-10.png +0 -0
  27. package/assets/jellyfish/light-11.png +0 -0
  28. package/dist/brand.js +7 -7
  29. package/dist/cli-options.js +12 -6
  30. package/dist/config-edit.js +1 -0
  31. package/dist/config.js +22 -2
  32. package/dist/cultivate-cli.js +16 -23
  33. package/dist/extension.js +128 -108
  34. package/dist/init-config.js +5 -0
  35. package/dist/jellyfish.js +130 -0
  36. package/dist/loop-cli.js +16 -8
  37. package/dist/loop-tools.js +60 -21
  38. package/dist/module-report.js +5 -4
  39. package/dist/pi.js +76 -19
  40. package/dist/picture-row.js +3 -2
  41. package/dist/regenerate/activity.js +21 -0
  42. package/dist/regenerate/jobs.js +10 -5
  43. package/dist/regenerate/list-arguments.js +121 -0
  44. package/dist/regenerate/loop.js +66 -43
  45. package/dist/regenerate/panel-dock.js +7 -5
  46. package/dist/regenerate/plain-palette.js +52 -37
  47. package/dist/regenerate/regenerate.js +4 -2
  48. package/dist/regenerate/self-check.js +13 -6
  49. package/dist/regenerate/side-panel.js +1 -1
  50. package/dist/regenerate/spec-map-view.js +9 -5
  51. package/dist/regenerate/test-scripts.js +79 -13
  52. package/dist/regenerate/unit-review.js +1 -1
  53. package/dist/regenerate-cli.js +11 -5
  54. package/dist/release-cli.js +3 -8
  55. package/dist/review/live.js +2 -1
  56. package/dist/run-report.js +26 -1
  57. package/dist/screen-padding.js +72 -0
  58. package/dist/stacks.js +3 -5
  59. package/dist/validate-cli.js +3 -8
  60. package/docs/README.md +5 -12
  61. package/docs/authoring-plain.md +37 -119
  62. package/docs/config.md +55 -178
  63. package/docs/deploy.md +21 -80
  64. package/docs/development.md +14 -41
  65. package/docs/headless.md +40 -129
  66. package/docs/images/how-turri-works.svg +29 -31
  67. package/docs/images/turri-banner.png +0 -0
  68. package/docs/images/turri-screenshot.png +0 -0
  69. package/docs/installation.md +13 -40
  70. package/docs/parser.md +15 -43
  71. package/docs/regenerating.md +231 -942
  72. package/docs/sandbox.md +38 -152
  73. package/docs/skills-and-gates.md +50 -173
  74. package/docs/theming.md +45 -46
  75. package/docs/using.md +68 -344
  76. package/genome/rules/bullet-continuation.md +5 -13
  77. package/genome/rules/concise-specs-examples.md +2 -4
  78. package/genome/rules/concise-specs-integration-examples.md +2 -6
  79. package/genome/rules/concise-specs.md +1 -2
  80. package/genome/rules/func-specs.md +1 -0
  81. package/genome/rules/integration-embedded-testing.md +1 -4
  82. package/genome/rules/integrations.md +1 -2
  83. package/genome/rules/project-model.md +14 -35
  84. package/genome/rules/stdlib.md +14 -49
  85. package/genome/rules/turri-regeneration.md +48 -0
  86. package/genome/skills/add-implementation-requirement/SKILL.md +1 -2
  87. package/genome/skills/analyze-if-func-spec-too-complex/SKILL.md +3 -8
  88. package/genome/skills/brood/SKILL.md +37 -127
  89. package/genome/skills/brood/references/intent.md +4 -12
  90. package/genome/skills/brood/references/product.md +24 -76
  91. package/genome/skills/brood/references/stack.md +7 -29
  92. package/genome/skills/brood/references/testing.md +11 -42
  93. package/genome/skills/bud/SKILL.md +32 -109
  94. package/genome/skills/bud/references/intent.md +4 -11
  95. package/genome/skills/implement-conformance-testing-script/SKILL.md +4 -7
  96. package/genome/skills/implement-unit-testing-script/SKILL.md +2 -3
  97. package/genome/skills/init-plain-project/SKILL.md +1 -1
  98. package/genome/skills/mature/SKILL.md +21 -69
  99. package/genome/skills/refactor-module/SKILL.md +24 -2
  100. package/genome/skills/spawn/SKILL.md +28 -113
  101. package/package.json +1 -1
  102. package/assets/jellyfish/dark-12.png +0 -0
  103. package/assets/jellyfish/dark-13.png +0 -0
  104. package/assets/jellyfish/dark-14.png +0 -0
  105. package/assets/jellyfish/fallback.txt +0 -252
  106. package/assets/jellyfish/light-12.png +0 -0
  107. package/assets/jellyfish/light-13.png +0 -0
  108. package/assets/jellyfish/light-14.png +0 -0
@@ -52,6 +52,9 @@ export function createJobRegistry(options) {
52
52
  },
53
53
  start(input) {
54
54
  const id = randomUUID().slice(0, 8);
55
+ // The stack chosen as it is queued - or pinned for the work that queues it - not as it starts: a job that waits
56
+ // for a slot is built with the stack it was asked for, whatever is chosen meanwhile.
57
+ const stack = chosenStack();
55
58
  const claimed = [...new Set(input.lanes ?? [])];
56
59
  const blockers = [
57
60
  ...new Set(claimed
@@ -70,6 +73,7 @@ export function createJobRegistry(options) {
70
73
  ...(input.title !== undefined ? { title: input.title } : {}),
71
74
  diff: input.diff,
72
75
  model: input.model,
76
+ ...(stack !== undefined ? { stack } : {}),
73
77
  ...(input.follows !== undefined ? { follows: input.follows } : {}),
74
78
  status: blockers.length > 0 || (limit !== undefined && active >= limit) ? "queued" : "running",
75
79
  sequence: (sequence += 1),
@@ -273,9 +277,9 @@ export function createJobRegistry(options) {
273
277
  log = startJobLog(job, claimed);
274
278
  if (log !== undefined)
275
279
  job.logFile = log.file;
276
- // What the job's agents start runs until it ends, and no longer (withPulse) - with the stack chosen as it
277
- // starts, whatever is chosen while it runs.
278
- return withStack(chosenStack(), () => (guarded ? runGuarded() : runOnce()));
280
+ // What the job's agents start runs until it ends, and no longer (withPulse) - with the stack it was queued
281
+ // with, whatever is chosen while it waits or runs.
282
+ return withStack(stack, () => (guarded ? runGuarded() : runOnce()));
279
283
  })
280
284
  .then((outcome) => {
281
285
  // Asked to stop, it is stopped - whether its work threw as it unwound or returned what it had.
@@ -385,10 +389,11 @@ export function pulseName(job) {
385
389
  }
386
390
  /** What the agent is told when it checks on a job. */
387
391
  export function describeJob(job) {
392
+ const name = `${pulseName(job)}${job.stack !== undefined ? ` (stack ${job.stack})` : ""}`;
388
393
  if (job.status === "queued") {
389
- return `${pulseName(job)}: queued behind ${job.waitingOn.map((id) => `pulse ${id}`).join(" and ")}. It starts when that finishes.`;
394
+ return `${name}: queued behind ${job.waitingOn.map((id) => `pulse ${id}`).join(" and ")}. It starts when that finishes.`;
390
395
  }
391
- const header = `${pulseName(job)}: ${job.status}, ${formatDuration(job)}`;
396
+ const header = `${name}: ${job.status}, ${formatDuration(job)}`;
392
397
  if (job.status === "running") {
393
398
  return [
394
399
  header,
@@ -0,0 +1,121 @@
1
+ const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
2
+ /** The tool's arguments that take a list of objects. */
3
+ function listArguments(schema) {
4
+ const required = new Set(schema.required ?? []);
5
+ return Object.entries(schema.properties ?? {})
6
+ .filter(([, property]) => property.type === "array" && property.items?.type === "object")
7
+ .map(([name, property]) => ({ name, required: required.has(name), item: property.items }));
8
+ }
9
+ /** JSON text, fenced or not, as what it holds; anything else as it is. */
10
+ function parsed(value) {
11
+ if (typeof value !== "string")
12
+ return value;
13
+ const text = value
14
+ .trim()
15
+ .replace(/^```(?:json)?\s*/i, "")
16
+ .replace(/\s*```$/, "");
17
+ if (!/^[[{]/.test(text))
18
+ return value;
19
+ try {
20
+ return JSON.parse(text);
21
+ }
22
+ catch {
23
+ return value;
24
+ }
25
+ }
26
+ const escaped = (name) => name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
27
+ /**
28
+ * Arguments the model wrote inside another argument's text - `answer</a>\n<b>[...]</b>\n<c>...` - taken out of it and
29
+ * given as their own, where they were not given already. Which argument each was found in, for the refusal.
30
+ */
31
+ function untucked(args, names) {
32
+ const out = { ...args };
33
+ const foundIn = new Map();
34
+ const anyTag = names.map(escaped).join("|");
35
+ for (const [key, value] of Object.entries(args)) {
36
+ if (typeof value !== "string")
37
+ continue;
38
+ let cut = value.search(new RegExp(`</${escaped(key)}>`));
39
+ for (const name of names) {
40
+ if (name === key || (out[name] !== undefined && out[name] !== ""))
41
+ continue;
42
+ const match = new RegExp(`<${escaped(name)}>([\\s\\S]*?)(?:</${escaped(name)}>|(?=<(?:${anyTag})>)|$)`).exec(value);
43
+ if (match === null)
44
+ continue;
45
+ out[name] = match[1].trim();
46
+ foundIn.set(name, key);
47
+ cut = cut === -1 ? match.index : Math.min(cut, match.index);
48
+ }
49
+ if (cut !== -1)
50
+ out[key] = value.slice(0, cut).trim();
51
+ }
52
+ return { args: out, foundIn };
53
+ }
54
+ /** What an entry of the list looks like, as JSON: its fields, the optional ones marked. */
55
+ function shapeOf(item) {
56
+ const required = new Set(item.required ?? []);
57
+ const entries = Object.entries(item.properties ?? {});
58
+ const fields = entries.map(([name, field]) => `"${name}"${required.has(name) ? "" : "?"}: ${field.type ?? "value"}`).join(", ");
59
+ const sample = (field) => (field.type === "number" || field.type === "integer" ? "1" : field.type === "boolean" ? "true" : field.type === "string" ? '"..."' : "...");
60
+ const example = entries
61
+ .filter(([name]) => required.has(name))
62
+ .map(([name, field]) => `"${name}": ${sample(field)}`)
63
+ .join(", ");
64
+ return { fields: `{${fields}}`, example: `{${example}}` };
65
+ }
66
+ /** Why a list argument is not one, said so a model can make the call right next time - or undefined when it is. */
67
+ function problemOf(list, value, foundIn) {
68
+ if (value === undefined)
69
+ return list.required ? "you left it out" : undefined;
70
+ if (!Array.isArray(value)) {
71
+ if (foundIn !== undefined)
72
+ return `you wrote it inside \`${foundIn}\``;
73
+ return typeof value === "string" ? "you sent it as text, not a list" : `you sent ${isObject(value) ? "an object" : `a ${typeof value}`}, not a list`;
74
+ }
75
+ const bad = value.findIndex((entry) => !isObject(entry));
76
+ if (bad === -1)
77
+ return undefined;
78
+ return `entry ${bad + 1} is ${typeof value[bad] === "string" ? "text" : `a ${typeof value[bad]}`}, not an object`;
79
+ }
80
+ /** The arguments with their lists made lists where they plainly are; refused, saying what is wanted, where they are not. */
81
+ export function prepareListArguments(toolName, schema, raw) {
82
+ const lists = listArguments(schema);
83
+ if (lists.length === 0 || !isObject(raw))
84
+ return raw;
85
+ const { args, foundIn } = untucked(raw, Object.keys(schema.properties ?? {}));
86
+ const problems = [];
87
+ for (const list of lists) {
88
+ let value = parsed(args[list.name]);
89
+ if (isObject(value))
90
+ value = [value];
91
+ if (Array.isArray(value))
92
+ value = value.map(parsed);
93
+ if (value !== undefined)
94
+ args[list.name] = value;
95
+ const problem = problemOf(list, value, foundIn.get(list.name));
96
+ if (problem === undefined)
97
+ continue;
98
+ const { fields, example } = shapeOf(list.item);
99
+ problems.push(`- \`${list.name}\`: ${problem}. It is a list of objects, each ${fields} - e.g. "${list.name}": [${example}].`);
100
+ }
101
+ if (problems.length === 0)
102
+ return args;
103
+ throw new Error([
104
+ `${toolName} was not run - its arguments are not in the shape it takes:`,
105
+ ...problems,
106
+ "Each argument is a field of its own in the call, at the top level: a list is a JSON array of objects, never text, and never written inside another argument's text.",
107
+ ].join("\n"));
108
+ }
109
+ /** The tools, each that takes a list of objects preparing its arguments so before they are checked. */
110
+ export function withListArguments(tools) {
111
+ return tools.map((tool) => {
112
+ const schema = tool.parameters;
113
+ if (listArguments(schema).length === 0)
114
+ return tool;
115
+ const before = tool.prepareArguments;
116
+ return {
117
+ ...tool,
118
+ prepareArguments: (args) => prepareListArguments(tool.name, schema, before !== undefined ? before(args) : args),
119
+ };
120
+ });
121
+ }
@@ -13,7 +13,7 @@ import { adoptDigests, chainTree, codeTree, conformanceTarget, REGENERATE_AGAIN,
13
13
  import { describeSpecDiffConformance, renderSpecDiffConformance } from "./conform.js";
14
14
  import { conformanceDirFor } from "./conformance.js";
15
15
  import { modulesRoot } from "./paths.js";
16
- import { budgetFor, choosingWhen, configForSpec, conformanceSwitchedOn } from "../config.js";
16
+ import { budgetFor, chosenStack, choosingWhen, configForSpec, conformanceSwitchedOn, withStack } from "../config.js";
17
17
  import { describeSpecChange } from "./prompt.js";
18
18
  import { resolveTemplateDirs } from "./paths.js";
19
19
  import { builtTips, copyRequiredCode, importingModules, isImportModule, newlyRequired, resolveRequiresChain, startFromScratch } from "./requires.js";
@@ -189,6 +189,8 @@ export function createWorkLoop(options) {
189
189
  // One tick at a time: each reads the records and the spec, and decides.
190
190
  let ticking = Promise.resolve();
191
191
  const tipEntry = (state) => tipOf(state.chain);
192
+ /** `work` with the codebase's stack chosen - the one it was asked for with - when it has one pinned. */
193
+ const inStack = (state, work) => (state.stack !== undefined ? withStack(state.stack.name, work) : work());
192
194
  const keyOf = (spec) => serializeTree(codeTree(spec.tree));
193
195
  /** What a codebase is built from: its record, or - nothing built - what it starts from, the code of the module it requires. */
194
196
  const builtOf = (state) => {
@@ -811,7 +813,7 @@ export function createWorkLoop(options) {
811
813
  // A codebase left behind - built on since - is not looked at, unless a job of it is still running; what it had
812
814
  // planned, or waited for, is no longer shown.
813
815
  if (now.has(state) || state.running !== undefined)
814
- await look(state);
816
+ await inStack(state, () => look(state));
815
817
  else {
816
818
  state.why = "left behind: the code is built on further up the chain, where changes to it are made";
817
819
  state.waitsFor = undefined;
@@ -963,7 +965,8 @@ export function createWorkLoop(options) {
963
965
  };
964
966
  const statusOf = (state) => describe(state).status;
965
967
  /** A codebase's status, and beside each job it lists as planned, the planned job it is - none for one being planned or scheduled. */
966
- const describe = (state) => {
968
+ const describe = (state) => inStack(state, () => describeIn(state));
969
+ const describeIn = (state) => {
967
970
  // What runs next: the code's jobs, then the conformance tests' - the module's, once its code is built - the running job first.
968
971
  const running = state.running?.planned;
969
972
  const own = (jobs) => (jobs ?? []).filter((job) => job !== running);
@@ -1011,6 +1014,7 @@ export function createWorkLoop(options) {
1011
1014
  const status = {
1012
1015
  module: tip.moduleName,
1013
1016
  plainFile: tip.plainFile,
1017
+ ...(state.stack?.name !== undefined ? { stack: state.stack.name } : {}),
1014
1018
  ...(state.running !== undefined
1015
1019
  ? {
1016
1020
  running: {
@@ -1027,8 +1031,11 @@ export function createWorkLoop(options) {
1027
1031
  };
1028
1032
  return { status, jobs: (state.running !== undefined ? listed.slice(1) : listed).map((item) => item.job), scheduled: (state.running !== undefined ? listed.slice(1) : listed).map((item) => (item.entry.waitsFor !== undefined ? { title: item.entry.title, specs: item.entry.cases.add.map((touched) => touched.text) } : undefined)) };
1029
1033
  };
1030
- /** Look after a codebase - its chain up to it - from now on; says its state. */
1031
- const track = (chain, askedFile, request) => {
1034
+ /**
1035
+ * Look after a codebase - its chain up to it - from now on; says its state. `pin`: the stack it is built with from now
1036
+ * on - kept, when `keep` and it has one already.
1037
+ */
1038
+ const track = (chain, askedFile, request, pin) => {
1032
1039
  const tip = tipOf(chain);
1033
1040
  let state = modules.get(tip.buildDir);
1034
1041
  if (state === undefined) {
@@ -1043,7 +1050,10 @@ export function createWorkLoop(options) {
1043
1050
  }
1044
1051
  state.chain = chain;
1045
1052
  state.askedFile = askedFile;
1046
- const model = request.model ?? options.modelFor?.(tip.plainFile);
1053
+ if (pin !== undefined && (pin.keep !== true || state.stack === undefined))
1054
+ state.stack = { name: pin.name };
1055
+ // Its model as its stack has it: a stack's file can name a coding model of its own.
1056
+ const model = request.model ?? inStack(state, () => options.modelFor?.(tip.plainFile));
1047
1057
  if (model !== undefined)
1048
1058
  state.model = model;
1049
1059
  if (request.guidance !== undefined && !state.guidance.includes(request.guidance))
@@ -1056,7 +1066,10 @@ export function createWorkLoop(options) {
1056
1066
  const files = codebasesOf(resolve(options.cwd, plainFile));
1057
1067
  for (const file of files)
1058
1068
  asked.set(file, { ...asked.get(file), ...request });
1059
- const states = withParseCache(() => files.flatMap((file) => chainsFor(file).flatMap((chain) => toBuild(chain).map((entry) => track(chain.slice(0, chain.indexOf(entry) + 1), file, request)))));
1069
+ // Asked for, it is built with the stack chosen now - pinned, whatever is chosen later; a spec change keeps the one
1070
+ // it was asked for with.
1071
+ const pin = { name: chosenStack(), keep: specChange === true };
1072
+ const states = withParseCache(() => files.flatMap((file) => chainsFor(file).flatMap((chain) => toBuild(chain).map((entry) => track(chain.slice(0, chain.indexOf(entry) + 1), file, request, pin)))));
1060
1073
  // Asked again, a halted codebase is tried again - one the person halted too, unless only its spec changed.
1061
1074
  for (const state of states) {
1062
1075
  state.halted = undefined;
@@ -1110,32 +1123,34 @@ export function createWorkLoop(options) {
1110
1123
  const tip = tipOf(codebase);
1111
1124
  // The codebase as the loop knows it, or - never asked for - as its records have it.
1112
1125
  const state = modules.get(tip.buildDir) ?? { chain: codebase, askedFile: file, guidance: [] };
1113
- const report = { module: tip.moduleName, plainFile: tip.plainFile, code: undefined, conformance: undefined, scheduled: [] };
1114
- let spec;
1115
- try {
1116
- spec = chainSpec(codebase);
1117
- }
1118
- catch (error) {
1119
- return { ...report, why: `its spec does not parse: ${error instanceof Error ? error.message : String(error)}` };
1120
- }
1121
- const from = builtOf(state);
1122
- const fresh = tip.requires === null && !started(tip);
1123
- const code = codeWork(from, spec.tree);
1124
- report.code = code.length === 0 ? null : casesOf(from, code, { fresh, module: tip.moduleName });
1125
- if (conformanceWanted(state, spec)) {
1126
- const tested = testedOf(state);
1127
- const tests = workOf("conformance", tested, state, spec);
1128
- report.conformance = tests.length === 0 ? null : casesOf(tested, tests, { module: tip.moduleName });
1129
- }
1130
- report.scheduled = (state.scheduled ?? []).map((group) => ({ frids: group.specs.map((touched) => touched.frid), unbuilt: group.unbuilt }));
1131
- if (state.running !== undefined)
1132
- report.running = { jobId: state.running.jobId, title: state.running.planned.title };
1133
- const halted = state.held?.why ?? state.halted?.why ?? state.conformanceHalted?.why;
1134
- if (halted !== undefined)
1135
- report.why = halted;
1136
- if (state.startOver !== undefined)
1137
- report.startOver = state.startOver;
1138
- return report;
1126
+ return inStack(state, () => {
1127
+ const report = { module: tip.moduleName, plainFile: tip.plainFile, code: undefined, conformance: undefined, scheduled: [] };
1128
+ let spec;
1129
+ try {
1130
+ spec = chainSpec(codebase);
1131
+ }
1132
+ catch (error) {
1133
+ return { ...report, why: `its spec does not parse: ${error instanceof Error ? error.message : String(error)}` };
1134
+ }
1135
+ const from = builtOf(state);
1136
+ const fresh = tip.requires === null && !started(tip);
1137
+ const code = codeWork(from, spec.tree);
1138
+ report.code = code.length === 0 ? null : casesOf(from, code, { fresh, module: tip.moduleName });
1139
+ if (conformanceWanted(state, spec)) {
1140
+ const tested = testedOf(state);
1141
+ const tests = workOf("conformance", tested, state, spec);
1142
+ report.conformance = tests.length === 0 ? null : casesOf(tested, tests, { module: tip.moduleName });
1143
+ }
1144
+ report.scheduled = (state.scheduled ?? []).map((group) => ({ frids: group.specs.map((touched) => touched.frid), unbuilt: group.unbuilt }));
1145
+ if (state.running !== undefined)
1146
+ report.running = { jobId: state.running.jobId, title: state.running.planned.title };
1147
+ const halted = state.held?.why ?? state.halted?.why ?? state.conformanceHalted?.why;
1148
+ if (halted !== undefined)
1149
+ report.why = halted;
1150
+ if (state.startOver !== undefined)
1151
+ report.startOver = state.startOver;
1152
+ return report;
1153
+ });
1139
1154
  })));
1140
1155
  },
1141
1156
  async conformance(plainFile, request = {}) {
@@ -1176,7 +1191,7 @@ export function createWorkLoop(options) {
1176
1191
  }
1177
1192
  }
1178
1193
  }
1179
- const tracked = withParseCache(() => (wentBack ? [own] : chainsFor(file)).flatMap((chain) => toBuild(chain).map((entry) => track(chain.slice(0, chain.indexOf(entry) + 1), file, request))));
1194
+ const tracked = withParseCache(() => (wentBack ? [own] : chainsFor(file)).flatMap((chain) => toBuild(chain).map((entry) => track(chain.slice(0, chain.indexOf(entry) + 1), file, request, { name: chosenStack() }))));
1180
1195
  // The module asked for, in its own codebase - and those below it: never the codebases built on it.
1181
1196
  const asking = tracked.find((state) => tipEntry(state).buildDir === self.buildDir);
1182
1197
  const states = asking !== undefined ? tracked.filter((state) => own.some((entry) => entry.buildDir === tipEntry(state).buildDir)) : tracked;
@@ -1194,7 +1209,7 @@ export function createWorkLoop(options) {
1194
1209
  // On for the whole module already - asked for before, or by the config: asked again, nothing changes, and it is said.
1195
1210
  const already = new Set(states.filter((state) => {
1196
1211
  const file = tipEntry(state).plainFile;
1197
- return (state.conformance !== undefined && state.conformance.chosen === undefined) || (configConformance(file) && !configChosen(file));
1212
+ return (state.conformance !== undefined && state.conformance.chosen === undefined) || inStack(state, () => configConformance(file) && !configChosen(file));
1198
1213
  }));
1199
1214
  // Only the module asked for: the modules below it keep their conformance tests as their config and choices have them.
1200
1215
  for (const state of tip !== undefined ? [tip] : []) {
@@ -1247,17 +1262,21 @@ export function createWorkLoop(options) {
1247
1262
  startAgain(entry, `it now requires ${requires.join(", ")}, which its code was not built on`);
1248
1263
  return loop.bringUp(plainFile, request);
1249
1264
  },
1250
- async fromScratch(plainFile, request = {}) {
1265
+ async fromScratch(plainFile, { chain, ...request } = {}) {
1251
1266
  const file = resolve(options.cwd, plainFile);
1252
- // Where its code lives: the tips its module is built in, or - none built yet - its own codebase.
1253
- const codebases = chainsFor(file).map(tipOf);
1267
+ // Where its code lives: the tips its module is built in, or - none built yet - its own codebase. The whole chain:
1268
+ // every codebase in those chains, bottom first - a tip taken back to nothing is otherwise started from a copy of
1269
+ // the code below it.
1270
+ const chains = chainsFor(file);
1271
+ const codebases = [...new Map((chain === true ? chains.flat() : chains.map(tipOf)).map((entry) => [entry.buildDir, entry])).values()];
1254
1272
  for (const entry of codebases) {
1255
1273
  if (modules.get(entry.buildDir)?.running !== undefined)
1256
1274
  throw new Error(`${entry.moduleName} has a pulse running: halt it, or ask again once it is done.`);
1257
1275
  }
1276
+ const why = chain === true ? "asked to be regenerated from scratch, with its whole chain" : "asked to be regenerated from scratch";
1258
1277
  for (const entry of codebases)
1259
1278
  if (started(entry))
1260
- startAgain(entry, "asked to be regenerated from scratch");
1279
+ startAgain(entry, why);
1261
1280
  return loop.bringUp(plainFile, request);
1262
1281
  },
1263
1282
  halt(target, reason) {
@@ -1398,7 +1417,7 @@ export function createWorkLoop(options) {
1398
1417
  plainFile: tip.plainFile,
1399
1418
  buildDir: tip.buildDir,
1400
1419
  pulses,
1401
- conformance: state.conformance !== undefined || configConformance(tip.plainFile),
1420
+ conformance: state.conformance !== undefined || inStack(state, () => configConformance(tip.plainFile)),
1402
1421
  ...(state.planning !== undefined ? { planning: state.planning } : {}),
1403
1422
  ...(running === undefined && state.waitsFor !== undefined ? { waitsFor: state.waitsFor } : {}),
1404
1423
  ...(running === undefined && state.why !== undefined ? { why: state.why } : {}),
@@ -1409,7 +1428,11 @@ export function createWorkLoop(options) {
1409
1428
  },
1410
1429
  async drain() {
1411
1430
  for (;;) {
1412
- await ticking;
1431
+ // A pulse that settles meanwhile ticks again: its next pulse is started by that tick, so it is waited for too.
1432
+ const looking = ticking;
1433
+ await looking;
1434
+ if (looking !== ticking)
1435
+ continue;
1413
1436
  const running = order.map((key) => modules.get(key).running?.jobId).filter((id) => id !== undefined);
1414
1437
  if (running.length === 0)
1415
1438
  return;
@@ -1518,7 +1541,7 @@ export function describeModules(statuses, options = {}) {
1518
1541
  ` Ask the user whether to start ${codebases.join(", ")} over, and say why: ${codebases.join(", ")} was built without ` +
1519
1542
  `${requires.join(", ")}, so no change to its code can bring ${requires.join(", ")} in - its code and conformance ` +
1520
1543
  "tests are taken out, kept in its history, and built again from the bottom of the chain. Only if they agree, " +
1521
- `call regenerate with ${basename(status.plainFile)} and from_scratch.`,
1544
+ `call regenerate with ${basename(status.plainFile)} and from_scratch: "module".`,
1522
1545
  ];
1523
1546
  };
1524
1547
  return statuses
@@ -1526,7 +1549,7 @@ export function describeModules(statuses, options = {}) {
1526
1549
  // Nothing to do there: said in a sentence, not as a status.
1527
1550
  if (isUpToDate(status))
1528
1551
  return `${status.module} is up to date: its code is built from the spec as it is now in ${basename(status.plainFile)}, so there is nothing to regenerate.`;
1529
- const lines = [`${status.module} (${basename(status.plainFile)}):`];
1552
+ const lines = [`${status.module} (${basename(status.plainFile)}${status.stack !== undefined ? `, stack ${status.stack}` : ""}):`];
1530
1553
  if (status.running !== undefined) {
1531
1554
  lines.push(` running: pulse ${status.running.jobId} - ${status.running.title}`);
1532
1555
  // Steered, not stopped or planned again: what changed went to its agent.
@@ -1,15 +1,16 @@
1
1
  import { HStack } from "@earendil-works/pi-tui";
2
+ import { unpadded } from "../screen-padding.js";
2
3
  /**
3
4
  * 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
5
  * laid over the columns on the right.
5
6
  *
6
7
  * 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
8
  * 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
+ * asked for in fewer columns. Either way inside the screen's padding (`screen-padding.ts`), when it has one.
9
10
  */
10
11
  /** Narrower than this, the chat and the panel have no room side by side: the panel takes the whole screen. */
11
12
  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
+ /** The columns the panel takes beside the chat: half of what they share, the rule between them in the middle - 0 when that is too narrow to share. */
13
14
  export function dockedWidth(columns) {
14
15
  return columns < SHARED_FROM ? 0 : Math.floor(columns / 2);
15
16
  }
@@ -20,14 +21,15 @@ export function dockedWidth(columns) {
20
21
  export function narrowChat(tui, panelWidth) {
21
22
  const screen = tui;
22
23
  if (typeof screen.setLayoutRoot === "function" && screen.layoutRoot !== undefined) {
23
- const root = screen.layoutRoot;
24
+ // What the padding pads: the row goes inside it, and is padded as it is set.
25
+ const root = unpadded(screen.layoutRoot);
24
26
  // A line as wide as the panel: the row gives the filler what it measures, the chat the rest.
25
27
  const filler = { render: () => [" ".repeat(panelWidth())], invalidate() { } };
26
28
  screen.setLayoutRoot(new HStack([{ component: root, basis: 0, grow: 1 }, { component: filler }]));
27
29
  return () => screen.setLayoutRoot(root);
28
30
  }
29
- // Read from the prototype: the screen's own render, not one laid over it.
30
- const render = Object.getPrototypeOf(tui).render;
31
+ // The render the screen has now - padded, when it is.
32
+ const render = screen.render;
31
33
  screen.render = function (width) {
32
34
  return render.call(this, Math.max(1, width - panelWidth()));
33
35
  };
@@ -1,45 +1,53 @@
1
- /** On a dark surface - turri-dark's #0f0f0f, pi's dark ones. Every colour at least 7:1 on it, and 4.5:1 on the fills. */
1
+ /**
2
+ * On a dark surface - turri-dark's abyss, #0a0f1a, pi's dark ones - in the design system's colours alone: a section's
3
+ * header in pink, a concept in neon, text in quotes or backticks in siesta tan. Every colour at least 7:1 on abyss and 4.8:1 on the blue whale fill
4
+ * of an added line; on the eggplant of a removed one, the design system's only fill of that warmth, its pinks and
5
+ * grauzone drop to 3.7:1.
6
+ */
2
7
  const DARK = {
3
8
  roles: {
4
- section: { colour: "#fcd34d", bold: true },
5
- concept: { colour: "#7dd3fc" },
6
- link: { colour: "#c4b5fd", underline: true },
7
- literal: { colour: "#fdba74" },
8
- keyword: { colour: "#f9a8d4", bold: true },
9
- module: { colour: "#5eead4" },
10
- comment: { colour: "#b4bfcf", italic: true },
11
- bullet: { colour: "#b4bfcf" },
9
+ section: { colour: "#ff7fa6", bold: true },
10
+ concept: { colour: "#5ce1e6" },
11
+ link: { colour: "#f4f7f9", underline: true },
12
+ literal: { colour: "#e9d8c8" },
13
+ keyword: { colour: "#f4f7f9", bold: true },
14
+ module: { colour: "#f4f7f9" },
15
+ comment: { colour: "#85a3b2", italic: true },
16
+ bullet: { colour: "#85a3b2" },
12
17
  },
13
- added: "#86efac",
14
- removed: "#fca5a5",
15
- addedFill: "#1f4d2e",
16
- removedFill: "#5c2323",
17
- muted: "#808080",
18
+ added: "#5ce1e6",
19
+ removed: "#ff7fa6",
20
+ addedFill: "#1e3442",
21
+ removedFill: "#732553",
22
+ muted: "#85a3b2",
18
23
  };
19
- /** On a light surface - turri-light's white, pi's light ones. Every colour at least 7:1 on it, and 5:1 on the fills. */
24
+ /**
25
+ * On a light surface - turri-light's white, pi's light ones - in the design system's deep colours, the only ones it has
26
+ * that read on white. Every colour at least 7:1 on white, and 5:1 on the neon hover and siesta tan fills.
27
+ */
20
28
  const LIGHT = {
21
29
  roles: {
22
- section: { colour: "#0a1fd4", bold: true },
23
- concept: { colour: "#155e75" },
24
- link: { colour: "#6d28d9", underline: true },
25
- literal: { colour: "#92400e" },
26
- keyword: { colour: "#9d174d", bold: true },
27
- module: { colour: "#065f46" },
28
- comment: { colour: "#475569", italic: true },
29
- bullet: { colour: "#475569" },
30
+ section: { colour: "#3e5a6b", bold: true },
31
+ concept: { colour: "#732553" },
32
+ link: { colour: "#1e3442", underline: true },
33
+ literal: { colour: "#1e3442" },
34
+ keyword: { colour: "#0a0f1a", bold: true },
35
+ module: { colour: "#1e3442" },
36
+ comment: { colour: "#3e5a6b", italic: true },
37
+ bullet: { colour: "#3e5a6b" },
30
38
  },
31
- added: "#166534",
32
- removed: "#991b1b",
33
- addedFill: "#d3f5dc",
34
- removedFill: "#fcd9d9",
35
- muted: "#6b7280",
39
+ added: "#1e3442",
40
+ removed: "#732553",
41
+ addedFill: "#8eebee",
42
+ removedFill: "#e9d8c8",
43
+ muted: "#3e5a6b",
36
44
  };
37
45
  const rgb = (hex) => {
38
46
  const value = Number.parseInt(hex.slice(1), 16);
39
47
  return [(value >> 16) & 255, (value >> 8) & 255, value & 255];
40
48
  };
41
49
  /** A colour's SGR parameters: 24-bit, or the nearest of the 256 where the terminal has no more. */
42
- function sgr(hex, background, truecolor) {
50
+ export function sgr(hex, background, truecolor) {
43
51
  const [r, g, b] = rgb(hex);
44
52
  if (truecolor)
45
53
  return `${background ? 48 : 38};2;${r};${g};${b}`;
@@ -57,17 +65,24 @@ const fillWith = (hex, text, truecolor) => {
57
65
  return `${on}${text.replace(/\x1b\[(?:0|49)?m/g, (reset) => `${reset}${on}`)}\x1b[49m`;
58
66
  };
59
67
  /**
60
- * Brand blue, for what is shown to do what its spec says - regen's ◆. Brand blue itself on a light surface, 9.72:1
61
- * on white; on a dark one, where it is illegible (1.97:1 on brand black - see docs/theming.md), its tint 55% of the way
62
- * to white, 7.34:1 on brand black.
68
+ * Neon, for what is shown to do what its spec says - regen's ◆: the design system's colour for what can be followed,
69
+ * 12.2:1 on abyss. On a light surface, where neon is illegible (1.6:1 on white), blue whale, 12.9:1 on white.
63
70
  */
64
- export const BRAND_BLUE = { light: "#0a1fd4", dark: "#919aec" };
65
- /** Text in brand blue on a theme - its tint on a dark one - in as many colours as the terminal has. */
66
- export function brandBlue(theme) {
67
- const colour = theme.appearance === "light" ? BRAND_BLUE.light : BRAND_BLUE.dark;
71
+ export const BRAND_NEON = { light: "#1e3442", dark: "#5ce1e6" };
72
+ /**
73
+ * Pink, the one pink thing in a view - the banner's wordmark: 6.54:1 on abyss. On a light surface, where pink is
74
+ * too pale (2.9:1 on white), eggplant, 9.9:1 on white.
75
+ */
76
+ export const BRAND_PINK = { light: "#732553", dark: "#ff5c8d" };
77
+ const brandInk = (colours) => (theme) => {
78
+ const colour = theme.appearance === "light" ? colours.light : colours.dark;
68
79
  const truecolor = (theme.getColorMode?.() ?? "truecolor") === "truecolor";
69
80
  return (text) => paintWith({ colour, bold: true }, text, truecolor);
70
- }
81
+ };
82
+ /** Text in neon on a theme - blue whale on a light one - in as many colours as the terminal has. */
83
+ export const brandNeon = brandInk(BRAND_NEON);
84
+ /** Text in pink on a theme - eggplant on a light one - in as many colours as the terminal has. */
85
+ export const brandPink = brandInk(BRAND_PINK);
71
86
  /** How a spec diff is painted on a theme: its palette by whether the theme is dark or light, in as many colours as the terminal has. */
72
87
  export function plainPaint(theme) {
73
88
  const palette = theme.appearance === "light" ? LIGHT : DARK;
@@ -281,9 +281,11 @@ export async function renderSpecDiff(options) {
281
281
  const work = createWorkLedger();
282
282
  // What it checks its own work with: the diff its reviewer is shown, and whether a test catches a bug - neither decides anything.
283
283
  const gate = createUnitGate(buildDir, scripts.unit);
284
+ // can_it_fail, for the coding agent and its reviewer: on unless mutation-testing says otherwise.
285
+ const mutationTesting = scripts.unit !== undefined && configForSpec(tip.plainFile).mutationTesting !== false;
284
286
  const selfChecks = [
285
287
  createMyDiffTool({ dir: buildDir, what: "code" }),
286
- ...(scripts.runOn === "copy" ? [createCanItFailTool({ buildDir, script: scripts.unit })] : []),
288
+ ...(mutationTesting ? [createCanItFailTool({ buildDir, script: scripts.unit })] : []),
287
289
  ];
288
290
  // A server it built, it can start and try from outside - stopped when it is done.
289
291
  const services = createServiceTools({ dir: buildDir });
@@ -499,7 +501,7 @@ export async function renderSpecDiff(options) {
499
501
  forChange: true,
500
502
  ...(options.cases !== undefined ? { cases: options.cases } : {}),
501
503
  label: `${moduleName} spec change`,
502
- ...(scripts.runOn === "copy" ? { unitScript: scripts.unit } : {}),
504
+ ...(mutationTesting ? { unitScript: scripts.unit } : {}),
503
505
  testingScript: { path: relative(root, scripts.unit), content: readFileSync(scripts.unit, "utf8") },
504
506
  model: options.judgeModel ?? modelSpec(inheritModel(configForSpec(tip.plainFile).judgeModel, modelOnly(options.model))),
505
507
  send: async (next) => {
@@ -1,9 +1,9 @@
1
- import { readFileSync, writeFileSync } from "node:fs";
2
- import { join, relative, resolve, sep } from "node:path";
1
+ import { readFileSync } from "node:fs";
2
+ import { relative, resolve, sep } from "node:path";
3
3
  import { defineTool } from "@earendil-works/pi-coding-agent";
4
4
  import { Type } from "typebox";
5
5
  import { workDiff } from "./lineage.js";
6
- import { lastPassingMs, runOnCode } from "./test-scripts.js";
6
+ import { lastPassingMs, runOnCode, scriptsRunInPlace } from "./test-scripts.js";
7
7
  /**
8
8
  * Tools an agent checks its own work with, before the harness and the reviewer do: the diff the reviewer is shown, and
9
9
  * whether a test catches a change to the code. Neither decides anything - the testing scripts, run by the harness, still do.
@@ -43,16 +43,23 @@ export function canItFailLimitMs(buildDir, script) {
43
43
  */
44
44
  export function createCanItFailTool(options) {
45
45
  let left = options.runs ?? CAN_IT_FAIL_RUNS;
46
+ // In place, the change is made to the code itself for the run, and undone after it: the scripts run on the code there.
47
+ const inPlace = scriptsRunInPlace(options.buildDir);
46
48
  return defineTool({
47
49
  name: "can_it_fail",
48
50
  label: "Can it fail",
49
51
  description: "Check that the unit tests catch a bug: give one change to the code that breaks a behaviour the specification " +
50
52
  "states - a value or a status changed, a check taken out, a condition turned round where it cannot make a loop run for " +
51
53
  "ever - and the unit testing script " +
52
- "runs on a copy of the code with that change. The code itself is never touched. The tests should fail; if they all " +
54
+ (inPlace
55
+ ? "runs with that change made to the code, which is put back as it was once the run ends, whatever its result. "
56
+ : "runs on a copy of the code with that change. The code itself is never touched. ") +
57
+ "The tests should fail; if they all " +
53
58
  "pass, no test catches that bug. Make a change that still builds and runs: a failure only because it no longer " +
54
59
  `compiles or imports says nothing about the tests. ${options.runs ?? CAN_IT_FAIL_RUNS} runs at most.`,
55
- promptSnippet: "can_it_fail: whether the unit tests catch a bug you put in a copy of the code",
60
+ promptSnippet: "can_it_fail: whether the unit tests catch a bug you put in the code for one run",
61
+ // Never beside another call: in place, an edit made while the bug is in would be undone with it.
62
+ executionMode: "sequential",
56
63
  parameters: Type.Object({
57
64
  file: Type.String({ description: "The code file to change, relative to the code folder" }),
58
65
  find: Type.String({ description: "Text that is in the file exactly once - the code to change" }),
@@ -83,7 +90,7 @@ export function createCanItFailTool(options) {
83
90
  left -= 1;
84
91
  let run;
85
92
  try {
86
- run = await runOnCode(options.buildDir, options.script, "unit testing script, with the change", (copy) => writeFileSync(join(copy, relative(options.buildDir, path)), text.slice(0, at) + replace + text.slice(at + find.length)), canItFailLimitMs(options.buildDir, options.script));
93
+ run = await runOnCode(options.buildDir, options.script, "unit testing script, with the change", { file: relative(options.buildDir, path), text: text.slice(0, at) + replace + text.slice(at + find.length) }, canItFailLimitMs(options.buildDir, options.script));
87
94
  }
88
95
  catch (error) {
89
96
  return say(error instanceof Error ? error.message : String(error));
@@ -16,7 +16,7 @@ export function createSidePanel(options) {
16
16
  const backKeys = () => {
17
17
  if (options.dock === undefined)
18
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`];
19
+ return options.dock.docked() ? [`${options.key} or esc to the chat`, "ctrl+c close", "s full screen"] : ["s beside the chat", `esc or ${options.key} back to the chat`];
20
20
  };
21
21
  const waitingNote = () =>
22
22
  // A question asked while it showed waits in the chat, unanswered: the person is told it is there.