@turri-dev/cli 0.1.2-next.48dacfc → 0.1.3-next.17f0f7f
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/dist/chat-skills.js +1 -1
- package/dist/config.js +23 -1
- package/dist/conform-cli.js +12 -5
- package/dist/init-config.js +3 -3
- package/dist/loop-cli.js +212 -17
- package/dist/pi.js +14 -2
- package/dist/plain/errors.js +1 -1
- package/dist/plain/files.js +1 -1
- package/dist/plain/liquid.js +2 -2
- package/dist/regenerate/activity.js +19 -0
- package/dist/regenerate/loop.js +56 -2
- package/dist/regenerate/prompt.js +1 -1
- package/dist/regenerate/release.js +8 -6
- package/dist/regenerate-cli.js +23 -29
- package/dist/run-report.js +309 -0
- package/dist/setup.js +12 -1
- package/dist/spec-diff-cli.js +16 -6
- package/docs/config.md +22 -11
- package/docs/headless.md +161 -15
- package/docs/parser.md +1 -1
- package/docs/regenerating.md +2 -2
- package/genome/skills/implement-conformance-testing-script/SKILL.md +1 -1
- package/package.json +1 -1
package/dist/chat-skills.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* message, a deploy - is offered as pi offers it.
|
|
12
12
|
*/
|
|
13
13
|
/** What a skill says it is about, that turri covers: ***plain specs and their testing scripts. */
|
|
14
|
-
const ABOUT_PLAIN = /\*\*\*plain|\\\*\\\*\\\*plain|\.plain\b
|
|
14
|
+
const ABOUT_PLAIN = /\*\*\*plain|\\\*\\\*\\\*plain|\.plain\b|functional specs?\b|testing scripts?\b|run_unittests|run_conformance_tests/i;
|
|
15
15
|
/** Whether turri has what a pi skill offers: it runs a skill of that name itself, or the skill is about ***plain. */
|
|
16
16
|
export function supersededByTurri(skill, turriRuns) {
|
|
17
17
|
return turriRuns.has(skill.name) || ABOUT_PLAIN.test(`${skill.name} ${skill.description}`);
|
package/dist/config.js
CHANGED
|
@@ -49,7 +49,7 @@ import { projectDirOf } from "./regenerate/paths.js";
|
|
|
49
49
|
* as `coding-model`, which it was before there were two.
|
|
50
50
|
*
|
|
51
51
|
* Keys are written with dashes; underscores are read the same (`conformance_tests`). Keys it
|
|
52
|
-
* does not know -
|
|
52
|
+
* does not know - another tool's `config.yaml`, read while it is the old file, may carry several - are ignored, and so is a value of
|
|
53
53
|
* the wrong type. Everything is optional, and what is given on the command line wins.
|
|
54
54
|
*
|
|
55
55
|
* A project whose parts do not share a stack - a Python backend and a React frontend beside each other - keeps a
|
|
@@ -385,6 +385,9 @@ function text(value) {
|
|
|
385
385
|
* not parse.
|
|
386
386
|
*/
|
|
387
387
|
export function readProjectConfig(root, stack) {
|
|
388
|
+
return withRunOverrides(readStackedConfig(root, stack));
|
|
389
|
+
}
|
|
390
|
+
function readStackedConfig(root, stack) {
|
|
388
391
|
const project = readConfigFile(join(root, projectConfigFile(root)));
|
|
389
392
|
if (stack === undefined)
|
|
390
393
|
return project;
|
|
@@ -403,6 +406,25 @@ export function readProjectConfig(root, stack) {
|
|
|
403
406
|
merged.models = joinModels(project.models, own.models);
|
|
404
407
|
return withoutUndefined(merged);
|
|
405
408
|
}
|
|
409
|
+
let runOverrides = {};
|
|
410
|
+
/** Read a command's options as the config's keys for the rest of this process. */
|
|
411
|
+
export function overrideConfig(overrides) {
|
|
412
|
+
runOverrides = { ...overrides };
|
|
413
|
+
}
|
|
414
|
+
/** `--conformance-tests <value>`: the config's own values - all (or true), chosen, module, false. Undefined for anything else. */
|
|
415
|
+
export function conformanceOption(value) {
|
|
416
|
+
return conformanceSetting(value);
|
|
417
|
+
}
|
|
418
|
+
/** `--review <value>`: the config's own, true or false. Undefined for anything else. */
|
|
419
|
+
export function reviewOption(value) {
|
|
420
|
+
const word = value.trim().toLowerCase();
|
|
421
|
+
return word === "true" ? true : word === "false" ? false : undefined;
|
|
422
|
+
}
|
|
423
|
+
/** The config with the command's options in place of the keys they name. */
|
|
424
|
+
function withRunOverrides(config) {
|
|
425
|
+
const given = Object.entries(runOverrides).filter(([, value]) => value !== undefined);
|
|
426
|
+
return given.length === 0 ? config : { ...config, ...Object.fromEntries(given) };
|
|
427
|
+
}
|
|
406
428
|
/** A module's `models:` over the project's, role by role - each entry taking what it leaves out from the project's; the chat's the project's alone. */
|
|
407
429
|
function joinModels(project, own) {
|
|
408
430
|
if (own === undefined)
|
package/dist/conform-cli.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { parseArgs, runLoop } from "./loop-cli.js";
|
|
1
|
+
import { headlessOptions, parseArgs, runLoop } from "./loop-cli.js";
|
|
2
2
|
const USAGE = `usage: turri conform <file.plain> [frid ...] [options]
|
|
3
3
|
|
|
4
4
|
Writes and runs the black-box conformance tests of a module's functional specs - those named, or
|
|
@@ -8,8 +8,14 @@ module inherits, a failure fixed in the test or the code, whichever is wrong. Ev
|
|
|
8
8
|
tested goes in one pulse, as far as the size guardrail lets.
|
|
9
9
|
|
|
10
10
|
--one-by-one a pulse a functional spec instead
|
|
11
|
-
--model <
|
|
12
|
-
|
|
11
|
+
--harness-model <p/id> config.turri.yaml's harness-model for this run: the planner, the conformance chooser, a diagnosis
|
|
12
|
+
--coding-model <p/id> its coding-model, --model too: the agents that build
|
|
13
|
+
--judge-model <p/id> its judge-model: the judge and the test review
|
|
14
|
+
--review <true|false> its review: whether the code and its tests are reviewed once they pass
|
|
15
|
+
--build-dir <dir> as the run ends, export the code there (see turri regenerate --help)
|
|
16
|
+
--report <file.json> write a report of the run there (see turri regenerate --help)`;
|
|
17
|
+
const { positional, options } = parseArgs(process.argv.slice(2), ["--one-by-one"], USAGE, ["--build-dir", "--report", "--harness-model", "--judge-model", "--review"]);
|
|
18
|
+
const { report, buildDir } = headlessOptions(options, false);
|
|
13
19
|
const [plainFile, ...frids] = positional;
|
|
14
20
|
if (plainFile === undefined) {
|
|
15
21
|
console.error(USAGE);
|
|
@@ -17,10 +23,11 @@ if (plainFile === undefined) {
|
|
|
17
23
|
}
|
|
18
24
|
runLoop({
|
|
19
25
|
plainFile,
|
|
20
|
-
...(
|
|
26
|
+
...(buildDir !== undefined ? { buildDir } : {}),
|
|
27
|
+
...(report !== undefined ? { report } : {}),
|
|
28
|
+
command: ["conform", ...process.argv.slice(2)],
|
|
21
29
|
ask: (loop) => loop.conformance(plainFile, {
|
|
22
30
|
...(frids.length > 0 ? { frids } : {}),
|
|
23
|
-
...(options.model !== undefined ? { model: options.model } : {}),
|
|
24
31
|
...(options["one-by-one"] !== undefined ? { separately: true } : {}),
|
|
25
32
|
}),
|
|
26
33
|
}).catch((error) => {
|
package/dist/init-config.js
CHANGED
|
@@ -292,7 +292,7 @@ function whose(vendor, bedrock) {
|
|
|
292
292
|
return `${VENDORS[choice.maker].label}'s on Amazon Bedrock (${choice.region})`;
|
|
293
293
|
}
|
|
294
294
|
/**
|
|
295
|
-
* What a config.yaml in `folder` says that turri reads too -
|
|
295
|
+
* What a config.yaml in `folder` says that turri reads too - another tool's testing scripts, say - by turri's names
|
|
296
296
|
* (`template_dir` read as `template-dir`), in the file's order; and the keys it leaves, turri reading none of them. The
|
|
297
297
|
* two models are the vendor's, so they are not taken.
|
|
298
298
|
*/
|
|
@@ -338,7 +338,7 @@ export function initConfig(dir, options = {}) {
|
|
|
338
338
|
const existing = existsSync(path) && options.force !== true;
|
|
339
339
|
const { harness, coding } = modelsOf(vendor, options.bedrock);
|
|
340
340
|
const lines = modelLines(harness, coding);
|
|
341
|
-
// A new file takes what a config.yaml beside it -
|
|
341
|
+
// A new file takes what a config.yaml beside it - another tool's, say - says that turri reads too: its testing scripts, say.
|
|
342
342
|
const shared = existing ? { carried: [], left: [] } : sharedWithLegacy(folder);
|
|
343
343
|
const config = existing
|
|
344
344
|
? withModels(readFileSync(path, "utf8"), lines)
|
|
@@ -384,7 +384,7 @@ const USAGE = [
|
|
|
384
384
|
"a mix of Anthropic and Google, the starting point for any provider pi supports. On amazon-bedrock, --maker and",
|
|
385
385
|
"--region say whose models and where (anthropic: global, us, eu, jp, au; openai: global, us) - asked when not given.",
|
|
386
386
|
"A config.turri.yaml already there keeps everything but its two models; --force writes the whole of it again. A new",
|
|
387
|
-
"one takes from a config.yaml beside it -
|
|
387
|
+
"one takes from a config.yaml beside it - another tool's, say - the keys turri reads too, its testing scripts say, and leaves",
|
|
388
388
|
"config.yaml as it is.",
|
|
389
389
|
].join("\n");
|
|
390
390
|
/** Ask until the answer is one `read` takes. */
|
package/dist/loop-cli.js
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { sweepOrphanedGroups } from "./regenerate/shell.js";
|
|
2
2
|
import { createInterface } from "node:readline/promises";
|
|
3
|
-
import { resolve } from "node:path";
|
|
4
|
-
import { configForSpec, modelSpec, projectModels, readProjectConfig } from "./config.js";
|
|
3
|
+
import { resolve, sep } from "node:path";
|
|
4
|
+
import { configForSpec, conformanceOption, reviewOption, inheritModel, modelOnly, modelSpec, overrideConfig, 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
7
|
import { tryItCommand } from "./regenerate/delivery.js";
|
|
8
8
|
import { describeDiagnosis, diagnoseFailure } from "./regenerate/diagnose.js";
|
|
9
9
|
import { createJobRegistry, pulseName } from "./regenerate/jobs.js";
|
|
10
10
|
import { conformanceChooser } from "./regenerate/choose-conformance.js";
|
|
11
|
-
import { createWorkLoop, describeModules, promptOf } from "./regenerate/loop.js";
|
|
12
|
-
import { projectDirOf } from "./regenerate/paths.js";
|
|
11
|
+
import { createWorkLoop, describeModules, functionalityCompletion, promptOf } from "./regenerate/loop.js";
|
|
12
|
+
import { MODULES_DIR, projectDirOf } from "./regenerate/paths.js";
|
|
13
|
+
import { exportModule } from "./regenerate/release.js";
|
|
14
|
+
import { listFiles } from "./regenerate/testing.js";
|
|
15
|
+
import { startRunReport } from "./run-report.js";
|
|
13
16
|
/**
|
|
14
17
|
* What every command that builds - `turri regenerate`, `conform`, `spec-diff` - does around its own
|
|
15
18
|
* request of the work loop, as the chat does it: the project's models, a job that fails run once more and, failing again,
|
|
16
19
|
* diagnosed, a line as each job starts and ends; then the loop run until nothing more can start, how each job ended,
|
|
17
|
-
* and exit 1 when any failed. With `dryRun`, the work is planned and the prompt of the first job each codebase would
|
|
20
|
+
* and exit 1 when any failed or a module is not complete. With `dryRun`, the work is planned and the prompt of the first job each codebase would
|
|
18
21
|
* start printed, and nothing runs.
|
|
19
22
|
*/
|
|
20
23
|
export async function runLoop(options) {
|
|
@@ -24,8 +27,42 @@ export async function runLoop(options) {
|
|
|
24
27
|
if (orphans > 0)
|
|
25
28
|
console.log(`Stopped ${orphans} process group${orphans === 1 ? "" : "s"} a turri that was killed left running.`);
|
|
26
29
|
const project = { ...readProjectConfig(process.cwd()), ...Object.fromEntries(Object.entries(configForSpec(plainFile)).filter(([, value]) => value !== undefined)) };
|
|
27
|
-
|
|
30
|
+
// The models as the config has them - with a command's own options read as its keys (headlessOptions), as the chat reads them.
|
|
31
|
+
const model = modelSpec(projectModels(project).coding);
|
|
28
32
|
const projectDir = projectDirOf(plainFile);
|
|
33
|
+
const buildDir = options.buildDir !== undefined && options.dryRun !== true ? resolve(options.buildDir) : undefined;
|
|
34
|
+
if (buildDir !== undefined)
|
|
35
|
+
refuseBuildDir(buildDir, projectDir);
|
|
36
|
+
// The code, exported into --build-dir as the process exits - however it exits - before the report's last write.
|
|
37
|
+
let exported;
|
|
38
|
+
if (buildDir !== undefined) {
|
|
39
|
+
process.once("exit", () => {
|
|
40
|
+
exported = exportCode(plainFile, buildDir);
|
|
41
|
+
console.error(exported.exported === true ? `The code is in ${buildDir} (${String(exported.module)} at ${String(exported.commit)}).` : `Nothing exported to ${buildDir}: ${String(exported.why)}`);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const report = options.report !== undefined && options.dryRun !== true
|
|
45
|
+
? startRunReport({
|
|
46
|
+
file: options.report,
|
|
47
|
+
command: options.command ?? process.argv.slice(2),
|
|
48
|
+
specFile: plainFile,
|
|
49
|
+
projectDir,
|
|
50
|
+
...(buildDir !== undefined ? { buildDir } : {}),
|
|
51
|
+
conformanceTests: conformanceLabel(project.conformanceTests),
|
|
52
|
+
review: project.review === true,
|
|
53
|
+
models: reportModels(project, model),
|
|
54
|
+
})
|
|
55
|
+
: undefined;
|
|
56
|
+
try {
|
|
57
|
+
return await runLoopReporting({ ...options, plainFile, project, model, projectDir, reporter: report, exported: () => exported });
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
report?.crashed(error);
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async function runLoopReporting(options) {
|
|
65
|
+
const { plainFile, project, model, projectDir, reporter: report } = options;
|
|
29
66
|
// Each job as it starts and as it ends - the transcript of each is in .turri/jobs/.
|
|
30
67
|
const seen = new Map();
|
|
31
68
|
const registry = createJobRegistry({
|
|
@@ -47,18 +84,28 @@ export async function runLoop(options) {
|
|
|
47
84
|
console.log(`${mark} ${job.id} ${pulseName(job)} - ${job.status}`);
|
|
48
85
|
if (job.status !== "succeeded")
|
|
49
86
|
console.log(c.dim((job.announce ?? job.report ?? job.error ?? "").trim()));
|
|
87
|
+
report?.write();
|
|
50
88
|
},
|
|
51
89
|
});
|
|
52
90
|
const planner = modelSpec(projectModels(project).harness);
|
|
53
91
|
const loop = createWorkLoop({
|
|
54
92
|
registry,
|
|
55
93
|
cwd: process.cwd(),
|
|
56
|
-
...(options.buildDir !== undefined ? { buildDir: resolve(options.buildDir) } : {}),
|
|
57
94
|
...(model !== undefined ? { modelFor: () => model } : {}),
|
|
58
95
|
...(planner !== undefined ? { plannerModel: planner } : {}),
|
|
59
96
|
...(options.dryRun === true ? { dryRun: true } : {}),
|
|
60
|
-
// Under conformance-tests: chosen or module, the chooser decides as a pulse ends, as in the chat
|
|
61
|
-
|
|
97
|
+
// Under conformance-tests: chosen or module, the chooser decides as a pulse ends, as in the chat - on the harness
|
|
98
|
+
// model, else the coding model: never pi's own default, which may be one this account cannot reach.
|
|
99
|
+
onChoose: conformanceChooser({ model: () => planner ?? model, ...(options.dryRun === true ? { dryRun: true } : {}) }),
|
|
100
|
+
});
|
|
101
|
+
report?.attach({
|
|
102
|
+
jobs: () => registry.list(),
|
|
103
|
+
modules: () => moduleStates(loop.drift(plainFile)),
|
|
104
|
+
completion: () => functionalityCompletion(plainFile),
|
|
105
|
+
atExit: () => {
|
|
106
|
+
const exported = options.exported();
|
|
107
|
+
return exported !== undefined ? { build_dir_export: exported } : undefined;
|
|
108
|
+
},
|
|
62
109
|
});
|
|
63
110
|
let planned = await options.ask(loop);
|
|
64
111
|
console.log(describeModules(planned, { for: "command line" }));
|
|
@@ -68,6 +115,13 @@ export async function runLoop(options) {
|
|
|
68
115
|
const why = toStartOver
|
|
69
116
|
.map(({ startOver }) => `${startOver.codebases.join(", ")} was built without ${startOver.requires.join(", ")}, which it now requires: no change to its code can bring it in.`)
|
|
70
117
|
.join("\n");
|
|
118
|
+
// No terminal and no --start-over: no one to ask, so the run stops here rather than build nothing and say it is done.
|
|
119
|
+
if (options.startOver !== true && process.stdin.isTTY !== true) {
|
|
120
|
+
const message = `${why}\nThere is no terminal to ask whether to start over: run it again with --start-over to start over without asking.`;
|
|
121
|
+
console.error(c.red(message));
|
|
122
|
+
report?.end("incomplete", message);
|
|
123
|
+
process.exit(1);
|
|
124
|
+
}
|
|
71
125
|
const agreed = options.startOver === true ||
|
|
72
126
|
(await askAtTerminal("Start over?", `${why}\nStarting over takes its code and conformance tests out - they stay in its history - and builds it again from the bottom of the chain.`));
|
|
73
127
|
if (agreed === true) {
|
|
@@ -91,27 +145,168 @@ export async function runLoop(options) {
|
|
|
91
145
|
console.log(`\n${describeModules(loop.status(), { for: "command line" })}`);
|
|
92
146
|
const ended = registry.list();
|
|
93
147
|
const failed = ended.filter((job) => job.status === "failed");
|
|
94
|
-
|
|
148
|
+
// Complete: every codebase regenerated from the spec as it is, its conformance tests too - nothing halted, nothing
|
|
149
|
+
// waiting for a start over, nothing the planner left out.
|
|
150
|
+
const unfinished = moduleStates(loop.drift(plainFile)).filter((module) => module.state !== "complete");
|
|
151
|
+
const verdict = failed.length > 0
|
|
152
|
+
? c.red(c.bold(`${failed.length} job${failed.length === 1 ? "" : "s"} failed`))
|
|
153
|
+
: unfinished.length > 0
|
|
154
|
+
? c.red(c.bold(`not complete: ${unfinished.map((module) => `${module.module}${module.why !== undefined ? ` - ${module.why}` : ""}`).join("; ")}`))
|
|
155
|
+
: c.green(c.bold("all jobs done"));
|
|
156
|
+
console.log(`\n${verdict}`);
|
|
95
157
|
for (const job of [...ended].reverse())
|
|
96
158
|
console.log(` ${job.id} ${pulseName(job)}: ${job.status}`);
|
|
97
159
|
if (ended.some((job) => job.status === "succeeded"))
|
|
98
160
|
console.log(`\n${tryItCommand(plainFile)}`);
|
|
99
|
-
|
|
161
|
+
report?.end(failed.length > 0 ? "failed" : unfinished.length > 0 ? "incomplete" : "completed");
|
|
162
|
+
process.exit(failed.length === 0 && unfinished.length === 0 ? 0 : 1);
|
|
163
|
+
}
|
|
164
|
+
/** How each codebase stands, from what is left to regenerate there. */
|
|
165
|
+
export function moduleStates(reports) {
|
|
166
|
+
return reports.map((report) => {
|
|
167
|
+
const state = report.running !== undefined
|
|
168
|
+
? "running"
|
|
169
|
+
: report.startOver !== undefined
|
|
170
|
+
? "start_over_needed"
|
|
171
|
+
: report.why !== undefined
|
|
172
|
+
? "halted"
|
|
173
|
+
: report.code === null && (report.conformance === null || report.conformance === undefined) && report.scheduled.length === 0
|
|
174
|
+
? "complete"
|
|
175
|
+
: "incomplete";
|
|
176
|
+
const why = state === "start_over_needed"
|
|
177
|
+
? `built without ${report.startOver.requires.join(", ")}, which it now requires: run with --start-over`
|
|
178
|
+
: state === "incomplete"
|
|
179
|
+
? report.code !== null && report.code !== undefined
|
|
180
|
+
? "its code is not regenerated from the spec as it is"
|
|
181
|
+
: "its conformance tests are not written for what is built"
|
|
182
|
+
: report.why;
|
|
183
|
+
return { module: report.module, state, ...(why !== undefined ? { why } : {}) };
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* A --build-dir the export would wipe something in: the project, a folder holding it, or one inside plain_modules.
|
|
188
|
+
* Anything else is the export's own, its contents replaced as the run ends.
|
|
189
|
+
*/
|
|
190
|
+
function refuseBuildDir(buildDir, projectDir) {
|
|
191
|
+
const within = (dir, of) => dir === of || dir.startsWith(`${of}${sep}`);
|
|
192
|
+
const why = within(projectDir, buildDir)
|
|
193
|
+
? "it holds the project, and the export replaces what is in it"
|
|
194
|
+
: within(buildDir, resolve(projectDir, MODULES_DIR))
|
|
195
|
+
? `it is inside ${MODULES_DIR}, which turri regenerates in`
|
|
196
|
+
: undefined;
|
|
197
|
+
if (why === undefined)
|
|
198
|
+
return;
|
|
199
|
+
console.error(`--build-dir ${buildDir} cannot be used: ${why}. Name a folder of its own - the code is exported there as the run ends.`);
|
|
200
|
+
process.exit(1);
|
|
201
|
+
}
|
|
202
|
+
/** The furthest-built codebase's last commit, exported into `dir` - or why nothing was. */
|
|
203
|
+
function exportCode(plainFile, dir) {
|
|
204
|
+
try {
|
|
205
|
+
const deployment = exportModule(plainFile, undefined, dir);
|
|
206
|
+
const files = listFiles(dir).length;
|
|
207
|
+
// Its history began, and nothing landed in it yet: only the harness's own files, which are left out.
|
|
208
|
+
if (files === 0)
|
|
209
|
+
return { exported: false, dir, why: `nothing has landed in ${deployment.moduleName} yet: its codebase holds no code` };
|
|
210
|
+
return { exported: true, dir, module: deployment.moduleName, commit: deployment.commit, files };
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
return { exported: false, dir, why: error instanceof Error ? error.message : String(error) };
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/** `conformance-tests:` as the report says it - not set is false. */
|
|
217
|
+
function conformanceLabel(setting) {
|
|
218
|
+
return setting === true ? "all" : setting === "chosen" || setting === "module" ? setting : "false";
|
|
219
|
+
}
|
|
220
|
+
/** The models of the three roles as this run uses them: the coding model given, the others as they fall back - each with the level it thinks at. */
|
|
221
|
+
function reportModels(project, model) {
|
|
222
|
+
const coding = splitModelSpec(model);
|
|
223
|
+
const harness = projectModels(project).harness ?? modelOnly(model);
|
|
224
|
+
// As the judge's agent finds it: its models: entry over judge-model over models.default, else the coding model's.
|
|
225
|
+
const judge = inheritModel(roleModel(project, "judge"), modelOnly(model)) ?? {};
|
|
226
|
+
const choice = (given, fallback) => ({
|
|
227
|
+
...(given.model !== undefined ? { model: given.model } : {}),
|
|
228
|
+
...((given.thinking ?? fallback) !== undefined ? { thinking: given.thinking ?? fallback } : {}),
|
|
229
|
+
});
|
|
230
|
+
return {
|
|
231
|
+
harness: choice(harness, ROLE_THINKING.planner),
|
|
232
|
+
coding: choice(coding, ROLE_THINKING.coding),
|
|
233
|
+
judge: choice(judge, ROLE_THINKING.judge),
|
|
234
|
+
};
|
|
100
235
|
}
|
|
101
|
-
/**
|
|
102
|
-
|
|
236
|
+
/**
|
|
237
|
+
* The options every command that regenerates takes for a headless run: `--report` and `--build-dir`, and the config's
|
|
238
|
+
* own keys - `--harness-model`, `--coding-model` (`--model`), `--judge-model`, `--review` and, where `conformance` is
|
|
239
|
+
* true, `--conformance-tests` - read as if config.turri.yaml had them, the config's order of them kept (overrideConfig).
|
|
240
|
+
* Exits on a value it cannot read.
|
|
241
|
+
*/
|
|
242
|
+
export function headlessOptions(options, conformance) {
|
|
243
|
+
const given = (name) => {
|
|
244
|
+
const value = options[name];
|
|
245
|
+
if (name in options && (value === undefined || value.trim() === ""))
|
|
246
|
+
failOption(`--${name} needs a value`);
|
|
247
|
+
return value;
|
|
248
|
+
};
|
|
249
|
+
const tests = conformance ? given("conformance-tests") : undefined;
|
|
250
|
+
const setting = tests !== undefined ? conformanceOption(tests) : undefined;
|
|
251
|
+
if (tests !== undefined && setting === undefined)
|
|
252
|
+
failOption(`--conformance-tests takes all, chosen, module or false, not ${tests}`);
|
|
253
|
+
const reviewed = given("review");
|
|
254
|
+
const review = reviewed !== undefined ? reviewOption(reviewed) : undefined;
|
|
255
|
+
if (reviewed !== undefined && review === undefined)
|
|
256
|
+
failOption(`--review takes true or false, not ${reviewed}`);
|
|
257
|
+
const model = (name) => {
|
|
258
|
+
const spec = given(name);
|
|
259
|
+
return spec !== undefined ? { [name === "model" ? "codingModel" : name === "harness-model" ? "harnessModel" : "judgeModel"]: splitModelSpec(spec) } : {};
|
|
260
|
+
};
|
|
261
|
+
overrideConfig({
|
|
262
|
+
...model("harness-model"),
|
|
263
|
+
...model("model"),
|
|
264
|
+
...model("judge-model"),
|
|
265
|
+
...(setting !== undefined ? { conformanceTests: setting } : {}),
|
|
266
|
+
...(review !== undefined ? { review } : {}),
|
|
267
|
+
});
|
|
268
|
+
const report = given("report");
|
|
269
|
+
const buildDir = given("build-dir");
|
|
270
|
+
return { ...(report !== undefined ? { report } : {}), ...(buildDir !== undefined ? { buildDir } : {}) };
|
|
271
|
+
}
|
|
272
|
+
function failOption(message) {
|
|
273
|
+
console.error(message);
|
|
274
|
+
process.exit(1);
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* A command's arguments: the positional ones, `--flag`s and `--name value` options (`--name=value` too) -
|
|
278
|
+
* `--coding-model` is `--model`. An option it does not take is refused, rather than taking the word after it, and so is an
|
|
279
|
+
* option with no value - the end of the words, or another option where its value should be.
|
|
280
|
+
*/
|
|
281
|
+
export function parseArgs(argv, flags, usage, valued = []) {
|
|
103
282
|
const positional = [];
|
|
104
283
|
const options = {};
|
|
284
|
+
const takes = new Set(["--model", ...valued]);
|
|
105
285
|
for (let i = 0; i < argv.length; i += 1) {
|
|
106
286
|
const arg = argv[i];
|
|
287
|
+
const [name, inline] = arg.startsWith("--") && arg.includes("=") ? [arg.slice(0, arg.indexOf("=")), arg.slice(arg.indexOf("=") + 1)] : [arg, undefined];
|
|
288
|
+
const option = name === "--coding-model" ? "--model" : name;
|
|
107
289
|
if (arg === "-h" || arg === "--help") {
|
|
108
290
|
console.log(usage);
|
|
109
291
|
process.exit(0);
|
|
110
292
|
}
|
|
111
|
-
else if (flags.includes(
|
|
112
|
-
options[
|
|
113
|
-
else if (
|
|
114
|
-
|
|
293
|
+
else if (flags.includes(option) && inline === undefined)
|
|
294
|
+
options[option.slice(2)] = "yes";
|
|
295
|
+
else if (takes.has(option)) {
|
|
296
|
+
// Its value is the next word - never another option, which would be taken as the value and lost.
|
|
297
|
+
const value = inline ?? argv[i + 1];
|
|
298
|
+
if (value === undefined || (inline === undefined && value.startsWith("--"))) {
|
|
299
|
+
console.error(`${usage}\n\n${name} needs a value${value !== undefined ? `, not the option ${value}` : ""} - ${name}=<value> gives one that starts with --.`);
|
|
300
|
+
process.exit(1);
|
|
301
|
+
}
|
|
302
|
+
if (inline === undefined)
|
|
303
|
+
i += 1;
|
|
304
|
+
options[option.slice(2)] = value;
|
|
305
|
+
}
|
|
306
|
+
else if (arg.startsWith("-")) {
|
|
307
|
+
console.error(`${usage}\n\nNo such option: ${name}.`);
|
|
308
|
+
process.exit(1);
|
|
309
|
+
}
|
|
115
310
|
else
|
|
116
311
|
positional.push(arg);
|
|
117
312
|
}
|
package/dist/pi.js
CHANGED
|
@@ -6,7 +6,7 @@ import { inheritModel, stackOf, readProjectConfig, ROLE_THINKING, roleModel, rol
|
|
|
6
6
|
import { maskToolResults } from "./regenerate/masking.js";
|
|
7
7
|
import { checkAgainstScript, ENVIRONMENT_ERROR_TOOL, EnvironmentError, environmentErrorTool, sandboxGapOf } from "./regenerate/environment-error.js";
|
|
8
8
|
import { MODULES_DIR, projectRootOf, sessionsDir } from "./regenerate/paths.js";
|
|
9
|
-
import { currentStopSignal, describeToolCall, describeToolResult, JobStoppedError, shownName, reportActivity, reportNow, reportAgent, reportTranscript, reportUsage, } from "./regenerate/activity.js";
|
|
9
|
+
import { currentStopSignal, describeToolCall, describeToolResult, JobStoppedError, shownName, reportActivity, reportNow, reportAgent, reportTranscript, reportModelEvent, reportUsage, } from "./regenerate/activity.js";
|
|
10
10
|
import { debugLogOf, startDebugLog } from "./regenerate/debug-log.js";
|
|
11
11
|
let thinkingSource;
|
|
12
12
|
/**
|
|
@@ -262,6 +262,7 @@ async function askOnce(session, text, onDelta) {
|
|
|
262
262
|
transcript({ kind: "prompt", text: task !== undefined ? `${task}\n\n${text}` : text });
|
|
263
263
|
if (agent !== undefined)
|
|
264
264
|
reportAgent({ label: agent.label, ...(agent.model !== undefined ? { model: agent.model } : {}), turns: 1 });
|
|
265
|
+
reportModelEvent({ kind: "turn", ...modelEventOf(session) });
|
|
265
266
|
const unsubscribe = session.subscribe((event) => {
|
|
266
267
|
if (event.type === "message_update") {
|
|
267
268
|
const update = event.assistantMessageEvent;
|
|
@@ -332,6 +333,7 @@ async function askOnce(session, text, onDelta) {
|
|
|
332
333
|
reportUsage(spent);
|
|
333
334
|
if (agent !== undefined)
|
|
334
335
|
reportAgent({ label: agent.label, usage: spent });
|
|
336
|
+
reportModelEvent({ kind: "call", ...modelEventOf(session), usage: spent, ms: Date.now() - stepStarted });
|
|
335
337
|
}
|
|
336
338
|
// A provider error counts only if the turn ends on it: a later message that ends well - pi's own retry, the
|
|
337
339
|
// stream picked up again - means it recovered, and the turn's work stands.
|
|
@@ -514,6 +516,7 @@ export async function compactIfDue(session) {
|
|
|
514
516
|
const who = agent?.label ?? "the agent";
|
|
515
517
|
reportActivity(` compacting ${who}'s work: ${thousands(conversation)} tokens of it, past ${thousands(settings.atTokens)}`);
|
|
516
518
|
try {
|
|
519
|
+
const compactStarted = Date.now();
|
|
517
520
|
const result = await session.compact(settings.instructions);
|
|
518
521
|
const usage = result.usage;
|
|
519
522
|
if (usage !== undefined) {
|
|
@@ -521,7 +524,9 @@ export async function compactIfDue(session) {
|
|
|
521
524
|
reportUsage(spent);
|
|
522
525
|
if (agent !== undefined)
|
|
523
526
|
reportAgent({ label: agent.label, usage: spent });
|
|
527
|
+
reportModelEvent({ kind: "call", ...modelEventOf(session), usage: spent, ms: Date.now() - compactStarted });
|
|
524
528
|
}
|
|
529
|
+
reportModelEvent({ kind: "compaction", ...modelEventOf(session) });
|
|
525
530
|
if (agent !== undefined)
|
|
526
531
|
reportAgent({ label: agent.label, compactions: 1 });
|
|
527
532
|
reportActivity(` compacted ${who}'s work${result.estimatedTokensAfter !== undefined ? ` to about ${thousands(result.estimatedTokensAfter)} tokens` : ""}`);
|
|
@@ -542,6 +547,13 @@ const agentRoles = new WeakMap();
|
|
|
542
547
|
function agentOf(session) {
|
|
543
548
|
return agentLabels.get(session);
|
|
544
549
|
}
|
|
550
|
+
/** Who a model event is from: the agent's model as it runs now, its role and its label - an agent with no label too. */
|
|
551
|
+
function modelEventOf(session) {
|
|
552
|
+
const agent = agentOf(session);
|
|
553
|
+
const role = agentRoles.get(session);
|
|
554
|
+
const model = session.model !== undefined ? `${session.model.provider}/${session.model.id}${session.thinkingLevel ? `:${session.thinkingLevel}` : ""}` : agent?.model;
|
|
555
|
+
return { ...(model !== undefined ? { model } : {}), ...(role !== undefined ? { role } : {}), ...(agent !== undefined ? { label: agent.label } : {}) };
|
|
556
|
+
}
|
|
545
557
|
/**
|
|
546
558
|
* Have this session's turns timed, as an agent a render starts has: `limitMs` each - its role's in the config - or
|
|
547
559
|
* the default.
|
|
@@ -700,7 +712,7 @@ export async function createExecutor(opts) {
|
|
|
700
712
|
if (chosen.model !== undefined) {
|
|
701
713
|
const model = findModel(session, chosen.model);
|
|
702
714
|
if (model === undefined) {
|
|
703
|
-
throw new Error(`Model '${chosen.model}' is not
|
|
715
|
+
throw new Error(`Model '${chosen.model}' is not a model pi knows: no such id for that provider. \`turri --list-models <search>\` lists the ones it does; one of your own goes in ~/.pi/agent/models.json.`);
|
|
704
716
|
}
|
|
705
717
|
await session.setModel(model);
|
|
706
718
|
}
|
package/dist/plain/errors.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Ports of the exception classes
|
|
1
|
+
/** Ports of the exception classes of the Python reference implementation that this parser raises. */
|
|
2
2
|
export class PlainSyntaxError extends Error {
|
|
3
3
|
constructor(message) {
|
|
4
4
|
super(message);
|
package/dist/plain/files.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFileSync, statSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { createEnvironment } from "./liquid.js";
|
|
4
|
-
/** Ports of the
|
|
4
|
+
/** Ports of the Python reference implementation's file helpers this parser needs. */
|
|
5
5
|
export function openFrom(dirs, fileName) {
|
|
6
6
|
for (const dir of dirs) {
|
|
7
7
|
const fullPath = join(dir, fileName);
|
package/dist/plain/liquid.js
CHANGED
|
@@ -7,7 +7,7 @@ function currentScope() {
|
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* Leading indentation of the line the tag sits on, and whether that line is a
|
|
10
|
-
* comment. Ported from
|
|
10
|
+
* comment. Ported from the reference implementation's include node, which walks
|
|
11
11
|
* backwards from the tag to the start of its line.
|
|
12
12
|
*/
|
|
13
13
|
function scanLine(source, start) {
|
|
@@ -70,7 +70,7 @@ export function createEnvironment(options) {
|
|
|
70
70
|
" 2. The directory specified by --template-dir (if provided)\n" +
|
|
71
71
|
" 3. The built-in 'standard_template_library' directory\n");
|
|
72
72
|
}
|
|
73
|
-
//
|
|
73
|
+
// The reference implementation's loader: rstrip, then re-indent every line to match the
|
|
74
74
|
// include site. The rstrip is what stops a block-level include from ending
|
|
75
75
|
// the surrounding list.
|
|
76
76
|
const indented = templateSource.replace(/\s+$/, "").split("\n").join("\n" + " ".repeat(whitespaces));
|
|
@@ -84,6 +84,25 @@ export function describeUsage(usage) {
|
|
|
84
84
|
return usage.cost > 0 ? `${size} tok · $${usage.cost.toFixed(2)}` : `${size} tok`;
|
|
85
85
|
}
|
|
86
86
|
const store = new AsyncLocalStorage();
|
|
87
|
+
const modelListeners = new Set();
|
|
88
|
+
/** Hear of every model call, turn and compaction from now on. Returns what stops it. */
|
|
89
|
+
export function onModelEvent(listener) {
|
|
90
|
+
modelListeners.add(listener);
|
|
91
|
+
return () => modelListeners.delete(listener);
|
|
92
|
+
}
|
|
93
|
+
export function reportModelEvent(event) {
|
|
94
|
+
if (modelListeners.size === 0)
|
|
95
|
+
return;
|
|
96
|
+
const job = store.getStore()?.job?.id;
|
|
97
|
+
for (const listener of modelListeners) {
|
|
98
|
+
try {
|
|
99
|
+
listener(job !== undefined ? { ...event, job } : event);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
/* a listener that fails does not take the agent down */
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
87
106
|
export function withActivity(sink, run) {
|
|
88
107
|
return store.run(sink, run);
|
|
89
108
|
}
|
package/dist/regenerate/loop.js
CHANGED
|
@@ -89,6 +89,61 @@ function chainsFor(plainFile) {
|
|
|
89
89
|
function ownBuilt(entry) {
|
|
90
90
|
return (readRecord(entry.buildDir)?.[FUNCTIONAL_REQUIREMENTS] ?? []).length;
|
|
91
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* The functional specs of a spec's whole requires chain, completed or not, in the codebase each chain delivers: its
|
|
94
|
+
* furthest-built module's code - which holds the code of every module below it. A functional spec is completed when that
|
|
95
|
+
* codebase's code record, as last committed, holds it as the spec has it now - the same text, the linked files it uses
|
|
96
|
+
* holding the same, no definition it uses changed, not marked to regenerate again. A record moves only when a pulse
|
|
97
|
+
* lands, its unit tests passing (and its conformance tests, when they are on), so completed is landed and passing.
|
|
98
|
+
* The modules above the delivered codebase have nothing completed. One entry per chain; planning nothing, calling no model.
|
|
99
|
+
*/
|
|
100
|
+
export function functionalityCompletion(plainFile) {
|
|
101
|
+
return withParseCache(() => chainsFor(resolve(plainFile)).map((chain) => {
|
|
102
|
+
let delivered = -1;
|
|
103
|
+
chain.forEach((entry, index) => {
|
|
104
|
+
if (readRecord(entry.buildDir) !== null)
|
|
105
|
+
delivered = index;
|
|
106
|
+
});
|
|
107
|
+
const counts = chain.map((entry) => ({ module: entry.moduleName, specified: entry.frids.length, completed: 0, conformanceTested: 0, incomplete: [...entry.frids] }));
|
|
108
|
+
if (delivered === -1)
|
|
109
|
+
return { codebase: tipOf(chain).buildDir, modules: counts };
|
|
110
|
+
const codebase = chain.slice(0, delivered + 1);
|
|
111
|
+
const tip = tipOf(codebase);
|
|
112
|
+
const spec = chainSpec(codebase).tree;
|
|
113
|
+
const record = readRecord(tip.buildDir);
|
|
114
|
+
const changes = codeWork(record, spec);
|
|
115
|
+
// Its own: what the work loop would regenerate - new, changed, a concept it uses changed, or marked again.
|
|
116
|
+
const cases = casesOf(codeTree(record ?? {}), changes, { module: tip.moduleName });
|
|
117
|
+
const touched = new Set([...cases.add, ...cases.patch, ...cases.again].map((spec) => `${spec.module ?? tip.moduleName}:${spec.frid}`));
|
|
118
|
+
// The modules' below it: an item the record does not have as the spec has it.
|
|
119
|
+
for (const change of changes) {
|
|
120
|
+
if (change.section !== REQUIRED_FUNCTIONAL_SPECS || change.after === undefined)
|
|
121
|
+
continue;
|
|
122
|
+
try {
|
|
123
|
+
const item = JSON.parse(change.after);
|
|
124
|
+
if (item.module !== undefined && item.frid !== undefined)
|
|
125
|
+
touched.add(`${item.module}:${item.frid}`);
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
/* not an item */
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const specText = (module, frid) => {
|
|
132
|
+
const own = module === tip.moduleName;
|
|
133
|
+
const items = spec[own ? FUNCTIONAL_REQUIREMENTS : REQUIRED_FUNCTIONAL_SPECS] ?? [];
|
|
134
|
+
return (own ? items[Number(frid) - 1] : items.find((item) => item.module === module && item.frid === frid))?.markdown.trim();
|
|
135
|
+
};
|
|
136
|
+
codebase.forEach((entry, index) => {
|
|
137
|
+
const count = counts[index];
|
|
138
|
+
const completed = entry.frids.filter((frid) => !touched.has(`${entry.moduleName}:${frid}`));
|
|
139
|
+
const tested = (readRecord(conformanceDirFor(entry.moduleName, modulesRoot(projectDirOf(entry.plainFile))))?.[FUNCTIONAL_REQUIREMENTS] ?? []).filter((item) => item.frid !== undefined && item.markdown.trim() === specText(entry.moduleName, item.frid));
|
|
140
|
+
count.completed = completed.length;
|
|
141
|
+
count.conformanceTested = completed.filter((frid) => tested.some((item) => item.frid === frid)).length;
|
|
142
|
+
count.incomplete = entry.frids.filter((frid) => !completed.includes(frid));
|
|
143
|
+
});
|
|
144
|
+
return { codebase: tip.buildDir, modules: counts };
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
92
147
|
/** The modules of a chain to build: its furthest-built one, and those above it - or, none built, all of it. */
|
|
93
148
|
function toBuild(chain) {
|
|
94
149
|
let from = 0;
|
|
@@ -434,7 +489,7 @@ export function createWorkLoop(options) {
|
|
|
434
489
|
title: planned.title,
|
|
435
490
|
diff: shown.diff,
|
|
436
491
|
...(state.model !== undefined ? { model: state.model } : {}),
|
|
437
|
-
lanes: [...moduleLanes(tip.plainFile
|
|
492
|
+
lanes: [...moduleLanes(tip.plainFile)],
|
|
438
493
|
rerun: `turri regenerate ${relative(options.cwd, tip.plainFile) || basename(tip.plainFile)}`,
|
|
439
494
|
run: async (onDelta) => {
|
|
440
495
|
// The guardrail: a conformance job tests only code that is built - the code record, read as the job starts, has every functional spec it tests as it tests it.
|
|
@@ -1313,7 +1368,6 @@ export async function previewJobs(options) {
|
|
|
1313
1368
|
registry: createJobRegistry(),
|
|
1314
1369
|
cwd: options.cwd,
|
|
1315
1370
|
dryRun: true,
|
|
1316
|
-
...(options.buildDir !== undefined ? { buildDir: options.buildDir } : {}),
|
|
1317
1371
|
...(options.model !== undefined ? { modelFor: () => options.model } : {}),
|
|
1318
1372
|
...(options.plannerModel !== undefined ? { plannerModel: options.plannerModel } : {}),
|
|
1319
1373
|
...(options.steering !== undefined ? { steering: options.steering } : {}),
|
|
@@ -24,7 +24,7 @@ function alreadyImplemented(moduleName, own, required) {
|
|
|
24
24
|
* one another, the current module marked - and each tagged with its module and its id there. A codebase holds the
|
|
25
25
|
* functionalities of every module it is built on, and each module numbers its own from 1, so
|
|
26
26
|
* "functionality 1" alone is ambiguous: the first listed may be base's 1 and the next top's 3.
|
|
27
|
-
* (
|
|
27
|
+
* (the reference implementation's implemented functional requirements prompt section, as tags.)
|
|
28
28
|
*/
|
|
29
29
|
export function functionalitiesByModule(entries, currentModule, status) {
|
|
30
30
|
// In the order given: the bottom of the chain first. A regeneration in a later module's
|