@turri-dev/cli 0.1.3-next.f74e98a → 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.
- package/README.md +22 -1
- package/dist/ask.js +34 -15
- package/dist/cli-options.js +12 -6
- package/dist/config-edit.js +1 -0
- package/dist/config.js +5 -2
- package/dist/extension.js +97 -42
- package/dist/genome.js +1 -1
- package/dist/init-config.js +5 -0
- package/dist/loop-cli.js +13 -1
- package/dist/loop-tools.js +31 -12
- package/dist/pi-launch.js +5 -0
- package/dist/pi.js +76 -19
- package/dist/question-dialog.js +9 -3
- package/dist/questioning.js +1 -1
- package/dist/regenerate/activity.js +23 -0
- package/dist/regenerate/conform.js +5 -5
- package/dist/regenerate/conformance-agents.js +28 -8
- package/dist/regenerate/conformance.js +24 -10
- package/dist/regenerate/list-arguments.js +121 -0
- package/dist/regenerate/loop.js +137 -18
- package/dist/regenerate/notes.js +66 -17
- package/dist/regenerate/prompt.js +3 -1
- package/dist/regenerate/regenerate.js +16 -10
- package/dist/regenerate/regression.js +2 -1
- package/dist/regenerate/requires.js +55 -2
- package/dist/regenerate/self-check.js +13 -6
- package/dist/regenerate/side-panel.js +1 -1
- package/dist/regenerate/test-scripts.js +54 -10
- package/dist/regenerate/unit-review.js +12 -1
- package/dist/regenerate-cli.js +11 -5
- package/dist/release-tools.js +1 -1
- package/dist/resume-line.js +4 -0
- package/dist/review/live.js +2 -1
- package/dist/run-report.js +39 -1
- package/dist/spec-tools.js +10 -45
- package/docs/authoring-plain.md +12 -7
- package/docs/config.md +3 -2
- package/docs/headless.md +33 -3
- package/docs/installation.md +3 -0
- package/docs/regenerating.md +70 -20
- package/docs/skills-and-gates.md +5 -3
- package/docs/using.md +28 -14
- package/genome/rules/func-specs.md +1 -0
- package/genome/rules/project-model.md +5 -3
- package/genome/rules/turri-regeneration.md +76 -0
- package/genome/skills/bud/SKILL.md +67 -36
- package/genome/skills/bud/references/intent.md +4 -0
- package/genome/skills/refactor-module/SKILL.md +24 -2
- package/package.json +3 -3
- package/genome/skills/bud/references/checklist.md +0 -44
package/dist/regenerate/notes.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { basename, dirname, join } from "node:path";
|
|
2
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
3
3
|
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
4
4
|
import { Type } from "typebox";
|
|
5
5
|
import { reportActivity } from "./activity.js";
|
|
@@ -40,7 +40,6 @@ export const SECTIONS = {
|
|
|
40
40
|
where: "Where things are",
|
|
41
41
|
run: "How to build, run and test",
|
|
42
42
|
assumptions: "Assumptions",
|
|
43
|
-
gaps: "Spec gaps",
|
|
44
43
|
pitfalls: "Pitfalls",
|
|
45
44
|
pulses: "Pulses",
|
|
46
45
|
};
|
|
@@ -53,8 +52,13 @@ export function notesPath(buildDir) {
|
|
|
53
52
|
return join(buildDir, NOTES_FILE);
|
|
54
53
|
}
|
|
55
54
|
function empty() {
|
|
56
|
-
return { where: [], run: [], assumptions: [],
|
|
55
|
+
return { where: [], run: [], assumptions: [], pitfalls: [], pulses: [] };
|
|
57
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Sections the notes no longer have, their lines dropped as they are read: the spec gaps are the person's, reported
|
|
59
|
+
* with report_spec_gap - the choice made meanwhile is an assumption, which stays.
|
|
60
|
+
*/
|
|
61
|
+
const DROPPED = new Set(["spec gaps"]);
|
|
58
62
|
/** The notes, as lines per section. Lines under no known heading go to pitfalls, not lost. */
|
|
59
63
|
export function parseNotes(text) {
|
|
60
64
|
const notes = empty();
|
|
@@ -63,11 +67,12 @@ export function parseNotes(text) {
|
|
|
63
67
|
const line = raw.trim();
|
|
64
68
|
const heading = /^##\s+(.+)$/.exec(line);
|
|
65
69
|
if (heading) {
|
|
66
|
-
|
|
70
|
+
const named = heading[1].trim().toLowerCase();
|
|
71
|
+
section = DROPPED.has(named) ? undefined : (ORDER.find((key) => SECTIONS[key].toLowerCase() === named) ?? section ?? "pitfalls");
|
|
67
72
|
continue;
|
|
68
73
|
}
|
|
69
74
|
const item = /^[-*]\s+(.+)$/.exec(line);
|
|
70
|
-
if (item)
|
|
75
|
+
if (item && section !== undefined)
|
|
71
76
|
notes[section].push(item[1].trim());
|
|
72
77
|
}
|
|
73
78
|
return notes;
|
|
@@ -93,14 +98,14 @@ const GUIDANCE = [
|
|
|
93
98
|
`- ${SECTIONS.where}: entry points, layout, where each functionality and its tests live.`,
|
|
94
99
|
`- ${SECTIONS.run}: the commands that build, run and test it, and what had to be installed for them.`,
|
|
95
100
|
`- ${SECTIONS.assumptions}: what you assumed where the specification is silent - a format, a default, a`,
|
|
96
|
-
" choice it leaves open
|
|
97
|
-
"
|
|
98
|
-
|
|
99
|
-
"
|
|
100
|
-
" specification. One a line, as the question it leaves: \"What happens to a contact archived in HubSpot after it",
|
|
101
|
-
" was synced?\"",
|
|
101
|
+
" choice it leaves open - and the tests that assert it, when any do: \"A Dash drains Pulses at 1/s - asserted in",
|
|
102
|
+
" predators.test.ts, The Dash\". One no test asserts is written down all the same. Build on the assumptions",
|
|
103
|
+
" already there; change or remove one the moment the code or the specification shows it wrong - and the tests",
|
|
104
|
+
" it names with it.",
|
|
102
105
|
`- ${SECTIONS.pitfalls}: what went wrong and what fixed it, approaches that did not work.`,
|
|
103
106
|
`- ${SECTIONS.pulses}: written by turri as each pulse ends - read them, never write them.`,
|
|
107
|
+
"A behaviour you had to decide that the person would want to decide - not a detail of how - is not a note: report",
|
|
108
|
+
"it with report_spec_gap, with the assumption you made meanwhile.",
|
|
104
109
|
"Each line stands on its own, for someone who never saw your work. When and where it came from is added",
|
|
105
110
|
"to it for you - do not write it. Where two lines disagree, the later one is right: change the older one",
|
|
106
111
|
'rather than add a contradicting line. Leave a section with nothing new alone: "none" is not a note.',
|
|
@@ -232,7 +237,7 @@ export function createNotesTool(buildDir, onWrite, before = () => { }, source) {
|
|
|
232
237
|
label: "Update notes",
|
|
233
238
|
description: "Update the working notes on this codebase for the next agent - add a line, change one that is no longer " +
|
|
234
239
|
"true, remove one that is wrong - in its sections: where things are, how to build, run and test, " +
|
|
235
|
-
"assumptions made where the specification is silent,
|
|
240
|
+
"assumptions made where the specification is silent, and pitfalls. Never " +
|
|
236
241
|
"requirements: the specification is never an assumption.",
|
|
237
242
|
promptSnippet: "leave the next agent what you learned and assumed about this codebase",
|
|
238
243
|
parameters: Type.Object({
|
|
@@ -283,7 +288,7 @@ export function sectionNamed(name) {
|
|
|
283
288
|
/** How many times an agent that finishes without update_notes is asked to call it. */
|
|
284
289
|
export const NOTES_ASKS = 3;
|
|
285
290
|
/** The turn that asks for the notes: update_notes is the only tool it may use - the work it follows is done. */
|
|
286
|
-
export const NOTES_TURN = { onlyTools: ["update_notes"] };
|
|
291
|
+
export const NOTES_TURN = { onlyTools: ["update_notes", "report_spec_gap"] };
|
|
287
292
|
/** What the notes turn says first, once the harness's own run of `script` has passed on the work. */
|
|
288
293
|
export function passedOutcome(script) {
|
|
289
294
|
return (`The harness ran the project's ${script} on your work itself, and it passed: your work is done and accepted. ` +
|
|
@@ -327,10 +332,53 @@ export function recordPulse(buildDir, text, source) {
|
|
|
327
332
|
// The notes are a help, not the work.
|
|
328
333
|
}
|
|
329
334
|
}
|
|
330
|
-
/**
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
335
|
+
/** Every spec gap reported in this process, with the codebase it was met in: a pulse reads those since it started. */
|
|
336
|
+
const reportedGaps = [];
|
|
337
|
+
/** Where the spec gaps stand now: what `gapsSince` reads from. */
|
|
338
|
+
export function gapMark() {
|
|
339
|
+
return reportedGaps.length;
|
|
340
|
+
}
|
|
341
|
+
/** The spec gaps reported in these codebases since `mark`. */
|
|
342
|
+
export function gapsSince(mark, dirs) {
|
|
343
|
+
const wanted = new Set(dirs.map((dir) => resolve(dir)));
|
|
344
|
+
return reportedGaps.slice(mark).filter((entry) => wanted.has(entry.dir)).map((entry) => entry.gap);
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* `report_spec_gap`: a behaviour the specification leaves open that the person would want to decide, put to them as
|
|
348
|
+
* the pulse ends - never into the notes, which are the next agent's. What the agent decided meanwhile goes into the
|
|
349
|
+
* notes' assumptions, so the code built on it is known for what it is until the specification settles it.
|
|
350
|
+
*/
|
|
351
|
+
export function createSpecGapTool(buildDir, source) {
|
|
352
|
+
return defineTool({
|
|
353
|
+
name: "report_spec_gap",
|
|
354
|
+
label: "Report a spec gap",
|
|
355
|
+
description: "Report a spec gap: a behaviour the specification leaves open that the person would want to decide - not a detail " +
|
|
356
|
+
"of how. Decide it meanwhile and carry on: the person is asked once the work ends, and what they decide is " +
|
|
357
|
+
"written into the specification. The assumption you made is added to the notes' assumptions for you.",
|
|
358
|
+
promptSnippet: "tell the person about a behaviour the specification leaves open, and what you decided meanwhile",
|
|
359
|
+
parameters: Type.Object({
|
|
360
|
+
question: Type.String({ description: 'The question it leaves the person, one line: "What happens to a contact archived in HubSpot after it was synced?"' }),
|
|
361
|
+
assumption: Type.String({
|
|
362
|
+
description: "What you decided meanwhile, as its line in the notes' assumptions - with the tests that assert it, when any do: " +
|
|
363
|
+
'"An archived contact is left as synced - asserted in sync.test.ts, archived contacts".',
|
|
364
|
+
}),
|
|
365
|
+
}),
|
|
366
|
+
async execute(_id, params) {
|
|
367
|
+
const question = params.question.replace(/\s+/g, " ").trim();
|
|
368
|
+
const assumption = params.assumption.replace(/\s+/g, " ").trim();
|
|
369
|
+
if (question === "" || assumption === "")
|
|
370
|
+
throw new Error("Nothing reported - a spec gap needs both the question it leaves and the assumption you made meanwhile.");
|
|
371
|
+
// However many there are, spec gaps are put to the person - never a reason to stop the pulse.
|
|
372
|
+
reportedGaps.push({ dir: resolve(buildDir), gap: { question, assumption } });
|
|
373
|
+
const known = readNotes(buildDir).assumptions.some((line) => body(line) === assumption);
|
|
374
|
+
if (!known)
|
|
375
|
+
recordNote(buildDir, "assumptions", assumption, source ?? "spec gap");
|
|
376
|
+
return {
|
|
377
|
+
content: [{ type: "text", text: `Reported. The assumption is in the notes' assumptions${known ? " already" : " now"} - do not add it again.` }],
|
|
378
|
+
details: { question, assumption },
|
|
379
|
+
};
|
|
380
|
+
},
|
|
381
|
+
});
|
|
334
382
|
}
|
|
335
383
|
/** The notes, for an agent that reads them but leaves none - a judge. Empty when there are none. */
|
|
336
384
|
export function notesToRead(buildDir) {
|
|
@@ -367,6 +415,7 @@ export function notesForSession(buildDir, source) {
|
|
|
367
415
|
return true;
|
|
368
416
|
};
|
|
369
417
|
return {
|
|
418
|
+
gapTool: createSpecGapTool(buildDir, source),
|
|
370
419
|
tool: createNotesTool(buildDir, (text) => {
|
|
371
420
|
written = true;
|
|
372
421
|
knownNotes.set(file, text);
|
|
@@ -278,8 +278,10 @@ function itemText(serialized) {
|
|
|
278
278
|
return item;
|
|
279
279
|
const { markdown, [ACCEPTANCE_TESTS]: tests } = (item ?? {});
|
|
280
280
|
const lines = [markdown ?? JSON.stringify(item)];
|
|
281
|
+
// Each test is an item of the tree, its text in its markdown - as spec-steps.ts `itemText` reads it.
|
|
282
|
+
const testText = (test) => (typeof test === "string" ? test : (test?.markdown ?? JSON.stringify(test)));
|
|
281
283
|
if (Array.isArray(tests) && tests.length > 0)
|
|
282
|
-
lines.push(" <acceptance tests>", ...tests.map((test) => ` ${
|
|
284
|
+
lines.push(" <acceptance tests>", ...tests.map((test) => ` ${testText(test).replace(/\n/g, "\n ")}`), " </acceptance tests>");
|
|
283
285
|
return lines.join("\n");
|
|
284
286
|
}
|
|
285
287
|
const indent = (text, by) => text.split("\n").map((line) => `${by}${line}`).join("\n");
|
|
@@ -14,7 +14,7 @@ import { buildSpecDiffPrompt, describeSpecChange, reviewedSpec, sectionModules }
|
|
|
14
14
|
import { abandonWork, recordHistory, startWork } from "./lineage.js";
|
|
15
15
|
import { createWorkLedger, SUBMIT_WORK_NOTE } from "./submit-work.js";
|
|
16
16
|
import { CODER_COMPACTION } from "./compaction.js";
|
|
17
|
-
import {
|
|
17
|
+
import { gapMark, gapsSince, NOTES_TURN, notesForSession, passedOutcome, recordNote, withNotes } from "./notes.js";
|
|
18
18
|
import { createLoopWatch, createScriptTool, failureSignature, findTestScripts, projectRootFor, requireTestScripts, runUnitScript, STUCK_ROUNDS, withoutConformance, withTestingScripts, } from "./test-scripts.js";
|
|
19
19
|
import { createWebTools, WEB_TOOLS } from "./web.js";
|
|
20
20
|
import { createCanItFailTool, createMyDiffTool, selfCheckNote } from "./self-check.js";
|
|
@@ -268,8 +268,8 @@ export async function renderSpecDiff(options) {
|
|
|
268
268
|
...(options.cases !== undefined ? { cases: options.cases } : {}),
|
|
269
269
|
});
|
|
270
270
|
const digestsBefore = digestFiles(buildDir);
|
|
271
|
-
// The
|
|
272
|
-
const
|
|
271
|
+
// The spec gaps its agents report from here on are told with the result.
|
|
272
|
+
const gapsFrom = gapMark();
|
|
273
273
|
/** What the debugger found, each time it was asked: the pulse's line in the notes says it. */
|
|
274
274
|
const diagnosed = [];
|
|
275
275
|
const runs = [];
|
|
@@ -281,9 +281,11 @@ export async function renderSpecDiff(options) {
|
|
|
281
281
|
const work = createWorkLedger();
|
|
282
282
|
// What it checks its own work with: the diff its reviewer is shown, and whether a test catches a bug - neither decides anything.
|
|
283
283
|
const gate = createUnitGate(buildDir, scripts.unit);
|
|
284
|
+
// can_it_fail, for the coding agent and its reviewer: on unless mutation-testing says otherwise.
|
|
285
|
+
const mutationTesting = scripts.unit !== undefined && configForSpec(tip.plainFile).mutationTesting !== false;
|
|
284
286
|
const selfChecks = [
|
|
285
287
|
createMyDiffTool({ dir: buildDir, what: "code" }),
|
|
286
|
-
...(
|
|
288
|
+
...(mutationTesting ? [createCanItFailTool({ buildDir, script: scripts.unit })] : []),
|
|
287
289
|
];
|
|
288
290
|
// A server it built, it can start and try from outside - stopped when it is done.
|
|
289
291
|
const services = createServiceTools({ dir: buildDir });
|
|
@@ -305,6 +307,7 @@ export async function renderSpecDiff(options) {
|
|
|
305
307
|
cwd: buildDir,
|
|
306
308
|
customTools: [
|
|
307
309
|
notes.tool,
|
|
310
|
+
notes.gapTool,
|
|
308
311
|
work.tool,
|
|
309
312
|
...createWebTools(),
|
|
310
313
|
createScriptTool({ kind: "unit", script: scripts.unit, run: () => runUnitScript(buildDir, scripts.unit), runs, watch: loop }),
|
|
@@ -313,7 +316,7 @@ export async function renderSpecDiff(options) {
|
|
|
313
316
|
...fence.tools,
|
|
314
317
|
createCopyResourceTool({ resources: linkedResources, dir: buildDir }),
|
|
315
318
|
],
|
|
316
|
-
tools: [...fence.names, "run_unit_tests", ...selfChecks.map((tool) => tool.name), ...services.names, "update_notes", "submit_work", "copy_resource", ...WEB_TOOLS],
|
|
319
|
+
tools: [...fence.names, "run_unit_tests", ...selfChecks.map((tool) => tool.name), ...services.names, "update_notes", "report_spec_gap", "submit_work", "copy_resource", ...WEB_TOOLS],
|
|
317
320
|
model: options.model,
|
|
318
321
|
label: `${moduleName} spec change coding agent`,
|
|
319
322
|
role: "coding",
|
|
@@ -498,7 +501,8 @@ export async function renderSpecDiff(options) {
|
|
|
498
501
|
forChange: true,
|
|
499
502
|
...(options.cases !== undefined ? { cases: options.cases } : {}),
|
|
500
503
|
label: `${moduleName} spec change`,
|
|
501
|
-
...(
|
|
504
|
+
...(mutationTesting ? { unitScript: scripts.unit } : {}),
|
|
505
|
+
testingScript: { path: relative(root, scripts.unit), content: readFileSync(scripts.unit, "utf8") },
|
|
502
506
|
model: options.judgeModel ?? modelSpec(inheritModel(configForSpec(tip.plainFile).judgeModel, modelOnly(options.model))),
|
|
503
507
|
send: async (next) => {
|
|
504
508
|
response = await ask(executor, next, options.onDelta);
|
|
@@ -541,8 +545,8 @@ export async function renderSpecDiff(options) {
|
|
|
541
545
|
testRemovals,
|
|
542
546
|
files,
|
|
543
547
|
...(steering !== undefined && steering.steers > 0 ? { steered: [...steering.notes] } : {}),
|
|
544
|
-
//
|
|
545
|
-
specGaps:
|
|
548
|
+
// A gap the agent met is the person's to decide, whether it landed or not.
|
|
549
|
+
specGaps: gapsSince(gapsFrom, [buildDir]),
|
|
546
550
|
diagnosed,
|
|
547
551
|
};
|
|
548
552
|
/** The change landed: what the code is built from is now the spec with the change in, committed with it. */
|
|
@@ -579,8 +583,10 @@ export function specGapsText(gaps) {
|
|
|
579
583
|
return [];
|
|
580
584
|
return [
|
|
581
585
|
"",
|
|
582
|
-
"Spec gaps its agents met - the spec does not say, so they decided
|
|
583
|
-
|
|
586
|
+
"Spec gaps its agents met - the spec does not say, so they decided, each as an assumption in the codebase's notes. Put " +
|
|
587
|
+
"each to the user, and write the ones they decide into the spec - the pulse that builds it is told the assumption " +
|
|
588
|
+
"it replaces:",
|
|
589
|
+
...gaps.map((gap) => `- ${gap.question} Meanwhile: ${gap.assumption}`),
|
|
584
590
|
];
|
|
585
591
|
}
|
|
586
592
|
/** What a rendered spec change did, for the agent and the person. */
|
|
@@ -21,7 +21,7 @@ import { keepingTestsUnchanged, listFiles } from "./testing.js";
|
|
|
21
21
|
* job ends on it: tests that pass on their own are not done until the whole suite passes with them.
|
|
22
22
|
*/
|
|
23
23
|
/** On top of the file tools, which are fenced to the build directory by `confine.ts`. */
|
|
24
|
-
const FIX_TOOLS = ["run_unit_tests", "run_conformance_tests", "update_notes"];
|
|
24
|
+
const FIX_TOOLS = ["run_unit_tests", "run_conformance_tests", "update_notes", "report_spec_gap"];
|
|
25
25
|
const DEFAULT_MAX_REGRESSION_ROUNDS = ATTEMPTS.regression;
|
|
26
26
|
/** The module's conformance tests, when there are any: the chain's, copied up, and its own. */
|
|
27
27
|
function conformanceDirs(conformanceRoot, moduleName) {
|
|
@@ -39,6 +39,7 @@ async function repairRegression(input) {
|
|
|
39
39
|
cwd: input.buildDir,
|
|
40
40
|
customTools: [
|
|
41
41
|
notes.tool,
|
|
42
|
+
notes.gapTool,
|
|
42
43
|
...createWebTools(),
|
|
43
44
|
...fence.tools,
|
|
44
45
|
createScriptTool({ kind: "unit", script: input.scripts.unit, run: () => runUnitScript(input.buildDir, input.scripts.unit), runs }),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { copyFileSync, existsSync, mkdirSync, readdirSync, rmSync } from "node:fs";
|
|
1
|
+
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync } from "node:fs";
|
|
2
2
|
import { basename, dirname, join, resolve } from "node:path";
|
|
3
|
-
import { PLAIN_SOURCE_FILE_EXTENSION, plainFileParser, withParseCache } from "../plain/parser.js";
|
|
3
|
+
import { IMPORT_DIRECTIVE, PLAIN_SOURCE_FILE_EXTENSION, plainFileParser, readPlainSourceMetadata, withParseCache } from "../plain/parser.js";
|
|
4
4
|
import { getFrids, getInheritedFunctionalSpecs } from "../plain/spec.js";
|
|
5
5
|
import { buildDirUnder, modulesRoot, projectDirOf } from "./paths.js";
|
|
6
6
|
import { notesPath } from "./notes.js";
|
|
@@ -54,6 +54,59 @@ options = {}) {
|
|
|
54
54
|
visit(resolve(plainFile), []);
|
|
55
55
|
return chain;
|
|
56
56
|
}
|
|
57
|
+
/** The .plain files that import `plainFile` - read from beside it, and, kept in a `template/` folder, from the folder it is in. */
|
|
58
|
+
function importersOf(plainFile) {
|
|
59
|
+
const file = resolve(plainFile);
|
|
60
|
+
const dir = dirname(file);
|
|
61
|
+
const name = basename(file, PLAIN_SOURCE_FILE_EXTENSION);
|
|
62
|
+
const dirs = [dir, ...(basename(dir) === "template" ? [dirname(dir)] : [])];
|
|
63
|
+
return dirs.flatMap((at) => {
|
|
64
|
+
let names;
|
|
65
|
+
try {
|
|
66
|
+
names = readdirSync(at).filter((entry) => entry.endsWith(PLAIN_SOURCE_FILE_EXTENSION));
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
return names
|
|
72
|
+
.map((entry) => join(at, entry))
|
|
73
|
+
.filter((path) => {
|
|
74
|
+
if (path === file || !resolveTemplateDirs(path).includes(dir))
|
|
75
|
+
return false;
|
|
76
|
+
try {
|
|
77
|
+
return (readPlainSourceMetadata(readFileSync(path, "utf8")).metadata[IMPORT_DIRECTIVE] ?? []).includes(name);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Whether a .plain file is an import module - one a .plain file imports, or one kept in a `template/` folder - rather than
|
|
87
|
+
* a module of its own. It is no codebase: its reqs and definitions are built in the modules that import it.
|
|
88
|
+
*/
|
|
89
|
+
export function isImportModule(plainFile) {
|
|
90
|
+
return basename(dirname(resolve(plainFile))) === "template" || importersOf(plainFile).length > 0;
|
|
91
|
+
}
|
|
92
|
+
/** The modules of their own that import an import module, through any import modules between. */
|
|
93
|
+
export function importingModules(plainFile) {
|
|
94
|
+
const found = new Set();
|
|
95
|
+
const seen = new Set();
|
|
96
|
+
const walk = (file) => {
|
|
97
|
+
if (seen.has(file))
|
|
98
|
+
return;
|
|
99
|
+
seen.add(file);
|
|
100
|
+
for (const importer of importersOf(file)) {
|
|
101
|
+
if (isImportModule(importer))
|
|
102
|
+
walk(importer);
|
|
103
|
+
else
|
|
104
|
+
found.add(importer);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
walk(resolve(plainFile));
|
|
108
|
+
return [...found];
|
|
109
|
+
}
|
|
57
110
|
/**
|
|
58
111
|
* The codebase a change to `plainFile`'s module lands in: the furthest-built module whose
|
|
59
112
|
* requires chain includes it, with that chain.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { readFileSync
|
|
2
|
-
import {
|
|
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
|
-
|
|
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
|
|
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",
|
|
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() ? [
|
|
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
|
-
*
|
|
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
|
-
|
|
414
|
-
|
|
415
|
-
|
|
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
|
|
468
|
+
if (change !== undefined)
|
|
469
|
+
writeFileSync(join(staging.build, change.file), change.text);
|
|
423
470
|
const started = Date.now();
|
|
424
|
-
|
|
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 });
|
|
@@ -63,6 +63,17 @@ export function unitReviewTask(options) {
|
|
|
63
63
|
options.spec.trim(),
|
|
64
64
|
"</specification>",
|
|
65
65
|
"",
|
|
66
|
+
...(options.testingScript !== undefined
|
|
67
|
+
? [
|
|
68
|
+
"The harness runs the unit tests with this script, and it decides whether they pass. Read it for which tests it",
|
|
69
|
+
"runs and how: a test it never reaches - a file it does not pick up, a folder it does not look in - is not run, and",
|
|
70
|
+
"checks nothing.",
|
|
71
|
+
`<unit testing script path="${options.testingScript.path}">`,
|
|
72
|
+
options.testingScript.content.trimEnd(),
|
|
73
|
+
"</unit testing script>",
|
|
74
|
+
"",
|
|
75
|
+
]
|
|
76
|
+
: []),
|
|
66
77
|
...(options.cases !== undefined ? [...codeReviewCasesBlock(options.cases), ""] : []),
|
|
67
78
|
// A job that touches no functional spec is held only to that: the checks of behaviour are not its.
|
|
68
79
|
...(mechanical ? [] : ["Check that the code does what the specification states for this work:"]),
|
|
@@ -85,7 +96,7 @@ export function unitReviewTask(options) {
|
|
|
85
96
|
" assertion so loose any answer passes, an expected value computed the way the code computes it.",
|
|
86
97
|
...(options.canItFail === true
|
|
87
98
|
? [
|
|
88
|
-
"- A test you doubt can fail, check: can_it_fail puts a bug in
|
|
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",
|
|
89
100
|
" value changed - and runs the unit tests on it. A test that still passes cannot fail: raise it as bad, with the",
|
|
90
101
|
` bug it missed. ${REVIEWER_CAN_IT_FAIL_RUNS} runs a session: spend them on the tests the work rests on.`,
|
|
91
102
|
]
|
package/dist/regenerate-cli.js
CHANGED
|
@@ -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 (
|
|
45
|
-
console.error(
|
|
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
|
-
:
|
|
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);
|
package/dist/release-tools.js
CHANGED
|
@@ -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"];
|
package/dist/review/live.js
CHANGED
|
@@ -79,7 +79,8 @@ export function createLiveReviewer(opts) {
|
|
|
79
79
|
pending.push(finding);
|
|
80
80
|
all.push(finding);
|
|
81
81
|
}
|
|
82
|
-
|
|
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) {
|