@turri-dev/cli 0.1.4-next.318a98a → 0.1.4-next.5a8c6e5
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.
- package/.pi/themes/turri-dark.json +67 -66
- package/.pi/themes/turri-light.json +71 -73
- package/README.md +40 -128
- package/assets/jellyfish/dark-00.png +0 -0
- package/assets/jellyfish/dark-01.png +0 -0
- package/assets/jellyfish/dark-02.png +0 -0
- package/assets/jellyfish/dark-03.png +0 -0
- package/assets/jellyfish/dark-04.png +0 -0
- package/assets/jellyfish/dark-05.png +0 -0
- package/assets/jellyfish/dark-06.png +0 -0
- package/assets/jellyfish/dark-07.png +0 -0
- package/assets/jellyfish/dark-08.png +0 -0
- package/assets/jellyfish/dark-09.png +0 -0
- package/assets/jellyfish/dark-10.png +0 -0
- package/assets/jellyfish/dark-11.png +0 -0
- package/assets/jellyfish/light-00.png +0 -0
- package/assets/jellyfish/light-01.png +0 -0
- package/assets/jellyfish/light-02.png +0 -0
- package/assets/jellyfish/light-03.png +0 -0
- package/assets/jellyfish/light-04.png +0 -0
- package/assets/jellyfish/light-05.png +0 -0
- package/assets/jellyfish/light-06.png +0 -0
- package/assets/jellyfish/light-07.png +0 -0
- package/assets/jellyfish/light-08.png +0 -0
- package/assets/jellyfish/light-09.png +0 -0
- package/assets/jellyfish/light-10.png +0 -0
- package/assets/jellyfish/light-11.png +0 -0
- package/dist/ask.js +34 -15
- package/dist/brand.js +7 -7
- package/dist/cli-options.js +12 -6
- package/dist/config-edit.js +1 -0
- package/dist/config.js +5 -2
- package/dist/cultivate-cli.js +16 -23
- package/dist/extension.js +59 -67
- package/dist/init-config.js +5 -0
- package/dist/jellyfish.js +130 -0
- package/dist/loop-cli.js +19 -7
- package/dist/loop-tools.js +11 -5
- package/dist/module-report.js +5 -4
- package/dist/pi.js +76 -19
- package/dist/question-dialog.js +1 -0
- package/dist/regenerate/activity.js +21 -0
- package/dist/regenerate/list-arguments.js +121 -0
- package/dist/regenerate/loop.js +21 -8
- package/dist/regenerate/plain-palette.js +52 -37
- package/dist/regenerate/regenerate.js +4 -2
- package/dist/regenerate/self-check.js +13 -6
- package/dist/regenerate/side-panel.js +1 -1
- package/dist/regenerate/spec-map-view.js +9 -5
- package/dist/regenerate/test-scripts.js +54 -10
- package/dist/regenerate/unit-review.js +1 -1
- package/dist/regenerate-cli.js +11 -5
- package/dist/release-cli.js +3 -8
- package/dist/review/live.js +2 -1
- package/dist/run-report.js +39 -1
- package/dist/validate-cli.js +3 -8
- package/docs/README.md +5 -12
- package/docs/authoring-plain.md +37 -119
- package/docs/config.md +53 -178
- package/docs/deploy.md +21 -80
- package/docs/development.md +13 -41
- package/docs/headless.md +45 -121
- package/docs/images/how-turri-works.svg +29 -31
- package/docs/images/turri-banner.png +0 -0
- package/docs/installation.md +13 -40
- package/docs/parser.md +15 -43
- package/docs/regenerating.md +229 -938
- package/docs/sandbox.md +38 -152
- package/docs/skills-and-gates.md +50 -171
- package/docs/theming.md +45 -46
- package/docs/using.md +69 -345
- package/genome/rules/bullet-continuation.md +5 -13
- package/genome/rules/concise-specs-examples.md +2 -4
- package/genome/rules/concise-specs-integration-examples.md +2 -6
- package/genome/rules/concise-specs.md +1 -2
- package/genome/rules/func-specs.md +1 -0
- package/genome/rules/integration-embedded-testing.md +1 -4
- package/genome/rules/integrations.md +1 -2
- package/genome/rules/project-model.md +14 -35
- package/genome/rules/stdlib.md +14 -49
- package/genome/rules/turri-regeneration.md +48 -0
- package/genome/skills/add-implementation-requirement/SKILL.md +1 -2
- package/genome/skills/analyze-if-func-spec-too-complex/SKILL.md +3 -8
- package/genome/skills/brood/SKILL.md +37 -127
- package/genome/skills/brood/references/intent.md +4 -12
- package/genome/skills/brood/references/product.md +24 -76
- package/genome/skills/brood/references/stack.md +7 -29
- package/genome/skills/brood/references/testing.md +11 -42
- package/genome/skills/bud/SKILL.md +32 -109
- package/genome/skills/bud/references/intent.md +4 -11
- package/genome/skills/implement-conformance-testing-script/SKILL.md +3 -6
- package/genome/skills/implement-unit-testing-script/SKILL.md +1 -2
- package/genome/skills/mature/SKILL.md +21 -69
- package/genome/skills/refactor-module/SKILL.md +24 -2
- package/genome/skills/spawn/SKILL.md +28 -113
- package/package.json +1 -1
- package/assets/jellyfish/dark-12.png +0 -0
- package/assets/jellyfish/dark-13.png +0 -0
- package/assets/jellyfish/dark-14.png +0 -0
- package/assets/jellyfish/fallback.txt +0 -252
- package/assets/jellyfish/light-12.png +0 -0
- package/assets/jellyfish/light-13.png +0 -0
- package/assets/jellyfish/light-14.png +0 -0
package/dist/init-config.js
CHANGED
|
@@ -110,6 +110,7 @@ export function withModels(text, lines) {
|
|
|
110
110
|
export const DEFAULTS = {
|
|
111
111
|
conformanceTests: false,
|
|
112
112
|
review: false,
|
|
113
|
+
mutationTesting: true,
|
|
113
114
|
allowToStopJobs: true,
|
|
114
115
|
releaseAfterPulse: false,
|
|
115
116
|
testingScriptsRunOn: "in-place",
|
|
@@ -143,6 +144,10 @@ export function quickStartConfig(vendor = "other", bedrock) {
|
|
|
143
144
|
"# Whether the code and its tests are reviewed once they pass - two reviews at most, the second weighed by the arbiter.",
|
|
144
145
|
`review: ${DEFAULTS.review}`,
|
|
145
146
|
"",
|
|
147
|
+
"# Whether the coding agent and the reviewer can put a bug in the code for one run of the unit tests (can_it_fail),",
|
|
148
|
+
"# to see that a test catches it - on a copy of the code, or in place and put back after.",
|
|
149
|
+
`mutation-testing: ${DEFAULTS.mutationTesting}`,
|
|
150
|
+
"",
|
|
146
151
|
"# Whether turri stops a running pulse the spec has moved on from. false: it lands, the change regenerated on top.",
|
|
147
152
|
`allow-to-stop-jobs: ${DEFAULTS.allowToStopJobs}`,
|
|
148
153
|
"",
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { sgr } from "./regenerate/plain-palette.js";
|
|
2
|
+
/** The pixels' colours on a dark background and a light one - the tentacles darker on light, where neon does not show. */
|
|
3
|
+
export const JELLYFISH_COLOURS = {
|
|
4
|
+
dark: { p: "#ff5c8d", h: "#ff7fa6", w: "#f4f7f9", o: "#ff7a3d", e: "#732553", N: "#8eebee", n: "#5ce1e6", l: "#85a3b2", g: "#3e5a6b" },
|
|
5
|
+
light: { p: "#ff5c8d", h: "#ff7fa6", w: "#f4f7f9", o: "#ff7a3d", e: "#732553", N: "#3e5a6b", n: "#1e3442", l: "#85a3b2", g: "#85a3b2" },
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* How shut the bell is, frame by frame - a quarter second each: shut quickly, held a moment, opened slowly, at rest
|
|
9
|
+
* until the next stroke.
|
|
10
|
+
*/
|
|
11
|
+
const SHUT = [0.1, 0.55, 0.9, 1, 0.85, 0.7, 0.56, 0.44, 0.33, 0.23, 0.14, 0.06];
|
|
12
|
+
const LARGE = {
|
|
13
|
+
width: 24,
|
|
14
|
+
height: 26,
|
|
15
|
+
open: [6, 12, 16, 18, 20, 22, 22, 24, 24],
|
|
16
|
+
shut: [6, 10, 14, 16, 18, 18, 18, 20, 20],
|
|
17
|
+
glint: [[-3, 2], [-4, 2], [-5, 3], [-6, 4], [-6, 5]],
|
|
18
|
+
shine: [-2, 2],
|
|
19
|
+
gut: [".oo..oo.", "oooooooo", "oooooooo", ".oo..oo."],
|
|
20
|
+
gutRow: 4,
|
|
21
|
+
strands: [
|
|
22
|
+
{ at: -8, length: 10, sway: 1.1, ink: "N" },
|
|
23
|
+
{ at: -4.5, length: 13, sway: 1.3, ink: "N" },
|
|
24
|
+
{ at: -1, length: 14, sway: 0.8, ink: "n" },
|
|
25
|
+
{ at: 2, length: 13, sway: 0.8, ink: "n" },
|
|
26
|
+
{ at: 5.5, length: 13, sway: 1.3, ink: "N" },
|
|
27
|
+
{ at: 9, length: 10, sway: 1.1, ink: "N" },
|
|
28
|
+
],
|
|
29
|
+
};
|
|
30
|
+
const SMALL = {
|
|
31
|
+
width: 18,
|
|
32
|
+
height: 20,
|
|
33
|
+
open: [4, 10, 12, 14, 16, 18, 18],
|
|
34
|
+
shut: [4, 8, 10, 12, 14, 14, 14],
|
|
35
|
+
glint: [[-2, 1], [-3, 2], [-4, 3]],
|
|
36
|
+
shine: [-1, 1],
|
|
37
|
+
gut: ["oo..oo", "oooooo", "oo..oo"],
|
|
38
|
+
gutRow: 3,
|
|
39
|
+
strands: [
|
|
40
|
+
{ at: -6, length: 8, sway: 0.9, ink: "N" },
|
|
41
|
+
{ at: -3, length: 10, sway: 1, ink: "N" },
|
|
42
|
+
{ at: -0.5, length: 11, sway: 0.7, ink: "n" },
|
|
43
|
+
{ at: 1.5, length: 10, sway: 0.7, ink: "n" },
|
|
44
|
+
{ at: 4, length: 10, sway: 1, ink: "N" },
|
|
45
|
+
{ at: 7, length: 8, sway: 0.9, ink: "N" },
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
/** One frame of a design: its height in rows of its width in pixels, "." where there is none. */
|
|
49
|
+
function frame(design, t) {
|
|
50
|
+
const grid = Array.from({ length: design.height }, () => Array(design.width).fill("."));
|
|
51
|
+
const centre = design.width / 2;
|
|
52
|
+
const set = (y, x, pixel, over = true) => {
|
|
53
|
+
if (y < 0 || y >= design.height || x < 0 || x >= design.width)
|
|
54
|
+
return;
|
|
55
|
+
if (over || grid[y][x] === ".")
|
|
56
|
+
grid[y][x] = pixel;
|
|
57
|
+
};
|
|
58
|
+
const shut = SHUT[t % SHUT.length];
|
|
59
|
+
// Shut, it has risen a pixel.
|
|
60
|
+
const top = shut > 0.6 ? 0 : 1;
|
|
61
|
+
const widths = design.open.map((open, row) => 2 * Math.round((open - (open - design.shut[row]) * shut) / 2));
|
|
62
|
+
widths.forEach((width, row) => {
|
|
63
|
+
for (let x = centre - width / 2; x < centre + width / 2; x++)
|
|
64
|
+
set(top + row, x, "p");
|
|
65
|
+
});
|
|
66
|
+
const rimWidth = widths.at(-1);
|
|
67
|
+
const rim = top + widths.length;
|
|
68
|
+
// The underside along the bottom row, the rim scalloped under it.
|
|
69
|
+
for (let x = centre - rimWidth / 2 + 2; x < centre + rimWidth / 2 - 2; x++)
|
|
70
|
+
set(rim - 1, x, "e");
|
|
71
|
+
for (let x = centre - rimWidth / 2; x < centre + rimWidth / 2; x += 2)
|
|
72
|
+
set(rim, x + 1, "p");
|
|
73
|
+
// A glint up on the left, curving with the dome, and a pixel of shine.
|
|
74
|
+
for (const [dx, dy] of design.glint)
|
|
75
|
+
set(top + dy, centre + dx, "h");
|
|
76
|
+
set(top + design.shine[1], centre + design.shine[0], "w");
|
|
77
|
+
const gutLeft = centre - Math.floor(design.gut[0].length / 2);
|
|
78
|
+
design.gut.forEach((line, dy) => [...line].forEach((pixel, dx) => pixel === "o" && set(top + design.gutRow + dy, gutLeft + dx, "o")));
|
|
79
|
+
// The tentacles: rooted under the bell, drawn in as it shuts, swaying - the further down, the later.
|
|
80
|
+
const phase = (2 * Math.PI * t) / SHUT.length;
|
|
81
|
+
design.strands.forEach((strand, i) => {
|
|
82
|
+
const root = centre - 0.5 + strand.at * (rimWidth / design.open.at(-1));
|
|
83
|
+
for (let y = 0; y < strand.length; y++) {
|
|
84
|
+
const x = Math.round(root + strand.sway * Math.sin(phase - y * 0.55 + i * 0.8) * Math.min(1, y / 3));
|
|
85
|
+
const left = strand.length - y;
|
|
86
|
+
// The tips come apart, every other pixel, fading - into code.
|
|
87
|
+
if (left <= 3 && y % 2 === 1)
|
|
88
|
+
continue;
|
|
89
|
+
set(rim + 1 + y, x, left > 5 ? strand.ink : left > 2 ? "l" : "g", false);
|
|
90
|
+
// The oral arms are frilled.
|
|
91
|
+
if (strand.ink === "n" && left > 5 && (y + t) % 3 === 0)
|
|
92
|
+
set(rim + 1 + y, x + (strand.at < 0 ? -1 : 1), "n", false);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
return grid.map((row) => row.join(""));
|
|
96
|
+
}
|
|
97
|
+
export const JELLYFISH_WIDTH = LARGE.width;
|
|
98
|
+
export const JELLYFISH_HEIGHT = LARGE.height;
|
|
99
|
+
/** The large jellyfish's frames, a stroke: what the pictures are rendered from. */
|
|
100
|
+
export const JELLYFISH_FRAMES = SHUT.map((_, t) => frame(LARGE, t));
|
|
101
|
+
/** The small jellyfish's frames, a stroke: what a terminal without images draws, in half blocks. */
|
|
102
|
+
export const JELLYFISH_TEXT_FRAMES = SHUT.map((_, t) => frame(SMALL, t));
|
|
103
|
+
/** How long each frame shows. */
|
|
104
|
+
export const JELLYFISH_FRAME_MS = 250;
|
|
105
|
+
/**
|
|
106
|
+
* A frame drawn in half blocks for a terminal that shows no images: two pixels a cell, the upper one the text's colour
|
|
107
|
+
* and the lower one the background's, in as many colours as the terminal has: a column a pixel, a row every two.
|
|
108
|
+
*/
|
|
109
|
+
export function halfBlocks(pixels, appearance, truecolor) {
|
|
110
|
+
const colours = JELLYFISH_COLOURS[appearance];
|
|
111
|
+
const colour = (pixel) => (pixel === undefined || pixel === "." ? undefined : colours[pixel]);
|
|
112
|
+
const rows = [];
|
|
113
|
+
for (let y = 0; y < pixels.length; y += 2) {
|
|
114
|
+
let row = "";
|
|
115
|
+
for (let x = 0; x < (pixels[0]?.length ?? 0); x++) {
|
|
116
|
+
const upper = colour(pixels[y]?.[x]);
|
|
117
|
+
const lower = colour(pixels[y + 1]?.[x]);
|
|
118
|
+
if (upper === undefined && lower === undefined)
|
|
119
|
+
row += " ";
|
|
120
|
+
else if (upper === undefined)
|
|
121
|
+
row += `\x1b[${sgr(lower, false, truecolor)}m▄\x1b[39m`;
|
|
122
|
+
else if (lower === undefined)
|
|
123
|
+
row += `\x1b[${sgr(upper, false, truecolor)}m▀\x1b[39m`;
|
|
124
|
+
else
|
|
125
|
+
row += `\x1b[${sgr(upper, false, truecolor)};${sgr(lower, true, truecolor)}m▀\x1b[39;49m`;
|
|
126
|
+
}
|
|
127
|
+
rows.push(row);
|
|
128
|
+
}
|
|
129
|
+
return rows;
|
|
130
|
+
}
|
package/dist/loop-cli.js
CHANGED
|
@@ -4,6 +4,7 @@ import { resolve, sep } from "node:path";
|
|
|
4
4
|
import { configForSpec, inheritModel, modelOnly, modelSpec, projectModels, readProjectConfig, roleModel, ROLE_THINKING, splitModelSpec, } from "./config.js";
|
|
5
5
|
import { PACKAGE_ROOT } from "./environment.js";
|
|
6
6
|
import { c } from "./module-report.js";
|
|
7
|
+
import { describeTurnIncident, onModelEvent } from "./regenerate/activity.js";
|
|
7
8
|
import { tryItCommand } from "./regenerate/delivery.js";
|
|
8
9
|
import { describeDiagnosis, diagnoseFailure } from "./regenerate/diagnose.js";
|
|
9
10
|
import { createJobRegistry, pulseName } from "./regenerate/jobs.js";
|
|
@@ -51,6 +52,7 @@ export async function runLoop(options) {
|
|
|
51
52
|
...(buildDir !== undefined ? { buildDir } : {}),
|
|
52
53
|
conformanceTests: conformanceLabel(project.conformanceTests),
|
|
53
54
|
review: project.review === true,
|
|
55
|
+
mutationTesting: project.mutationTesting !== false,
|
|
54
56
|
models: reportModels(project, model),
|
|
55
57
|
})
|
|
56
58
|
: undefined;
|
|
@@ -78,16 +80,26 @@ async function runLoopReporting(options) {
|
|
|
78
80
|
return;
|
|
79
81
|
seen.set(job.id, line);
|
|
80
82
|
if (job.status === "running")
|
|
81
|
-
console.log(`${c.
|
|
83
|
+
console.log(`${c.accent(`▶ ${job.id}`)} ${pulseName(job)}${job.stage !== undefined ? c.dim(` - ${job.stage}`) : ""}`);
|
|
82
84
|
},
|
|
83
85
|
onFinish: (job) => {
|
|
84
|
-
const mark = job.status === "succeeded" ? c.
|
|
86
|
+
const mark = job.status === "succeeded" ? c.success("✓") : job.status === "stopped" ? c.dim("■") : c.error("✗");
|
|
85
87
|
console.log(`${mark} ${job.id} ${pulseName(job)} - ${job.status}`);
|
|
86
88
|
if (job.status !== "succeeded")
|
|
87
89
|
console.log(c.dim((job.announce ?? job.report ?? job.error ?? "").trim()));
|
|
90
|
+
// Its report is not printed when it succeeds, and nobody is asked here: the spec gaps its agents met are said.
|
|
91
|
+
else
|
|
92
|
+
for (const gap of job.details?.specGaps ?? [])
|
|
93
|
+
console.log(c.warning(` spec gap: ${gap.question}`), c.dim(`Meanwhile: ${gap.assumption}`));
|
|
88
94
|
report?.write();
|
|
89
95
|
},
|
|
90
96
|
});
|
|
97
|
+
// A provider failing and waited out, a turn turri ended itself: said as they happen, not left in the job logs alone.
|
|
98
|
+
onModelEvent((event) => {
|
|
99
|
+
const line = describeTurnIncident(event);
|
|
100
|
+
if (line !== undefined)
|
|
101
|
+
console.log(c.warning(` ${event.job !== undefined ? `${event.job}: ` : ""}${line}`));
|
|
102
|
+
});
|
|
91
103
|
const planner = modelSpec(projectModels(project).harness);
|
|
92
104
|
const loop = createWorkLoop({
|
|
93
105
|
registry,
|
|
@@ -119,7 +131,7 @@ async function runLoopReporting(options) {
|
|
|
119
131
|
// No terminal and no --start-over: no one to ask, so the run stops here rather than build nothing and say it is done.
|
|
120
132
|
if (options.startOver !== true && process.stdin.isTTY !== true) {
|
|
121
133
|
const message = `${why}\nThere is no terminal to ask whether to start over: run it again with --start-over to start over without asking.`;
|
|
122
|
-
console.error(c.
|
|
134
|
+
console.error(c.error(message));
|
|
123
135
|
report?.end("incomplete", message);
|
|
124
136
|
process.exit(1);
|
|
125
137
|
}
|
|
@@ -150,10 +162,10 @@ async function runLoopReporting(options) {
|
|
|
150
162
|
// waiting for a start over, nothing the planner left out.
|
|
151
163
|
const unfinished = moduleStates(loop.drift(plainFile)).filter((module) => module.state !== "complete");
|
|
152
164
|
const verdict = failed.length > 0
|
|
153
|
-
? c.
|
|
165
|
+
? c.error(c.bold(`${failed.length} job${failed.length === 1 ? "" : "s"} failed`))
|
|
154
166
|
: unfinished.length > 0
|
|
155
|
-
? c.
|
|
156
|
-
: c.
|
|
167
|
+
? c.error(c.bold(`not complete: ${unfinished.map((module) => `${module.module}${module.why !== undefined ? ` - ${module.why}` : ""}`).join("; ")}`))
|
|
168
|
+
: c.success(c.bold("all jobs done"));
|
|
157
169
|
console.log(`\n${verdict}`);
|
|
158
170
|
for (const job of [...ended].reverse())
|
|
159
171
|
console.log(` ${job.id} ${pulseName(job)}: ${job.status}`);
|
|
@@ -236,7 +248,7 @@ function reportModels(project, model) {
|
|
|
236
248
|
}
|
|
237
249
|
/**
|
|
238
250
|
* The options every command that regenerates takes for a headless run: `--report` and `--build-dir`, and the config's
|
|
239
|
-
* own keys (configKeyOptions) - `--harness-model`, `--coding-model` (`--model`), `--judge-model`, `--review` and, where
|
|
251
|
+
* own keys (configKeyOptions) - `--harness-model`, `--coding-model` (`--model`), `--judge-model`, `--review`, `--mutation-testing` and, where
|
|
240
252
|
* `conformance` is true, `--conformance-tests` - read as if config.turri.yaml had them. Exits on a value it cannot read.
|
|
241
253
|
*/
|
|
242
254
|
export function headlessOptions(options, conformance) {
|
package/dist/loop-tools.js
CHANGED
|
@@ -110,6 +110,10 @@ function plainFileOf(cwd, given, what) {
|
|
|
110
110
|
export function asksFromScratch(words) {
|
|
111
111
|
return FROM_SCRATCH.test(words);
|
|
112
112
|
}
|
|
113
|
+
/** Whether a /regenerate asking for its module from scratch asks for its whole requires chain with it. */
|
|
114
|
+
export function asksWholeChain(words) {
|
|
115
|
+
return /\bchain\b|\bevery module\b|\ball (the )?modules\b/i.test(words);
|
|
116
|
+
}
|
|
113
117
|
const FROM_SCRATCH = /\b(from (scratch|nothing|zero|the (start|beginning|ground up))|start(ing)? (it )?(over|afresh)|afresh|anew|clean slate|(delete|wipe|remove|drop|throw away)\b.{0,30}\b(module|code|codebase|everything|all of it))/i;
|
|
114
118
|
/** regenerate: regenerate a module's code up to its spec as it is now. */
|
|
115
119
|
export function regenerateTool(options) {
|
|
@@ -131,6 +135,7 @@ export function regenerateTool(options) {
|
|
|
131
135
|
"A change to a file the spec links - an API surface, a mapping document - is a change to the spec: regenerate sees it by itself, and regenerates every functional spec that uses what links it.",
|
|
132
136
|
"Never stop pulses and start them again yourself to follow a spec change: regenerate does it.",
|
|
133
137
|
"Set from_scratch only when the user asks for the module to be regenerated from scratch - started over, its code deleted - in this conversation, or agrees to it when a module's status says it has to start over: never to fix a pulse that did not land.",
|
|
138
|
+
'from_scratch "module" takes out the code where the module is built; the modules below keep theirs, and the module starts from a copy of the code below it. "chain" takes out every codebase of its requires chain, the base\'s too, and builds all of it again from the bottom: use it after modules were split, merged or moved (refactor-module), or when the user asks for the whole chain.',
|
|
134
139
|
],
|
|
135
140
|
parameters: Type.Object({
|
|
136
141
|
plain_file: Type.Optional(Type.String({ description: "Path to the .plain file. Omitted: the module the project's config.turri.yaml names" })),
|
|
@@ -139,8 +144,9 @@ export function regenerateTool(options) {
|
|
|
139
144
|
functionalities: Type.Optional(Type.Array(Type.String(), {
|
|
140
145
|
description: "Functional specs already built, by id, to regenerate though their spec did not change. Omitted: what the spec now differs from the code in",
|
|
141
146
|
})),
|
|
142
|
-
from_scratch: Type.Optional(Type.
|
|
143
|
-
description: "Only when the user asks for it: the module's code and conformance tests deleted - committed first, so its lineage keeps them - and the whole module regenerated from its spec"
|
|
147
|
+
from_scratch: Type.Optional(Type.Union([Type.Literal("module"), Type.Literal("chain")], {
|
|
148
|
+
description: "Only when the user asks for it: the module's code and conformance tests deleted - committed first, so its lineage keeps them - and the whole module regenerated from its spec. " +
|
|
149
|
+
'"chain": every module of its requires chain too, built again from the bottom',
|
|
144
150
|
})),
|
|
145
151
|
model: MODEL_PARAM,
|
|
146
152
|
wait: WAIT_PARAM,
|
|
@@ -151,15 +157,15 @@ export function regenerateTool(options) {
|
|
|
151
157
|
if (!check.ok)
|
|
152
158
|
throw new Error(`${relative(options.cwd, plainFile) || plainFile} does not parse, so nothing can be regenerated from it yet: ${check.error}`);
|
|
153
159
|
const again = given.functionalities ?? [];
|
|
154
|
-
if (again.length > 0 && given.from_scratch
|
|
160
|
+
if (again.length > 0 && given.from_scratch !== undefined)
|
|
155
161
|
throw new Error("Name functionalities or set from_scratch, not both: from scratch regenerates every one of them.");
|
|
156
162
|
// Named functionalities are work on functionalities, as engine chooses a model for it; the rest, spec changes.
|
|
157
163
|
const work = again.length > 0 ? "functionalities" : "spec_changes";
|
|
158
164
|
const model = options.model !== undefined ? options.model(ctx, plainFile, given.model, work) : given.model;
|
|
159
165
|
const loop = options.loop(ctx);
|
|
160
166
|
const request = { ...(model !== undefined ? { model } : {}), ...(given.guidance !== undefined ? { guidance: given.guidance } : {}) };
|
|
161
|
-
const statuses = given.from_scratch
|
|
162
|
-
? await loop.fromScratch(plainFile, request)
|
|
167
|
+
const statuses = given.from_scratch !== undefined
|
|
168
|
+
? await loop.fromScratch(plainFile, { ...request, chain: given.from_scratch === "chain" })
|
|
163
169
|
: again.length > 0
|
|
164
170
|
? await loop.regenerateAgain(plainFile, again, request)
|
|
165
171
|
: await loop.bringUp(plainFile, request);
|
package/dist/module-report.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { brand } from "./brand.js";
|
|
1
2
|
/** Colours for what the command line prints. */
|
|
2
3
|
export const c = {
|
|
3
4
|
dim: (s) => `\x1b[2m${s}\x1b[0m`,
|
|
4
5
|
bold: (s) => `\x1b[1m${s}\x1b[0m`,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
success: brand.success,
|
|
7
|
+
error: brand.error,
|
|
8
|
+
warning: brand.warning,
|
|
9
|
+
accent: brand.accent,
|
|
9
10
|
};
|
package/dist/pi.js
CHANGED
|
@@ -4,6 +4,7 @@ import { createAgentSession, DefaultResourceLoader, getAgentDir, ModelRegistry,
|
|
|
4
4
|
import { loadRules, renderRulesBlock } from "./rules.js";
|
|
5
5
|
import { inheritModel, stackOf, readProjectConfig, ROLE_THINKING, roleModel, roleTurnLimitMs, splitModelSpec } from "./config.js";
|
|
6
6
|
import { maskToolResults } from "./regenerate/masking.js";
|
|
7
|
+
import { withListArguments } from "./regenerate/list-arguments.js";
|
|
7
8
|
import { checkAgainstScript, ENVIRONMENT_ERROR_TOOL, EnvironmentError, environmentErrorTool, sandboxGapOf } from "./regenerate/environment-error.js";
|
|
8
9
|
import { MODULES_DIR, projectRootOf, sessionsDir } from "./regenerate/paths.js";
|
|
9
10
|
import { currentStopSignal, describeToolCall, describeToolResult, JobStoppedError, shownName, reportActivity, reportNow, reportAgent, reportTranscript, reportModelEvent, reportUsage, } from "./regenerate/activity.js";
|
|
@@ -146,6 +147,19 @@ export class ProviderError extends Error {
|
|
|
146
147
|
this.name = "ProviderError";
|
|
147
148
|
}
|
|
148
149
|
}
|
|
150
|
+
/** Why turri itself ended a session's turn under way: the abort that comes back is its own, not the provider failing. */
|
|
151
|
+
const harnessStops = new WeakMap();
|
|
152
|
+
/**
|
|
153
|
+
* End the agent's turn, turri's own doing - it is going round in a circle, its time is up. The turn ends as any turn
|
|
154
|
+
* does: what the agent said stands, and the harness goes on from there. Never a provider error.
|
|
155
|
+
*/
|
|
156
|
+
export function stopTurn(session, reason) {
|
|
157
|
+
if (session === undefined || harnessStops.has(session))
|
|
158
|
+
return;
|
|
159
|
+
harnessStops.set(session, reason);
|
|
160
|
+
reportModelEvent({ kind: "stopped", ...modelEventOf(session), reason });
|
|
161
|
+
void session.abort();
|
|
162
|
+
}
|
|
149
163
|
/**
|
|
150
164
|
* Run one turn and return the assistant's text, streaming deltas to `onDelta`.
|
|
151
165
|
*
|
|
@@ -212,17 +226,32 @@ async function askUnrestricted(session, text, onDelta) {
|
|
|
212
226
|
catch (error) {
|
|
213
227
|
if (!(error instanceof ProviderError) || !TRANSIENT_PROVIDER_ERROR.test(error.message) || attempt >= PROVIDER_RETRIES)
|
|
214
228
|
throw error;
|
|
215
|
-
const wait =
|
|
216
|
-
|
|
217
|
-
|
|
229
|
+
const wait = providerRetryDelay(attempt);
|
|
230
|
+
const shown = `${Math.round(wait / 1000)}s (${attempt + 1} of ${PROVIDER_RETRIES})`;
|
|
231
|
+
reportActivity(` the model provider is failing for now - trying again in ${shown}`);
|
|
232
|
+
reportNow(`the model provider is failing - trying again in ${shown}`);
|
|
233
|
+
reportModelEvent({ kind: "provider_retry", ...modelEventOf(session), error: error.message, attempt: attempt + 1, of: PROVIDER_RETRIES, waitMs: wait });
|
|
234
|
+
debugLogOf(session)?.note(`provider failing - trying again in ${shown}: ${error.message.slice(0, 200)}`);
|
|
218
235
|
await waitOrStop(wait);
|
|
236
|
+
reportNow(undefined);
|
|
219
237
|
prompt = "Carry on where you were: the model provider failed part-way through your last turn.";
|
|
220
238
|
}
|
|
221
239
|
}
|
|
222
240
|
}
|
|
223
|
-
/**
|
|
224
|
-
|
|
241
|
+
/**
|
|
242
|
+
* How many times, after pi's own retries, a turn whose provider failed for a moment is tried again; the first wait,
|
|
243
|
+
* doubled each time up to the longest - 15s, 30s, 1m, 2m, 4m, 5m: an outage of about 13 minutes is waited out.
|
|
244
|
+
*/
|
|
245
|
+
export const PROVIDER_RETRIES = 6;
|
|
225
246
|
export const PROVIDER_RETRY_DELAY_MS = Number(process.env.TURRI_PROVIDER_RETRY_DELAY ?? 15) * 1000;
|
|
247
|
+
export const PROVIDER_RETRY_MAX_DELAY_MS = 20 * PROVIDER_RETRY_DELAY_MS;
|
|
248
|
+
/** The wait before try `attempt + 1`: doubled each time, up to the longest, with a tenth either way so parallel jobs do not all come back at once. */
|
|
249
|
+
export function providerRetryDelay(attempt, random = Math.random) {
|
|
250
|
+
const base = Math.min(PROVIDER_RETRY_DELAY_MS * 2 ** attempt, PROVIDER_RETRY_MAX_DELAY_MS);
|
|
251
|
+
return Math.round(base * (0.9 + 0.2 * random()));
|
|
252
|
+
}
|
|
253
|
+
/** How long a request to the model may go without anything coming back before the provider is said to be stalling; 0 never. */
|
|
254
|
+
export const PROVIDER_STALL_MS = Number(process.env.TURRI_PROVIDER_STALL ?? 120) * 1000;
|
|
226
255
|
/** A provider error that passes: overloaded, rate limited, unreachable, timed out. */
|
|
227
256
|
const TRANSIENT_PROVIDER_ERROR = /\b(429|500|502|503|504|529)\b|overloaded|high demand|rate.?limit|too many requests|unavailable|fetch failed|network|connection|timed? ?out|ECONNRESET|socket|terminated/i;
|
|
228
257
|
/** Wait, unless the job is stopped first. */
|
|
@@ -251,7 +280,7 @@ async function askOnce(session, text, onDelta) {
|
|
|
251
280
|
// Calls to one tool failing one after another - arguments it refuses, or errors - with nothing going through.
|
|
252
281
|
let failing = 0;
|
|
253
282
|
let failingTool;
|
|
254
|
-
|
|
283
|
+
harnessStops.delete(session);
|
|
255
284
|
reportNow("waiting for the model");
|
|
256
285
|
// Every entry says which agent it is from, and what it runs on - for reading one agent at a time.
|
|
257
286
|
const agent = agentOf(session);
|
|
@@ -263,7 +292,30 @@ async function askOnce(session, text, onDelta) {
|
|
|
263
292
|
if (agent !== undefined)
|
|
264
293
|
reportAgent({ label: agent.label, ...(agent.model !== undefined ? { model: agent.model } : {}), turns: 1 });
|
|
265
294
|
reportModelEvent({ kind: "turn", ...modelEventOf(session) });
|
|
295
|
+
// The provider stalling: a request to the model that nothing has come back on - not a token, not an error - for
|
|
296
|
+
// long. Said once for each silence; the turn goes on waiting, its own time limit ending it if it must.
|
|
297
|
+
let toolsRunning = 0;
|
|
298
|
+
let stall;
|
|
299
|
+
const watchForStall = (afterMs = PROVIDER_STALL_MS) => {
|
|
300
|
+
if (stall !== undefined)
|
|
301
|
+
clearTimeout(stall);
|
|
302
|
+
stall = toolsRunning > 0 || PROVIDER_STALL_MS <= 0 ? undefined : setTimeout(() => {
|
|
303
|
+
reportModelEvent({ kind: "provider_stall", ...modelEventOf(session), waitMs: PROVIDER_STALL_MS });
|
|
304
|
+
debugLogOf(session)?.note(`the provider has sent nothing back for ${seconds(PROVIDER_STALL_MS)}`);
|
|
305
|
+
}, afterMs);
|
|
306
|
+
};
|
|
266
307
|
const unsubscribe = session.subscribe((event) => {
|
|
308
|
+
if (event.type === "tool_execution_start")
|
|
309
|
+
toolsRunning += 1;
|
|
310
|
+
if (event.type === "tool_execution_end")
|
|
311
|
+
toolsRunning = Math.max(0, toolsRunning - 1);
|
|
312
|
+
// pi tries a failed request again itself first: the provider failing is said then, not only once pi gives up.
|
|
313
|
+
if (event.type === "auto_retry_start") {
|
|
314
|
+
reportModelEvent({ kind: "provider_retry", ...modelEventOf(session), error: event.errorMessage, attempt: event.attempt, of: event.maxAttempts, waitMs: event.delayMs });
|
|
315
|
+
watchForStall(event.delayMs + PROVIDER_STALL_MS);
|
|
316
|
+
}
|
|
317
|
+
else
|
|
318
|
+
watchForStall();
|
|
267
319
|
if (event.type === "message_update") {
|
|
268
320
|
const update = event.assistantMessageEvent;
|
|
269
321
|
if (update.type === "text_delta") {
|
|
@@ -308,14 +360,13 @@ async function askOnce(session, text, onDelta) {
|
|
|
308
360
|
if (event.type === "tool_execution_end") {
|
|
309
361
|
failing = event.isError ? (event.toolName === failingTool ? failing + 1 : 1) : 0;
|
|
310
362
|
failingTool = event.isError ? event.toolName : undefined;
|
|
311
|
-
if (failing >= FAILURES_BEFORE_STOP && !
|
|
363
|
+
if (failing >= FAILURES_BEFORE_STOP && !harnessStops.has(session)) {
|
|
312
364
|
// A call its tool refuses never reaches the tool, so no guard on the tools sees it: an agent can
|
|
313
365
|
// make the same bad call, worded a little differently, thousands of times. Its turn ends here, and
|
|
314
366
|
// the harness goes on from there, as after any turn.
|
|
315
|
-
stoppedFailing = true;
|
|
316
367
|
reportActivity(` stopped the agent's turn: ${failing} ${shownName(event.toolName)} calls failed in a row`);
|
|
317
368
|
debugLogOf(session)?.note(`turn stopped: ${failing} ${event.toolName} calls failed in a row`);
|
|
318
|
-
|
|
369
|
+
stopTurn(session, `${failing} ${shownName(event.toolName)} calls failed in a row`);
|
|
319
370
|
}
|
|
320
371
|
const output = resultText(event.result);
|
|
321
372
|
transcript({ kind: "result", text: clipText(output, MAX_TOOL_RESULT), error: event.isError, full: output });
|
|
@@ -376,7 +427,7 @@ async function askOnce(session, text, onDelta) {
|
|
|
376
427
|
stopped = true;
|
|
377
428
|
reportActivity(` stopped the agent's turn: its ${formatLimit(limitMs)} are up`);
|
|
378
429
|
debug?.note(`turn stopped: its ${formatLimit(limitMs)} are up${how}`);
|
|
379
|
-
|
|
430
|
+
stopTurn(session, `its ${formatLimit(limitMs)} were up`);
|
|
380
431
|
};
|
|
381
432
|
const atNextRequest = timed
|
|
382
433
|
? session.subscribe((event) => {
|
|
@@ -392,6 +443,7 @@ async function askOnce(session, text, onDelta) {
|
|
|
392
443
|
}
|
|
393
444
|
// What the model is sent, and only that: its task is its system prompt, which the log already holds whole.
|
|
394
445
|
debug?.prompt(text);
|
|
446
|
+
watchForStall();
|
|
395
447
|
try {
|
|
396
448
|
// Its images, when its conversation does not hold them: the first turn, and the first after a compaction.
|
|
397
449
|
const images = sessionImages.get(session);
|
|
@@ -412,19 +464,24 @@ async function askOnce(session, text, onDelta) {
|
|
|
412
464
|
clearTimeout(timer);
|
|
413
465
|
if (backstop !== undefined)
|
|
414
466
|
clearTimeout(backstop);
|
|
467
|
+
if (stall !== undefined)
|
|
468
|
+
clearTimeout(stall);
|
|
415
469
|
atNextRequest?.();
|
|
416
470
|
unsubscribe();
|
|
417
471
|
stop?.removeEventListener("abort", onStop);
|
|
418
472
|
reportNow(undefined);
|
|
419
473
|
}
|
|
420
|
-
|
|
421
|
-
|
|
474
|
+
// turri ended the turn itself - its time was up, the agent went round in a circle: the abort that ended it is its own.
|
|
475
|
+
const stoppedFor = harnessStops.get(session);
|
|
476
|
+
harnessStops.delete(session);
|
|
477
|
+
if (stoppedFor !== undefined)
|
|
478
|
+
out = `${out.trim()}\n\n[the turn was stopped: ${stoppedFor}]`.trim();
|
|
422
479
|
if (stop?.aborted) {
|
|
423
480
|
debug?.note(`turn stopped on request after ${seconds(Date.now() - turnStarted)}`);
|
|
424
481
|
throw new JobStoppedError();
|
|
425
482
|
}
|
|
426
|
-
// A turn ended
|
|
427
|
-
if (providerError !== undefined &&
|
|
483
|
+
// A turn turri ended is ended, whatever the provider was doing then: what comes back of the abort is not the provider failing.
|
|
484
|
+
if (providerError !== undefined && stoppedFor === undefined) {
|
|
428
485
|
debug?.note(`turn ended with a provider error after ${seconds(Date.now() - turnStarted)}: ${providerError}`);
|
|
429
486
|
throw new ProviderError(`${session.model?.id ?? "model"}: ${providerError}`);
|
|
430
487
|
}
|
|
@@ -614,7 +671,7 @@ export function guardRepeats(tools, session, budget) {
|
|
|
614
671
|
refused += 1;
|
|
615
672
|
if (refused > REFUSED_BEFORE_STOP) {
|
|
616
673
|
reportActivity(` stopped the agent's turn: ${refused} calls to tools this turn does not have`);
|
|
617
|
-
|
|
674
|
+
stopTurn(current, `${refused} calls to tools this turn does not have`);
|
|
618
675
|
throw new Error(`Stopped: ${refused} calls to tools this turn does not have.`);
|
|
619
676
|
}
|
|
620
677
|
throw new Error(`Not run: your work is done and checked - this turn is for ${[...only].join(" and ")} alone, and nothing else is ` +
|
|
@@ -624,7 +681,7 @@ export function guardRepeats(tools, session, budget) {
|
|
|
624
681
|
if (budget !== undefined && !budget.finish.includes(tool.name) && calls > budget.calls) {
|
|
625
682
|
if (calls > budget.calls * 2) {
|
|
626
683
|
reportActivity(` stopped the agent's turn: ${calls} tool calls, past its budget of ${budget.calls}`);
|
|
627
|
-
|
|
684
|
+
stopTurn(session(), `${calls} tool calls, past its budget of ${budget.calls}`);
|
|
628
685
|
throw new Error(`Stopped: ${calls} tool calls, past the budget of ${budget.calls}.`);
|
|
629
686
|
}
|
|
630
687
|
throw new Error(`Not run: you have made ${budget.calls} tool calls, which is all you have. Decide now with what you know: call ` +
|
|
@@ -652,7 +709,7 @@ export function guardRepeats(tools, session, budget) {
|
|
|
652
709
|
}
|
|
653
710
|
if (repeats > REPEATS_BEFORE_STOP) {
|
|
654
711
|
reportActivity(` stopped the agent's turn: it made the same ${tool.name} call ${repeats} times with nothing changed`);
|
|
655
|
-
|
|
712
|
+
stopTurn(session(), `the same ${tool.name} call ${repeats} times with nothing changed`);
|
|
656
713
|
throw new Error(`Stopped: the same ${tool.name} call ${repeats} times with nothing changed.`);
|
|
657
714
|
}
|
|
658
715
|
if (repeats > REPEATS_ALLOWED) {
|
|
@@ -695,7 +752,7 @@ export async function createExecutor(opts) {
|
|
|
695
752
|
modelRuntime: await subAgentModelRuntime(),
|
|
696
753
|
tools: hasShell ? [...opts.tools, ENVIRONMENT_ERROR_TOOL] : opts.tools,
|
|
697
754
|
// What an agent is shown never holds a credential the project passed: each value is its name (masking.ts).
|
|
698
|
-
customTools: guardRepeats(maskToolResults(withEnvironmentErrors), () => session, opts.budget),
|
|
755
|
+
customTools: guardRepeats(maskToolResults(withListArguments(withEnvironmentErrors)), () => session, opts.budget),
|
|
699
756
|
sessionManager,
|
|
700
757
|
resourceLoader: await subAgentResources(opts.cwd, opts.rules === true, [opts.system, opts.task].filter((part) => part !== undefined && part !== "").join("\n\n") || undefined),
|
|
701
758
|
});
|
|
@@ -814,7 +871,7 @@ export async function createJudge(opts) {
|
|
|
814
871
|
model,
|
|
815
872
|
modelRuntime,
|
|
816
873
|
tools: [...(opts.extraTools ?? []), "submit_verdict"],
|
|
817
|
-
customTools: [opts.verdictTool],
|
|
874
|
+
customTools: withListArguments([opts.verdictTool]),
|
|
818
875
|
sessionManager: SessionManager.inMemory(opts.cwd),
|
|
819
876
|
// Judges assess specs against the rules, so they have them too.
|
|
820
877
|
resourceLoader: await subAgentResources(opts.cwd, true, opts.task),
|
package/dist/question-dialog.js
CHANGED
|
@@ -90,6 +90,27 @@ export function onModelEvent(listener) {
|
|
|
90
90
|
modelListeners.add(listener);
|
|
91
91
|
return () => modelListeners.delete(listener);
|
|
92
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* The model provider failing or stalling, in a line for the person: the chat's notification, a headless run's console.
|
|
95
|
+
* A turn turri stopped itself is the work going its normal course - kept in the activity, the pulse's log and the run
|
|
96
|
+
* report, not said.
|
|
97
|
+
*/
|
|
98
|
+
export function describeTurnIncident(event) {
|
|
99
|
+
const who = event.role ?? event.label ?? "an agent";
|
|
100
|
+
const model = event.model !== undefined ? ` (${event.model})` : "";
|
|
101
|
+
if (event.kind === "provider_retry") {
|
|
102
|
+
const wait = Math.round((event.waitMs ?? 0) / 1000);
|
|
103
|
+
return `The model provider failed${model}: ${(event.error ?? "").slice(0, 160)} - trying ${who}'s request again in ${wait}s (${event.attempt} of ${event.of}).`;
|
|
104
|
+
}
|
|
105
|
+
if (event.kind === "provider_stall") {
|
|
106
|
+
return `The model provider has sent nothing back to ${who}${model} for ${formatSilence(event.waitMs ?? 0)} - still waiting.`;
|
|
107
|
+
}
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
function formatSilence(ms) {
|
|
111
|
+
const seconds = Math.round(ms / 1000);
|
|
112
|
+
return seconds >= 60 && seconds % 60 === 0 ? `${seconds / 60}m` : seconds >= 60 ? `${Math.floor(seconds / 60)}m ${seconds % 60}s` : `${seconds}s`;
|
|
113
|
+
}
|
|
93
114
|
export function reportModelEvent(event) {
|
|
94
115
|
if (modelListeners.size === 0)
|
|
95
116
|
return;
|