@turri-dev/cli 0.1.3 → 0.1.4-next.01530aa

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.
@@ -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.
@@ -297,6 +297,10 @@ export function setScriptTimeoutForTests(ms) {
297
297
  * own paths start - and whether they run on the code in place (the default), rather than on a fresh copy
298
298
  * (`testing-scripts-run-on: copy`).
299
299
  */
300
+ /** Whether the testing scripts run on the code in `buildDir` itself, not on a copy of it. */
301
+ export function scriptsRunInPlace(buildDir) {
302
+ return projectOfBuild(buildDir).inPlace;
303
+ }
300
304
  function projectOfBuild(buildDir) {
301
305
  const parts = resolve(buildDir).split(sep);
302
306
  const index = parts.lastIndexOf("plain_modules");
@@ -401,30 +405,70 @@ const lastPassing = new Map();
401
405
  export function lastPassingMs(buildDir, script) {
402
406
  return lastPassing.get(`${resolve(buildDir)}\n${script}`);
403
407
  }
408
+ /** Files changed in place for a run under way, and what each held: put back however the run ends - the process exiting too. */
409
+ const changedInPlace = new Map();
410
+ let restoreOnExit = false;
411
+ function putBack(path) {
412
+ const original = changedInPlace.get(path);
413
+ if (original === undefined)
414
+ return;
415
+ writeFileSync(path, original);
416
+ changedInPlace.delete(path);
417
+ }
418
+ /**
419
+ * `run` with `change` made to the code itself, and undone once it ends - passed, failed, timed out, thrown, or the process
420
+ * exiting. Killed outright, the change is left: the next unit of work starts from the last commit (lineage.ts startWork).
421
+ */
422
+ async function withChangeInPlace(buildDir, change, run) {
423
+ const path = resolve(buildDir, change.file);
424
+ if (changedInPlace.has(path))
425
+ throw new Error(`${change.file} is being changed for another run already.`);
426
+ if (!restoreOnExit) {
427
+ restoreOnExit = true;
428
+ process.once("exit", () => {
429
+ for (const changed of [...changedInPlace.keys()])
430
+ putBack(changed);
431
+ });
432
+ }
433
+ changedInPlace.set(path, readFileSync(path));
434
+ try {
435
+ writeFileSync(path, change.text);
436
+ return await run();
437
+ }
438
+ finally {
439
+ putBack(path);
440
+ }
441
+ }
404
442
  /**
405
- * A script that takes the code folder - the unit testing script - run where the testing scripts
406
- * run. `change`: what to do to the fresh copy before it runs - only where there is a copy; never in place.
443
+ * A script that takes the code folder - the unit testing script - run where the testing scripts run. `change`: one file
444
+ * as it is for this run - made to the fresh copy, or, in place, to the code itself and undone once the run ends.
407
445
  */
408
446
  export async function runOnCode(buildDir, script, what, change,
409
447
  /** A time limit of its own, in place of a test run's. */
410
448
  limitMs) {
411
449
  const project = projectOfBuild(buildDir);
450
+ const passed = (run, started) => {
451
+ if (change === undefined && run.exitCode === 0)
452
+ lastPassing.set(`${resolve(buildDir)}\n${script}`, Date.now() - started);
453
+ return run;
454
+ };
412
455
  if (project.inPlace) {
413
- if (change !== undefined)
414
- throw new Error("This runs only where the testing scripts run on a copy: here they run in place, on the code itself.");
415
- return runScript(project.root, script, [resolve(buildDir)], buildDir);
456
+ const inPlace = () => runScript(project.root, script, [resolve(buildDir)], buildDir, limitMs !== undefined ? { limitMs } : {});
457
+ const started = Date.now();
458
+ if (change === undefined)
459
+ return passed(await inPlace(), started);
460
+ reportActivity(` changing ${change.file} in place for the ${what} - put back once it has run`);
461
+ return withChangeInPlace(buildDir, change, inPlace);
416
462
  }
417
463
  const staging = stagingFor(buildDir);
418
464
  rmSync(staging.root, { recursive: true, force: true });
419
465
  ensureInModulesScratch(buildDir, staging.root);
420
466
  try {
421
467
  reportActivity(` copying ${stageBuild(buildDir, staging.build)} files of the code for the ${what}`);
422
- change?.(staging.build);
468
+ if (change !== undefined)
469
+ writeFileSync(join(staging.build, change.file), change.text);
423
470
  const started = Date.now();
424
- const run = await runOnCopy(staging.root, script, [staging.build], buildDir, limitMs);
425
- if (change === undefined && run.exitCode === 0)
426
- lastPassing.set(`${resolve(buildDir)}\n${script}`, Date.now() - started);
427
- return run;
471
+ return passed(await runOnCopy(staging.root, script, [staging.build], buildDir, limitMs), started);
428
472
  }
429
473
  finally {
430
474
  rmSync(staging.root, { recursive: true, force: true });
@@ -96,7 +96,7 @@ export function unitReviewTask(options) {
96
96
  " assertion so loose any answer passes, an expected value computed the way the code computes it.",
97
97
  ...(options.canItFail === true
98
98
  ? [
99
- "- A test you doubt can fail, check: can_it_fail puts a bug in a copy of the code - a condition turned round, a",
99
+ "- A test you doubt can fail, check: can_it_fail puts a bug in the code for one run - a condition turned round, a",
100
100
  " value changed - and runs the unit tests on it. A test that still passes cannot fail: raise it as bad, with the",
101
101
  ` bug it missed. ${REVIEWER_CAN_IT_FAIL_RUNS} runs a session: spend them on the tests the work rests on.`,
102
102
  ]
@@ -19,10 +19,15 @@ its conformance tests too when they are on.
19
19
  --start-over start over, without asking, a codebase regenerated without a module it now requires -
20
20
  with no terminal to ask and without it, the run stops there
21
21
  --from-scratch delete the module's code and conformance tests (its lineage keeps them) and regenerate all of it
22
+ --from-scratch-chain the same for every module of its requires chain, built again from the bottom - after
23
+ modules were split or moved
22
24
  --harness-model <p/id> config.turri.yaml's harness-model for this run: the planner and the conformance chooser
23
25
  --coding-model <p/id> its coding-model, --model too: the agents that build; p/id:level for how hard a model thinks
24
26
  --judge-model <p/id> its judge-model: the judge and the test review
25
27
  --review <true|false> its review: whether the code and its tests are reviewed once they pass
28
+ --mutation-testing <true|false>
29
+ its mutation-testing: whether the coding agent and the reviewer can put a bug in the code
30
+ for one test run (can_it_fail), to see that a test catches it
26
31
  --conformance-tests <all|chosen|module|false>
27
32
  its conformance-tests: which conformance tests are written and run
28
33
  --build-dir <dir> as the run ends, however it ends, export the code there: the furthest-built codebase's
@@ -31,7 +36,7 @@ its conformance tests too when they are on.
31
36
  as it starts, as each pulse ends and as it exits (docs/headless.md)
32
37
 
33
38
  PLAIN_TEMPLATE_DIRS colon-separated template directories`;
34
- const { positional, options } = parseArgs(process.argv.slice(2), ["--dry-run", "--start-over", "--from-scratch"], USAGE, ["--build-dir", "--report", "--conformance-tests", "--harness-model", "--judge-model", "--review"]);
39
+ const { positional, options } = parseArgs(process.argv.slice(2), ["--dry-run", "--start-over", "--from-scratch", "--from-scratch-chain"], USAGE, ["--build-dir", "--report", "--conformance-tests", "--harness-model", "--judge-model", "--review", "--mutation-testing"]);
35
40
  const { report, buildDir } = headlessOptions(options, true);
36
41
  const named = positional[0] ?? readProjectConfig(process.cwd()).module;
37
42
  // Functional specs named after the file: regenerated again though their spec did not change.
@@ -40,9 +45,10 @@ if (!named) {
40
45
  console.error(`${USAGE}\n\nNo file given, and ${CONFIG_FILE} names no module.`);
41
46
  process.exit(1);
42
47
  }
48
+ const scratch = options["from-scratch-chain"] !== undefined ? "chain" : options["from-scratch"] !== undefined ? "module" : undefined;
43
49
  // A dry run starts nothing, and from scratch deletes before it plans: the two do not go together.
44
- if (options["from-scratch"] !== undefined && options["dry-run"] !== undefined) {
45
- console.error("--from-scratch deletes the module's code before anything is planned: it cannot be a dry run.");
50
+ if (scratch !== undefined && options["dry-run"] !== undefined) {
51
+ console.error(`--from-scratch${scratch === "chain" ? "-chain" : ""} deletes the code before anything is planned: it cannot be a dry run.`);
46
52
  process.exit(1);
47
53
  }
48
54
  runLoop({
@@ -54,8 +60,8 @@ runLoop({
54
60
  startOver: options["start-over"] !== undefined,
55
61
  ask: (loop) => again.length > 0
56
62
  ? loop.regenerateAgain(named, again)
57
- : options["from-scratch"] !== undefined
58
- ? loop.fromScratch(named)
63
+ : scratch !== undefined
64
+ ? loop.fromScratch(named, { chain: scratch === "chain" })
59
65
  : loop.bringUp(named),
60
66
  }).catch((error) => {
61
67
  console.error(error instanceof Error ? error.message : error);
@@ -142,7 +142,7 @@ export function createDeployTools(options) {
142
142
  },
143
143
  });
144
144
  // The one halt: with the pulses in the conversation, and without them for the release agent.
145
- const stopTool = haltTool(options.jobs !== undefined ? { jobs: options.jobs } : {});
145
+ const stopTool = haltTool(options.jobs !== undefined ? { jobs: options.jobs, ...(options.workLoop !== undefined ? { workLoop: options.workLoop } : {}) } : {});
146
146
  return [deploy, startTool, stopTool];
147
147
  }
148
148
  export const DEPLOY_TOOLS = ["release", "activate", "halt"];
@@ -79,7 +79,8 @@ export function createLiveReviewer(opts) {
79
79
  pending.push(finding);
80
80
  all.push(finding);
81
81
  }
82
- if (violations.length === 0) {
82
+ // No verdict - its turn stopped before it gave one - clears nothing: the scope is looked at again next pass.
83
+ if (captured !== undefined && violations.length === 0) {
83
84
  cleared.push(scope);
84
85
  }
85
86
  else if (captured?.question) {
@@ -22,6 +22,9 @@ const emptyTotals = () => ({
22
22
  llm_calls: 0,
23
23
  agent_turns: 0,
24
24
  compactions: 0,
25
+ provider_retries: 0,
26
+ provider_stalls: 0,
27
+ turns_stopped: 0,
25
28
  model_seconds: 0,
26
29
  });
27
30
  function addUsage(totals, usage) {
@@ -43,8 +46,14 @@ function addEvent(totals, event, tokens) {
43
46
  }
44
47
  else if (event.kind === "turn")
45
48
  totals.agent_turns += 1;
46
- else
49
+ else if (event.kind === "compaction")
47
50
  totals.compactions += 1;
51
+ else if (event.kind === "provider_retry")
52
+ totals.provider_retries += 1;
53
+ else if (event.kind === "provider_stall")
54
+ totals.provider_stalls += 1;
55
+ else
56
+ totals.turns_stopped += 1;
48
57
  }
49
58
  function sumTotals(a, b) {
50
59
  const sum = emptyTotals();
@@ -181,6 +190,32 @@ export function startRunReport(options) {
181
190
  list,
182
191
  };
183
192
  };
193
+ /** The spec gaps the pulses' agents met, in the order the pulses started: questions a person would want to decide. */
194
+ const specGapsOf = (jobs) => jobs.flatMap((job) => {
195
+ const details = job.details;
196
+ return (details?.specGaps ?? []).map((gap) => ({
197
+ module: job.module ?? null,
198
+ pulse: job.pulse ?? null,
199
+ pulse_id: job.id,
200
+ landed: job.status === "succeeded" && details?.landed === true,
201
+ question: gap.question,
202
+ assumption: gap.assumption,
203
+ }));
204
+ });
205
+ /** Each request the provider failed and was waited out or stalled on, and each turn turri ended itself: why, and where. */
206
+ const turnIncidentsOf = () => events
207
+ .filter((event) => event.kind === "provider_retry" || event.kind === "provider_stall" || event.kind === "stopped")
208
+ .map((event) => ({
209
+ kind: event.kind,
210
+ pulse_id: event.job ?? null,
211
+ role: event.role ?? null,
212
+ model: event.model ?? null,
213
+ ...(event.kind === "stopped"
214
+ ? { reason: event.reason ?? null }
215
+ : event.kind === "provider_stall"
216
+ ? { silent_seconds: Math.round((event.waitMs ?? 0) / 1000) }
217
+ : { error: event.error ?? null, attempt: event.attempt ?? null, of: event.of ?? null, wait_seconds: Math.round((event.waitMs ?? 0) / 100) / 10 }),
218
+ }));
184
219
  const functionalitiesOf = (counts) => {
185
220
  if (counts === undefined)
186
221
  return null;
@@ -228,6 +263,7 @@ export function startRunReport(options) {
228
263
  build_dir: options.buildDir !== undefined ? resolve(options.buildDir) : null,
229
264
  conformance_tests: options.conformanceTests,
230
265
  review: options.review ?? null,
266
+ mutation_testing: options.mutationTesting ?? null,
231
267
  models: {
232
268
  ...Object.fromEntries(Object.entries(options.models).map(([role, choice]) => [role, { model: choice.model ?? null, thinking: choice.thinking ?? null }])),
233
269
  observed: Object.fromEntries([...new Set(events.map((event) => event.role ?? "unknown"))].sort().map((role) => [role, [...new Set(events.filter((event) => (event.role ?? "unknown") === role).map((event) => event.model ?? "unknown"))].sort()])),
@@ -245,6 +281,8 @@ export function startRunReport(options) {
245
281
  usage: usageOf(jobs),
246
282
  pulses: pulsesOf(jobs, now),
247
283
  functionalities: functionalitiesOf(attempt(sources.completion)),
284
+ spec_gaps: specGapsOf(jobs),
285
+ turn_incidents: turnIncidentsOf(),
248
286
  ...(exitParts ?? {}),
249
287
  logs: {
250
288
  jobs_dir: fromProject(join(projectRoot, ".turri", "jobs")),
@@ -88,7 +88,8 @@ export function createSpecDiffTools(options) {
88
88
  owed = false;
89
89
  liveReview?.notice(`${params.plain_file}, after the change to ${touched.join(", ")}`);
90
90
  // In the files, the change is work: the loop works out what is left to build and plans it.
91
- const statuses = await loop.bringUp(params.plain_file, params.guidance !== undefined ? { guidance: params.guidance } : {});
91
+ // A spec change, not a request: a module the person halted stays halted.
92
+ const statuses = await loop.bringUp(params.plain_file, { specChange: true, ...(params.guidance !== undefined ? { guidance: params.guidance } : {}) });
92
93
  const lines = [
93
94
  result === "applied" ? `Applied the change to ${touched.join(", ")}.` : `The change to ${touched.join(", ")} was already applied.`,
94
95
  `Building in the background:\n${describeModules(statuses)}\n`,
@@ -158,13 +158,15 @@ an agent has to decide to go and read.
158
158
  | `import-modules.md`, `requires-modules.md` | the two ways modules build on each other |
159
159
  | `exported-concepts.md`, `required-concepts.md` | which concepts cross module boundaries |
160
160
  | `integrations.md` (+ standalone, embedded, embedded testing) | specs for REST API integrations, deployed standalone or embedded in an existing codebase |
161
+ | `turri-regeneration.md` | turri's model of itself: a spec change regenerated as a spec diff, wherever it sits, in the chain's tip; what each kind of change sets off; what a coding agent sees; how bad code is fixed; where the cost is - so a spec is placed by what it means, never to spare regeneration |
161
162
  | `stdlib.md` | the standard library: when to import which template, and every template with what it is and where it is, read from `stdlib/` |
162
163
 
163
164
  The ones that shape a spec most:
164
165
 
165
166
  - **One functionality is at most ~200 lines of code.** A bigger one is split before it is written
166
167
  (`analyze-if-func-spec-too-complex`, `break-down-func-spec`).
167
- - **Functional specs are in build order.** Each is rendered on top of the ones before it.
168
+ - **Functional specs are in build order.** Each is rendered on top of the ones before it - which is
169
+ what a spec may assume, not what a change costs: a spec inserted anywhere is regenerated alone.
168
170
  - **They state facts, with a concrete subject.** "A :User: can add a :Task:" - not "Implement
169
171
  adding tasks", not "The system should…".
170
172
  - **Nothing a test cannot check.** No `robust`, `seamless`, `as appropriate`; state the checkable
package/docs/config.md CHANGED
@@ -84,7 +84,7 @@ runs:
84
84
  | --- | --- |
85
85
  | now | `harness-model` and `models.chat` - the conversation switches to it; `parallel-jobs` - a pulse waiting for a slot starts if there is one now; `allow-to-stop-jobs` |
86
86
  | your next message | `rules-off` - for the conversation; a skill's agents from the next skill run |
87
- | the next pulse - one running keeps what it started with | `coding-model`, `judge-model`, every other `models.<role>`, `review`, `turn-limit`, `compact-at`, `agent-env`, `toolchains` |
87
+ | the next pulse - one running keeps what it started with | `coding-model`, `judge-model`, every other `models.<role>`, `review`, `mutation-testing`, `turn-limit`, `compact-at`, `agent-env`, `toolchains` |
88
88
  | the next time the work is planned | `conformance-tests`, `conformance-budget`, `max-specs-per-pulse`, `max-lines-per-pulse` |
89
89
  | the next test run - the running pulse's too | the testing scripts, `testing-scripts-run-on` |
90
90
  | the next pulse that lands - the running one too | `release-after-pulse` |
@@ -128,6 +128,7 @@ models: # each agent role's model, thinking and tur
128
128
  | `conformance-tests` | `all` (or `true`): conformance tests for every functional spec of every module with test reqs, written once each module's code is built, before anything is built on it. `chosen`: for the functional specs chosen - every one with acceptance tests, and those the chooser picks as each code pulse ends, from what that pulse regenerated. `module`: the same, but the chooser is asked once, when the whole module is regenerated, and plans the conformance pulses too. Under both, the choice is made inside the pulse, before anything is built on the module, and the pulse's report says what was chosen and why; those the person asks for with `conform` are written too; once chosen, a functional spec keeps them, and they are rewritten when it changes - see [who chooses, and when](regenerating.md#conformance-tests-in-the-work-loop). `false`: none written, and none of the existing ones run - until the conversation asks with `conform` | `false` |
129
129
  | `conformance-budget` | under `conformance-tests: chosen` or `module`: how many of a module's functional specs may be chosen for conformance tests, beside those with acceptance tests - a count (`2`) or a share of its functional specs (`30%`, rounded up, at least one). Every choice for the module counts, whenever it was made; the chooser is told what is left, and can choose no more. Your own `conform` is not limited. A stack's `config.turri.<stack>.yaml` can set its own | no limit |
130
130
  | `review` | `true` or `false`: whether the code and its unit tests - and the conformance tests - are reviewed once they pass: two reviews at most, the second weighed by the arbiter; off, a job lands once its tests pass - see [regenerating the code](regenerating.md#the-code-and-its-unit-tests-are-reviewed) | `false` |
131
+ | `mutation-testing` | `true` or `false`: whether the coding agent and the reviewer have `can_it_fail` - one change put in the code for one run of the unit testing script, to see that a test catches it; on a copy of the code, or in place and put back after the run (see [regenerating the code](regenerating.md#checking-its-own-work)). `turri regenerate --mutation-testing false` for one run | `true` |
131
132
  | `rules-off` | a list of rule names - `integrations`, `concise-specs`, the files of `genome/rules/` without `.md` - left out of the conversation's prompt and every spec-writing agent's: a rule this project's own skills or AGENTS.md replace, such as one that says to probe a live API before any spec is written. The project's alone | none |
132
133
  | `allow-to-stop-jobs` | `true` or `false`: whether turri stops a running job the spec has moved on from - a functional spec it regenerates changed, or a file one links was edited - rolls it back and regenerates the spec as it now is. `false`: the job runs to its end and lands, and what changed since is regenerated on top of it by the next job - see [regenerating the code](regenerating.md). Your own `halt` stops a job either way | `true` |
133
134
  | `release-after-pulse` | `true` or `false`: whether every pulse that lands code releases it, in the chat, as its last stage - before the module's next pulse starts, whatever the chat is doing: an agent on the coding model looks for the project's release guidance as the chat does (what was passed to `release` this conversation, AGENTS.md, the project's skills) and, when it says to release after a build, does what it says - see [deploy](deploy.md#after-every-pulse). One release a pulse that lands; a release that fails is said in the pulse's report, and what it landed stays | `false` |
@@ -142,7 +143,7 @@ models: # each agent role's model, thinking and tur
142
143
  | `toolchains` | folders of this machine an agent's commands may read beside the system's, the `PATH`'s and those the toolchain variables point at - a toolchain installed somewhere unusual (`[/srv/zig]`). A stack's add to the project's. See [the OS sandbox](sandbox.md#the-os-sandbox) | none |
143
144
  | `turn-limit` | seconds each turn of an agent a job starts has, for every role without its own (`models:`); `0` for none. The config is the only place it is set. A turn past it ends at its next request to the model - see [regenerating the code](regenerating.md) | 120 |
144
145
  | `models` | each agent role's own model, thinking and turn limit - see [models per role](#models-per-role) | every role on `coding-model`, the conversation's side on `harness-model` |
145
- | `testing-scripts-run-on` | what the testing scripts run on - always on this machine, in your environment. `in-place`: the real build and tests folders, the script at its own path, from the project - so a script that finds a host codebase from its own path finds it. `copy`: a fresh copy of the code, staged in `plain_modules/.turri/scripts/`, with the script copied beside it; it gives the coding agent `can_it_fail` (see [the testing scripts](regenerating.md#the-testing-scripts)) | `in-place` |
146
+ | `testing-scripts-run-on` | what the testing scripts run on - always on this machine, in your environment. `in-place`: the real build and tests folders, the script at its own path, from the project - so a script that finds a host codebase from its own path finds it. `copy`: a fresh copy of the code, staged in `plain_modules/.turri/scripts/`, with the script copied beside it. `can_it_fail` works on either: on a copy it changes the copy, in place the code itself for the one run, put back after it (see [the testing scripts](regenerating.md#the-testing-scripts)) | `in-place` |
146
147
 
147
148
  Keys are written with dashes; underscores are read the same (`conformance_tests`). A key turri
148
149
  does not know is ignored - another tool's `config.yaml`, read while it is the old file, may carry several - and so is a value of the
package/docs/headless.md CHANGED
@@ -86,7 +86,10 @@ Useful options - `turri regenerate --help` lists all of them:
86
86
  | `--judge-model <provider/id>` | `judge-model`: the judge and the test review; not given, the coding model |
87
87
  | `--conformance-tests <all\|chosen\|module\|false>` | `conformance-tests`, with its values (`true` is `all`) |
88
88
  | `--review <true\|false>` | `review`: whether the code and its tests are reviewed once they pass |
89
+ | `--mutation-testing <true\|false>` | `mutation-testing`: whether the coding agent and the reviewer have `can_it_fail` |
89
90
  | `--stack <name>` | build with the stack's `config.turri.<name>.yaml` over `config.turri.yaml`; default, `TURRI_STACK`, else none |
91
+ | `--from-scratch` | delete the module's code and conformance tests (its lineage keeps them) and regenerate all of it |
92
+ | `--from-scratch-chain` | the same for every module of its requires chain, the base's included, built again from the bottom |
90
93
  | `--start-over` | start over, unasked, a codebase built without a module it now requires - without a terminal, a run that needs it and lacks it stops |
91
94
  | `--build-dir <dir>` | as the run ends, export the code there - see below |
92
95
  | `--report <file.json>` | write [the run report](#the-run-report) there |
@@ -104,7 +107,8 @@ Conformance tests follow `conformance-tests:` in `config.turri.yaml`, or `--conf
104
107
  The command exits `0` only when every module is complete: its code regenerated from the spec as it is
105
108
  now, and its conformance tests written for what is built when they are on - no pulse failed, nothing
106
109
  halted, nothing waiting for a start over. Anything else exits `1`, and the last lines say which
107
- module is not complete, and why. The log says, per functionality, what was built and whether its
110
+ module is not complete, and why. A behaviour the spec leaves open that an agent had to decide is printed
111
+ as a `spec gap` under its pulse, with what was decided meanwhile. The log says, per functionality, what was built and whether its
108
112
  tests passed.
109
113
 
110
114
  | | |
@@ -150,6 +154,7 @@ changes meaning or goes; new fields may appear in the same version. Paths in `pu
150
154
  "spec_file": "/work/app.plain", "project_dir": "/work", "build_dir": "/work/out", // build_dir: null without one
151
155
  "conformance_tests": "all", // all | chosen | module | false
152
156
  "review": false,
157
+ "mutation_testing": true,
153
158
  "models": {
154
159
  "harness": { "model": "…", "thinking": "medium" }, // the planner, the chooser
155
160
  "coding": { "model": "…", "thinking": "low" },
@@ -165,7 +170,7 @@ changes meaning or goes; new fields may appear in the same version. Paths in `pu
165
170
  "usage": {
166
171
  "total": {
167
172
  "input_tokens": 0, "output_tokens": 0, "cache_read_tokens": 0, "cache_write_tokens": 0, "cost_usd": 0,
168
- "llm_calls": 0, "agent_turns": 0, "compactions": 0, "model_seconds": 0
173
+ "llm_calls": 0, "agent_turns": 0, "compactions": 0, "provider_retries": 0, "provider_stalls": 0, "turns_stopped": 0, "model_seconds": 0
169
174
  },
170
175
  "in_pulses": { }, // the pulses' usage added up - the same fields
171
176
  "outside_pulses": { }, // the planner, the conformance chooser, a failed pulse's diagnosis
@@ -191,6 +196,16 @@ changes meaning or goes; new fields may appear in the same version. Paths in `pu
191
196
  ],
192
197
  "codebases": ["plain_modules/app/code"]
193
198
  },
199
+ "spec_gaps": [{ // [] when no agent met one
200
+ "module": "app", "pulse": 3, "pulse_id": "2a058729", "landed": true,
201
+ "question": "What happens to a contact archived in HubSpot after it was synced?",
202
+ "assumption": "An archived contact is left as synced - asserted in sync.test.ts, archived contacts"
203
+ }],
204
+ "turn_incidents": [ // [] when none
205
+ { "kind": "provider_retry", "pulse_id": "2a058729", "role": "coding", "model": "…", "error": "…: 529 overloaded", "attempt": 1, "of": 6, "wait_seconds": 15.3 },
206
+ { "kind": "provider_stall", "pulse_id": "2a058729", "role": "coding", "model": "…", "silent_seconds": 120 },
207
+ { "kind": "stopped", "pulse_id": "5c1e0b2f", "role": "conformance explorer", "model": "…", "reason": "10 submit_exploration calls failed in a row" }
208
+ ],
194
209
  "build_dir_export": { "exported": true, "dir": "/work/out", "module": "app", "commit": "8036b3b", "files": 23 },
195
210
  "logs": { "jobs_dir": ".turri/jobs", "debug_dir": ".turri/debug", "sessions_dir": ".turri/sessions" }
196
211
  }
@@ -209,6 +224,21 @@ calls; a role or model turri could not tell is `unknown`.
209
224
  stopped, or did not pass - and everything it wrote was undone. A pulse that failed is tried once more
210
225
  before it counts as failed; both tries are the one pulse.
211
226
 
227
+ **Spec gaps.** A behaviour the spec leaves open that an agent met and decided on its own - reported with
228
+ `report_spec_gap` (see [regenerating](regenerating.md)). In the chat they are put to you as the pulse ends; a
229
+ headless run has no one to ask, so they are listed here, in the order the pulses started, and printed under the
230
+ pulse that met them. `assumption` is what the agent decided meanwhile, also in the codebase's notes'
231
+ assumptions while its pulse is `landed`; a pulse rolled back takes it out of the notes, but the question still
232
+ stands. Settle the ones you care about in the spec and run again.
233
+
234
+ **Turn incidents.** Each time the model provider failed for a moment and pi or turri waited it out before trying
235
+ the request again, each time the provider sent nothing back on a request for two minutes, and each turn turri
236
+ stopped itself - an agent going round in a circle, its calls failing again and again, its time up - after which the
237
+ run carried on. The provider failing or stalling is printed as it happens, in yellow, under the pulse; a stop is
238
+ the work's normal course and is only listed. They are counted in the usage as `provider_retries`,
239
+ `provider_stalls` and `turns_stopped`. Many of any point at the model, not the spec: a provider at its limits, or a
240
+ model too small for the role it was given.
241
+
212
242
  **Completed functional specs** - the pass rate, the figure to compare runs by.
213
243
  A functional spec is completed when the code record of the codebase the run delivers - the
214
244
  furthest-built of the chain, the one `--build-dir` exports - as last committed, holds it as the spec has
@@ -227,7 +257,7 @@ and modules that are complete are skipped, so it picks up where it stopped - aft
227
257
  provider outage, or a machine that went to sleep anyway. Whatever the stopped run left
228
258
  half-written is undone first: each step starts from the module's last commit. A functionality whose spec has changed
229
259
  since counts as not built, so editing the spec and re-running rebuilds what changed. `--from-scratch`
230
- rebuilds everything.
260
+ rebuilds the module; `--from-scratch-chain` rebuilds every module of its chain.
231
261
 
232
262
  ## Rebuilding one functionality
233
263
 
@@ -40,6 +40,9 @@ on npm runs JavaScript compiled from them instead (`npm run build`, into `dist/`
40
40
  before they pack), as Node runs no `.ts` file inside a `node_modules`. `bin/turri.mjs` runs `src/` where there is one,
41
41
  and `dist/` otherwise.
42
42
 
43
+ To update, `git pull` and `npm install` - the second picks up a dependency that changed, pi's say. `npm link` needs
44
+ running only once. A **turri** already running keeps the code it started with: start it again to run what you pulled.
45
+
43
46
  ## In Docker
44
47
 
45
48
  `docker/Dockerfile` builds an image with Node, git, bash, bubblewrap and **turri** linked; the agents' commands and the
@@ -123,7 +123,22 @@ An agent that goes round in a circle - the same tool called with the same argume
123
123
  nothing in between, or a look (read, grep, find, ls) made again with nothing changed since, however
124
124
  many other looks came between, so the same answer comes back - is let through three times; the next
125
125
  such call is refused with what is happening, and past six its turn is stopped, and the harness goes on
126
- from there as after any turn. The arguments are compared whatever order they come in.
126
+ from there as after any turn. The arguments are compared whatever order they come in. So too an agent whose
127
+ calls to one tool fail ten times in a row, nothing going through - a call its arguments do not fit never reaches
128
+ any guard on the tools.
129
+
130
+ A turn turri stops itself - for any of these, or for its time, below - ends as any turn ends: what the agent said
131
+ stands, `[the turn was stopped: ...]` after it, and the caller does what it does when the agent handed nothing over
132
+ (the explorer's fallback, a nudge, a failed round). The abort that ended it is never taken for the provider
133
+ failing; an abort turri did not make still is. A stop is the work's normal course: it is in the pulse's activity
134
+ and log and the run report's `turn_incidents`, but not said in the chat or a headless run's console - those say
135
+ only the model provider failing or stalling.
136
+
137
+ A tool argument that is a list of objects - the explorer's `interfaces` and `plan`, a reviewer's `problems` - is
138
+ what small models get wrong most. Before a call's arguments are checked, a list sent as JSON text, entries sent as
139
+ JSON text, one object for the list, or a list written inside another argument's text
140
+ (`...</tests_reach_it><plan>[...]</plan>`) are taken as the list; what still is not one is refused saying which
141
+ argument, what was sent, each entry's fields and an example (`list-arguments.ts`).
127
142
 
128
143
  The agents with one thing to decide have a budget of tool calls: the judge 30, the test review and the
129
144
  explorer 40. Past it every tool but the one that hands the decision over refuses, telling it to decide
@@ -245,12 +260,18 @@ use each:
245
260
  - **`my_diff`**: the diff of the code folder from the commit the job started from, new files whole - exactly
246
261
  what the reviewer is shown. Read before handing the work in: every part of the change in it, and nothing else.
247
262
  - **`can_it_fail`**: whether the unit tests catch a bug. The agent gives one change to a code file - a
248
- condition turned round, a value changed - and the unit testing script runs on a fresh copy of the code with
249
- it; the code itself is never touched. If every test still passes, no test catches that bug. Six
263
+ condition turned round, a value changed - and the unit testing script runs with it. Where the testing scripts
264
+ run on a copy (`testing-scripts-run-on: copy`), the change is made to a fresh copy and the code itself is never
265
+ touched. In place, the default, it is made to the code itself, so a script that finds the code from its own path
266
+ sees it; the file is put back as it was once the run ends - passed, failed, hung, the script failing to start, the
267
+ script rewriting the file, turri exiting. Killed outright, the next unit of work starts from the last commit anyway.
268
+ It never runs beside another call of the agent's, so no edit lands while the bug is in. What the script does
269
+ beyond the code - a package copied into a host codebase - it does with the bug in, until the next test run puts the
270
+ real code there. If every test still passes, no test catches that bug. Six
250
271
  runs a job. A bug often makes the code hang instead - a loop that never ends - so a run may take three times
251
272
  as long as the last passing run of the unit tests, within 15 and 60 seconds, and one that does not finish is
252
- reported as a hang, not as a test that caught it. Only where the testing scripts run on a copy
253
- (`testing-scripts-run-on: copy`): in place, the default, there is no copy to change.
273
+ reported as a hang, not as a test that caught it. `mutation-testing: false` in the [config](config.md) - or
274
+ `turri regenerate --mutation-testing false` - takes it away, from the reviewer too.
254
275
  - **`start_service`**, **`service_logs`**, **`stop_service`**: a server or a worker it built, started in the
255
276
  background on this machine, behind the same walls as its shell - the command check, the module's environment, the
256
277
  OS sandbox, the audit while it comes up - to try from outside with `curl` as a client would. Whatever the stack: the
@@ -380,6 +401,18 @@ halts its codebase: nothing more runs there until the spec changes or the module
380
401
  the command line, `turri regenerate` runs until nothing more can start, one line as each job starts and
381
402
  ends, and exits 1 when any failed.
382
403
 
404
+ The person halts a module's planned work too: `halt` (and `/halt`) given a planned row - `planned-<module>-2`,
405
+ `planned-<module>-waiting` - or the module's name. A module's pulses are planned again from its spec at every look, so
406
+ one planned pulse cannot be taken out alone: the module is halted - its running pulse stopped and rolled back, none of
407
+ its planned pulses started, the modules built on it waiting for it - and what landed stays. A halt the person asked for
408
+ holds through spec changes - `write_spec_diff` brings the spec in without starting the module - until the module is
409
+ asked for again (`regenerate`, `conform`). To build some of it later, or cut it differently, there is `steer`; to drop
410
+ work, the spec.
411
+
412
+ A module the loop looked after whose `.plain` file is gone is forgotten - no rows, nothing waited for - and a codebase
413
+ left behind, or whose spec no longer parses, shows nothing planned: its plan, and what it waited for, were the spec's
414
+ before.
415
+
383
416
  ### How the work is cut into jobs
384
417
 
385
418
  A job that renders the whole of a new spec is too big to build well, and a render per functional spec,
@@ -549,7 +582,8 @@ does not find them:
549
582
  testing-scripts-run-on: copy
550
583
  ```
551
584
 
552
- `can_it_fail` needs a copy to change, so an agent has it only where the scripts run on one.
585
+ `can_it_fail` works either way: on a copy it changes the copy; in place it changes the code for the one run and puts
586
+ it back.
553
587
 
554
588
  ### When the environment lacks something
555
589
 
@@ -706,7 +740,7 @@ with no agent and no testing script. Moving specs into a module the code was not
706
740
  change to the code brings that module's code in, so the codebase stops: it has to be started over - its code
707
741
  and conformance tests taken out, committed so its history keeps them, and the chain built again from the
708
742
  bottom. That is never done unasked. In the chat the model asks the person, saying why, and calls
709
- `regenerate` with `from_scratch` once they agree; `turri regenerate` and `spec-diff` ask at the terminal, and
743
+ `regenerate` with `from_scratch: "module"` once they agree; `turri regenerate` and `spec-diff` ask at the terminal, and
710
744
  `--start-over` agrees in advance - with no terminal and no flag, the run stops there, exit 1, saying so.
711
745
 
712
746
  ## Conformance tests
@@ -1099,7 +1133,9 @@ are the next agent's, and a gap is yours. An agent reports one with `report_spec
1099
1133
  and the assumption it made meanwhile; turri writes that assumption into the notes' assumptions, so the code built on
1100
1134
  it is known for what it is. The gaps a pulse's agents report are said in its report - "Spec gaps its agents met ... Put
1101
1135
  each to the user", each with its assumption - so the conversation asks you, and writes the ones you decide into the
1102
- spec; the pulse that builds the answer finds the assumption it replaces in the notes, and the tests it names. However many gaps a pulse's agents report, they
1136
+ spec; the pulse that builds the answer finds the assumption it replaces in the notes, and the tests it names.
1137
+ A headless run has no one to ask: it prints each gap under its pulse, and lists them in its run report's
1138
+ `spec_gaps` ([running unattended](headless.md#the-run-report)). However many gaps a pulse's agents report, they
1103
1139
  are put to you - never a reason to stop the pulse; the tool is guarded like any other. A notes
1104
1140
  file from before keeps no spec gaps section: its lines are dropped as it is read.
1105
1141
 
@@ -133,7 +133,9 @@ change the step makes and puts its findings on the executor's next tool result.
133
133
  - **Interview the user.** `ask_user` puts one question to the person. In the TUI it is a dialog;
134
134
  from the CLI the options are numbered. Offering choices is required, not optional - a call with
135
135
  neither `options` nor `free_form: true` is refused - and every list carries "Something else…".
136
- `multi_select: true` keeps offering what is left until they are done. The skill's agent talks in a
136
+ `multi_select: true` gives every option a box, ticked and unticked as it is chosen - a pick made by mistake is
137
+ undone by choosing it again - until they choose Done; what they type is one more box, ticked. "Something
138
+ else…", "Chat about this" and Done are no boxes. The skill's agent talks in a
137
139
  session of its own that the person never sees, so what the person must read to answer - the brief
138
140
  to confirm, the plan to approve - it passes as `ask_user`'s `context`, shown above the question in
139
141
  the dialog; `brood`, `spawn` and `bud` pass their briefs so. The agents are told to keep it to what can be taken in at