@llm4ts/shell 4.9.0 → 4.11.0
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/flows/epic-stories.js +6 -0
- package/flows/lib/debt.js +33 -12
- package/flows/lib/epic-mvp.js +8 -121
- package/flows/lib/epic-stories.js +47 -3
- package/flows/lib/red-phase.js +191 -0
- package/package.json +4 -4
package/flows/epic-stories.js
CHANGED
|
@@ -25,6 +25,12 @@
|
|
|
25
25
|
// (shape kept, content removed) rather than deleting them (ADR 0025).
|
|
26
26
|
// With --defer-tests the judge's tests score is never a finding and what it
|
|
27
27
|
// excused is written to debt.md; --harden plans that debt (ADR 0045).
|
|
28
|
+
// Test-first by default (ADR 0053): before a story's tasks are planned, its
|
|
29
|
+
// coder writes one test per acceptance criterion, the test gate proves them
|
|
30
|
+
// red, and they are frozen; --no-test-first (LLM4TS_TEST_FIRST=off) skips it.
|
|
31
|
+
// A story its last round would fail gets one rescue turn by the judge's
|
|
32
|
+
// agent, with write access, before it fails (ADR 0054); --no-rescue
|
|
33
|
+
// (LLM4TS_RESCUE=off) fails it at once.
|
|
28
34
|
import * as Effect from "effect/Effect";
|
|
29
35
|
import { runFlowMain } from "@llm4ts/runner";
|
|
30
36
|
import { epicStoriesOptions, parseStoriesFlags } from "./lib/debt.js";
|
package/flows/lib/debt.js
CHANGED
|
@@ -7,8 +7,10 @@ import { Info } from "@llm4ts/flow/FlowEvents";
|
|
|
7
7
|
import { countNotPlanned } from "@llm4ts/flow/RefineRound";
|
|
8
8
|
import { settingValue } from "@llm4ts/flow/Settings";
|
|
9
9
|
import { lastStoryVerdict } from "@llm4ts/flow/Stories";
|
|
10
|
+
import { evidenceSourceFromEnvironment } from "@llm4ts/flow/TestEvidence";
|
|
10
11
|
import { ScriptUsage } from "@llm4ts/runner";
|
|
11
12
|
import { deferringTestsJudge, epicUsage, loadRounds, rubricStoryJudge, unitStateDirs } from "./epic-stories.js";
|
|
13
|
+
import { storiesTestFirst } from "./red-phase.js";
|
|
12
14
|
// ---- The debt ---------------------------------------------------------------
|
|
13
15
|
export const counted = (count, one, many) => `${count} ${count === 1 ? one : many}`;
|
|
14
16
|
/** What a unit deferred: the tests owed, the findings, the test gate it skipped. */
|
|
@@ -117,16 +119,35 @@ export const parseStoriesFlags = (argv, environment) => Effect.gen(function* ()
|
|
|
117
119
|
message: `--harden pays the debt under the full bar; it does not take --defer-tests (or LLM4TS_DEFER_TESTS)\n${epicUsage}`
|
|
118
120
|
});
|
|
119
121
|
}
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
+
const testFirst = !argv.includes("--no-test-first") &&
|
|
123
|
+
settingValue("LLM4TS_TEST_FIRST", environment) &&
|
|
124
|
+
!deferTests &&
|
|
125
|
+
!harden;
|
|
126
|
+
const rescue = !argv.includes("--no-rescue") && settingValue("LLM4TS_RESCUE", environment);
|
|
127
|
+
const ours = new Set(["--defer-tests", "--harden", "--no-test-first", "--no-rescue"]);
|
|
128
|
+
const rest = argv.filter((arg) => !ours.has(arg));
|
|
129
|
+
return {
|
|
130
|
+
deferTests,
|
|
131
|
+
harden,
|
|
132
|
+
testFirst,
|
|
133
|
+
rescue,
|
|
134
|
+
testEvidence: evidenceSourceFromEnvironment(environment),
|
|
135
|
+
argv: harden ? ["--refine", ...rest] : rest
|
|
136
|
+
};
|
|
122
137
|
});
|
|
123
|
-
/** epic-stories' policy for its flags: the rubric judge, excusing tests, or hardening. */
|
|
124
|
-
export const epicStoriesOptions = (flags) =>
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
138
|
+
/** epic-stories' policy for its flags: the rubric judge, excusing tests, or hardening; then the rescue. */
|
|
139
|
+
export const epicStoriesOptions = (flags) => {
|
|
140
|
+
const policy = flags.harden
|
|
141
|
+
? hardenOptions
|
|
142
|
+
: flags.deferTests
|
|
143
|
+
? {
|
|
144
|
+
storyJudge: deferringTestsJudge,
|
|
145
|
+
stories: () => ({ judgeBar: "defer-tests" }),
|
|
146
|
+
afterUnit: testsDebtAfterUnit
|
|
147
|
+
}
|
|
148
|
+
: {
|
|
149
|
+
storyJudge: rubricStoryJudge,
|
|
150
|
+
...(flags.testFirst ? { stories: storiesTestFirst(flags.testEvidence) } : {})
|
|
151
|
+
};
|
|
152
|
+
return flags.rescue ? { ...policy, rescue: true } : policy;
|
|
153
|
+
};
|
package/flows/lib/epic-mvp.js
CHANGED
|
@@ -9,19 +9,18 @@ import { join } from "node:path";
|
|
|
9
9
|
import * as Effect from "effect/Effect";
|
|
10
10
|
import * as Option from "effect/Option";
|
|
11
11
|
import * as Schema from "effect/Schema";
|
|
12
|
-
import {
|
|
13
|
-
import { FlowAborted, StoryFailed, StoryPlanInvalid } from "@llm4ts/flow/FlowError";
|
|
12
|
+
import { FlowAborted, StoryPlanInvalid } from "@llm4ts/flow/FlowError";
|
|
14
13
|
import { CriterionChecked, Info, Parked } from "@llm4ts/flow/FlowEvents";
|
|
15
14
|
import { loadVersioned } from "@llm4ts/flow/Persistence";
|
|
16
15
|
import { Plan, Task } from "@llm4ts/flow/Plan";
|
|
17
|
-
import { correctnessReviewer
|
|
18
|
-
import { Reviewer } from "@llm4ts/flow/Reviewer";
|
|
16
|
+
import { correctnessReviewer } from "@llm4ts/flow/Review";
|
|
19
17
|
import { RedTests, RedTestsVersion, redTestsPath } from "@llm4ts/flow/Stories";
|
|
20
18
|
import { Story, StoryPlan } from "@llm4ts/flow/StoryPlan";
|
|
21
|
-
import {
|
|
19
|
+
import { criterionTags, evidenceSourceFromEnvironment } from "@llm4ts/flow/TestEvidence";
|
|
22
20
|
import { structuredAndPublish } from "@llm4ts/flow/Usage";
|
|
23
|
-
import {
|
|
21
|
+
import { ScriptUsage } from "@llm4ts/runner";
|
|
24
22
|
import { storyJsonSchema, storyPlanInstructions, unitStateDirs } from "./epic-stories.js";
|
|
23
|
+
import { evidenceAt, redPhaseOf } from "./red-phase.js";
|
|
25
24
|
export const parseMvpFlags = (argv) => {
|
|
26
25
|
const iterate = argv.includes("--iterate");
|
|
27
26
|
const review = argv.includes("--review");
|
|
@@ -118,124 +117,12 @@ export const evidenceRequired = [
|
|
|
118
117
|
export const mvpPreflight = (environment) => evidenceSourceFromEnvironment(environment) === undefined
|
|
119
118
|
? Effect.fail(ScriptUsage.make({ message: evidenceRequired }))
|
|
120
119
|
: Effect.void;
|
|
121
|
-
/**
|
|
122
|
-
* The status of each tag in a checkout. `written(tag)` says the test sources
|
|
123
|
-
* carry it, so a tag a report does not show (a suite that cannot load yet)
|
|
124
|
-
* reads red rather than missing.
|
|
125
|
-
*/
|
|
126
|
-
export const evidenceAt = (source, unit, workDir, tags, written, events,
|
|
127
|
-
/** The checkout's uncommitted paths, to refuse a report git would commit. */
|
|
128
|
-
uncommitted) => Effect.gen(function* () {
|
|
129
|
-
const appRoot = join(workDir, unit.appDir);
|
|
130
|
-
const statuses = new Map();
|
|
131
|
-
if (source._tag === "Report") {
|
|
132
|
-
if (unit.testGate === undefined) {
|
|
133
|
-
return yield* FlowAborted.make({
|
|
134
|
-
message: `LLM4TS_TEST_REPORT is set but the gates name no test command to write it`
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
const report = join(appRoot, source.path);
|
|
138
|
-
yield* unit.files.remove(report);
|
|
139
|
-
// Red is the point of a red phase: the gate's verdict is read from the report.
|
|
140
|
-
yield* unit.testGate(workDir, events);
|
|
141
|
-
const cases = parseJUnit((yield* unit.files.read(report)) ?? "");
|
|
142
|
-
// A report git can see would be committed by a story and dirty the
|
|
143
|
-
// epic checkout: it must be ignored, and it never outlives the read.
|
|
144
|
-
const relative = join(unit.appDir, source.path);
|
|
145
|
-
const visible = uncommitted === undefined ? false : (yield* uncommitted).includes(relative);
|
|
146
|
-
yield* unit.files.remove(report);
|
|
147
|
-
if (visible) {
|
|
148
|
-
return yield* FlowAborted.make({
|
|
149
|
-
message: `the test report ${relative} is not git-ignored: add it to .gitignore, then rerun`
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
for (const tag of tags) {
|
|
153
|
-
statuses.set(tag, statusFromReport(tag, cases, written(tag)));
|
|
154
|
-
}
|
|
155
|
-
return statuses;
|
|
156
|
-
}
|
|
157
|
-
for (const tag of tags) {
|
|
158
|
-
const result = yield* lintCommand(nodeProcessExecutor, events, commandFor(source.argv, tag), appRoot);
|
|
159
|
-
statuses.set(tag, result.isClean ? "green" : written(tag) ? "red" : "missing");
|
|
160
|
-
}
|
|
161
|
-
return statuses;
|
|
162
|
-
});
|
|
163
120
|
// ---- The red phase ----------------------------------------------------------
|
|
164
|
-
export const redTestsPrompt = (story, tags) => [
|
|
165
|
-
`Red phase of the story "${story.title}" (test-first). Write ONLY tests now — no production code.`,
|
|
166
|
-
"",
|
|
167
|
-
"For each outcome below, write one or more tests whose NAME contains its tag exactly, for",
|
|
168
|
-
'example it("[story-id#1] shows the balance", …). The tests assert the observable outcome and',
|
|
169
|
-
"MUST FAIL now, because the behaviour does not exist yet; importing a module the story will",
|
|
170
|
-
"create is fine. Put them in the story's owned test paths, beside the code they cover, in the",
|
|
171
|
-
"repository's test style. Do not commit. Once written, these tests are frozen: the",
|
|
172
|
-
"implementation will be judged by them alone.",
|
|
173
|
-
"",
|
|
174
|
-
...story.acceptance.map((outcome, index) => `${tags[index] ?? ""} ${outcome}`)
|
|
175
|
-
].join("\n");
|
|
176
|
-
/** The one lens on the red tests: do they pin down the outcomes, and only them. */
|
|
177
|
-
export const redTestsLens = Reviewer.make({
|
|
178
|
-
name: "red-tests",
|
|
179
|
-
systemPrompt: [
|
|
180
|
-
"You review tests written BEFORE the implementation, which will be the only check of it.",
|
|
181
|
-
"For each tagged outcome, check that its tests assert the outcome itself (not an",
|
|
182
|
-
"implementation detail), would fail on a wrong implementation, and cannot pass vacuously",
|
|
183
|
-
"(no assertion, a mocked subject, a hard-coded expectation). Report only those gaps, one",
|
|
184
|
-
"finding per gap, naming the tag. Production code is absent on purpose; never report that."
|
|
185
|
-
].join("\n"),
|
|
186
|
-
screen: "The tests leave an outcome unasserted, assert a detail, or could pass vacuously."
|
|
187
|
-
});
|
|
188
|
-
const tagsWritten = (files, workDir, paths) => Effect.map(Effect.forEach(paths, (path) => files.read(join(workDir, path))), (texts) => texts.filter((text) => text !== undefined).join("\n"));
|
|
189
121
|
/**
|
|
190
|
-
* The story's red phase
|
|
191
|
-
*
|
|
192
|
-
* outcome with no tagged test after one more turn fails the story; one
|
|
193
|
-
* whose tests already pass is parked as "check the outcome".
|
|
122
|
+
* The story's red phase under epic-mvp: per-test evidence, an outcome no
|
|
123
|
+
* test names fails the story, one green before implementation is parked.
|
|
194
124
|
*/
|
|
195
|
-
export const mvpRedPhase = (source, unit) => (
|
|
196
|
-
const git = seats.context.git;
|
|
197
|
-
const tags = criterionTags(story.id, story.acceptance);
|
|
198
|
-
const chat = yield* makeChat(seats.context.coder, { system, events, agent: "coder" });
|
|
199
|
-
yield* chat.ask(redTestsPrompt(story, tags));
|
|
200
|
-
const reviewer = seats.context.roster?.forRole("reviewer") ?? seats.context.reasoning;
|
|
201
|
-
const review = yield* reviewWith(reviewer, events, redTestsLens, `red tests: ${story.title}`, yield* git.diffAll);
|
|
202
|
-
if (!review.isClean) {
|
|
203
|
-
yield* chat.ask([
|
|
204
|
-
"A reviewer read your tests. Fix these gaps in the tests (still no production code):",
|
|
205
|
-
...review.issues.map((issue) => `- ${issue.title}: ${issue.description}`)
|
|
206
|
-
].join("\n"));
|
|
207
|
-
}
|
|
208
|
-
const check = Effect.gen(function* () {
|
|
209
|
-
const changed = testPaths(yield* git.uncommittedFiles);
|
|
210
|
-
const text = yield* tagsWritten(unit.files, workDir, changed);
|
|
211
|
-
const statuses = yield* evidenceAt(source, unit, workDir, tags, (tag) => text.includes(tag), events, git.uncommittedFiles);
|
|
212
|
-
return { changed, statuses };
|
|
213
|
-
});
|
|
214
|
-
let seen = yield* check;
|
|
215
|
-
const missing = () => tags.filter((tag) => seen.statuses.get(tag) === "missing");
|
|
216
|
-
if (missing().length > 0) {
|
|
217
|
-
yield* chat.ask(`No test names these outcomes yet: ${missing().join(", ")}. Write them, with the tag in the test name.`);
|
|
218
|
-
seen = yield* check;
|
|
219
|
-
}
|
|
220
|
-
if (missing().length > 0) {
|
|
221
|
-
return yield* StoryFailed.make({
|
|
222
|
-
story: story.id,
|
|
223
|
-
reason: `red phase: no test names ${missing().join(", ")}`
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
const parked = [];
|
|
227
|
-
for (const [index, tag] of tags.entries()) {
|
|
228
|
-
const status = seen.statuses.get(tag) ?? "missing";
|
|
229
|
-
yield* events.publish(CriterionChecked.make({ story: story.id, tag, status }));
|
|
230
|
-
if (status === "green") {
|
|
231
|
-
const item = `${tag} ${story.acceptance[index] ?? ""}`;
|
|
232
|
-
const reason = "its tests pass before implementation: check the outcome or its test";
|
|
233
|
-
parked.push(`${item} — ${reason}`);
|
|
234
|
-
yield* events.publish(Parked.make({ story: story.id, item, reason, mvp: false }));
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
return { frozen: seen.changed, parked };
|
|
238
|
-
});
|
|
125
|
+
export const mvpRedPhase = (source, unit) => redPhaseOf({ evidence: source, strict: true, park: true }, unit);
|
|
239
126
|
/** One green task per story: the tests are the plan. */
|
|
240
127
|
export const greenTaskPlan = (_seats, story, _prompt) => {
|
|
241
128
|
const tags = criterionTags(story.id, story.acceptance);
|
|
@@ -15,6 +15,7 @@ import { parseEpicBrief, renderEpicBrief, unanswered } from "@llm4ts/flow/EpicBr
|
|
|
15
15
|
import { structuredAndPublish } from "@llm4ts/flow/Usage";
|
|
16
16
|
import { EpicBriefInvalid, EpicBriefNotApproved, EpicCheckoutDirty, LandingFailed, RefineRefused } from "@llm4ts/flow/FlowError";
|
|
17
17
|
import { Info } from "@llm4ts/flow/FlowEvents";
|
|
18
|
+
import { testPaths } from "@llm4ts/flow/TestEvidence";
|
|
18
19
|
import { nodePreflight } from "@llm4ts/flow/NodePreflight";
|
|
19
20
|
import { applyApprovedRetros } from "@llm4ts/flow/Retro";
|
|
20
21
|
import { statusPaths } from "@llm4ts/flow/GitTool";
|
|
@@ -78,6 +79,12 @@ export const epicUsage = [
|
|
|
78
79
|
" excused are written to debt.md (the coder is still asked for tests;",
|
|
79
80
|
" a red test gate still fails). LLM4TS_DEFER_TESTS=1 sets it too",
|
|
80
81
|
" --harden plan the epic's open debt as a refine round under the full bar",
|
|
82
|
+
" --no-rescue fail a story its last review round leaves open; by default the",
|
|
83
|
+
" judge's agent first takes the coder's seat for one rescue turn, then",
|
|
84
|
+
" the gates and the judge decide (ADR 0054). LLM4TS_RESCUE=off sets it",
|
|
85
|
+
" --no-test-first plan a story's tasks straight from it; by default its coder first",
|
|
86
|
+
" writes one test per acceptance criterion, proves them red with the",
|
|
87
|
+
" test gate, and they are frozen (ADR 0053). LLM4TS_TEST_FIRST=off sets it",
|
|
81
88
|
"Seats: LLM4TS_REASONER (claude|gemini|…, default claude) splits, reviews, judges;",
|
|
82
89
|
" LLM4TS_CODER (default pi) implements; LLM4TS_REASONING_MODEL / LLM4TS_CODER_MODEL",
|
|
83
90
|
" pick their models (pi: provider/model); LLM4TS_CODER_FLAGS / LLM4TS_REASONING_FLAGS",
|
|
@@ -802,6 +809,9 @@ orientation) => [
|
|
|
802
809
|
"- A story fits one agent session: one screen, one contract, or one component.",
|
|
803
810
|
"- Every story OWNS the test files it must write (the judge asks for tests): list them",
|
|
804
811
|
" in `owned` explicitly — a story cannot add a test outside its owned paths.",
|
|
812
|
+
"- No story only writes tests: each story writes the tests of its own behaviour, and the",
|
|
813
|
+
' composition story tests only its wiring. Never plan a last story that "writes the tests"',
|
|
814
|
+
' or "tests and integrates" what other stories built.',
|
|
805
815
|
`- Use exactly this epicId: "${epicId}". Copy the epic text into "epic".`,
|
|
806
816
|
"",
|
|
807
817
|
"Respond only with JSON:",
|
|
@@ -820,9 +830,40 @@ export const generateStoryPlan = (reasoning, events, epic, epicId, guidance,
|
|
|
820
830
|
/** An approved epic brief (`epic-design`): what the planner reads in place of the sentence. */
|
|
821
831
|
brief,
|
|
822
832
|
/** The repository digest (`orientationFor`), so stories can name real paths. */
|
|
823
|
-
orientation) =>
|
|
824
|
-
|
|
825
|
-
|
|
833
|
+
orientation) => Effect.gen(function* () {
|
|
834
|
+
const prompt = `${storyPlanInstructions(epicId, guidance, orientation)}\n\nEpic:\n${brief ?? epic}`;
|
|
835
|
+
const ask = (text) => structuredAndPublish(reasoning, events, text, StoryPlan, storyPlanJsonSchema).pipe(
|
|
836
|
+
// The id and the epic text are ours, whatever the model echoed back.
|
|
837
|
+
Effect.map((plan) => StoryPlan.make({ ...plan, epicId, epic })));
|
|
838
|
+
const first = yield* ask(prompt);
|
|
839
|
+
const testOnly = testOnlyStories(first);
|
|
840
|
+
if (testOnly.length === 0) {
|
|
841
|
+
return first;
|
|
842
|
+
}
|
|
843
|
+
// Asked once more; a plan that keeps one is the operator's to edit (ADR 0053).
|
|
844
|
+
const second = yield* ask([
|
|
845
|
+
prompt,
|
|
846
|
+
"",
|
|
847
|
+
`Your previous plan had stories that only write tests: ${testOnly.join(", ")}.`,
|
|
848
|
+
"Plan again: move each test into the story whose behaviour it covers."
|
|
849
|
+
].join("\n"));
|
|
850
|
+
const still = testOnlyStories(second);
|
|
851
|
+
if (still.length > 0) {
|
|
852
|
+
yield* events.publish(Info.make({
|
|
853
|
+
message: `story plan: ${still.join(", ")} only write tests; move them into the stories they cover before running (edit plan.md)`
|
|
854
|
+
}));
|
|
855
|
+
}
|
|
856
|
+
return second;
|
|
857
|
+
});
|
|
858
|
+
/**
|
|
859
|
+
* Stories that own nothing but test files and are not test migrations: the
|
|
860
|
+
* catch-all "write the tests" story that test-first rules out (ADR 0053).
|
|
861
|
+
*/
|
|
862
|
+
export const testOnlyStories = (plan) => plan.stories
|
|
863
|
+
.filter((story) => !story.testsChange &&
|
|
864
|
+
story.owned.length > 0 &&
|
|
865
|
+
testPaths(story.owned).length === story.owned.length)
|
|
866
|
+
.map((story) => story.id);
|
|
826
867
|
/** The round planner's constraints: the story planner's, for feedback on finished work. */
|
|
827
868
|
export const refinePlanInstructions = (inputs) => [
|
|
828
869
|
"You are the orchestrator of a parallel implementation. The epic below is finished: every",
|
|
@@ -1527,6 +1568,8 @@ export const runEpicStories = (options) => Effect.gen(function* () {
|
|
|
1527
1568
|
coder,
|
|
1528
1569
|
reasoning,
|
|
1529
1570
|
reviewers: [asReadOnly(reasoning)],
|
|
1571
|
+
// The judge's agent, writable, for a story's rescue turn (ADR 0054).
|
|
1572
|
+
...(options.rescue === true ? { rescuer: reasoning } : {}),
|
|
1530
1573
|
environment: storiesEnvironment(process.env),
|
|
1531
1574
|
...runnerOptions
|
|
1532
1575
|
}, (context) => Effect.gen(function* () {
|
|
@@ -1853,6 +1896,7 @@ export const runEpicStories = (options) => Effect.gen(function* () {
|
|
|
1853
1896
|
concurrency,
|
|
1854
1897
|
...(deferring ? { deferNonBlocking: true } : {}),
|
|
1855
1898
|
failFast: flags.failFast,
|
|
1899
|
+
...(options.rescue === true ? { rescue: true } : {}),
|
|
1856
1900
|
...(options.stories === undefined ? {} : options.stories(unitContext(work)))
|
|
1857
1901
|
});
|
|
1858
1902
|
const summarize = (work, report) => events.publish(Info.make({
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// The red phase (ADR 0042, ADR 0053): before a story's tasks are planned,
|
|
2
|
+
// its coder writes tests for each acceptance criterion, one review round
|
|
3
|
+
// reads them, and the tests must fail. The executor commits them and freezes
|
|
4
|
+
// them. epic-mvp proves each criterion red with per-test evidence;
|
|
5
|
+
// epic-stories proves the story red with its test gate.
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
import { makeChat } from "@llm4ts/flow/Chat";
|
|
9
|
+
import { FlowAborted, StoryFailed } from "@llm4ts/flow/FlowError";
|
|
10
|
+
import { CriterionChecked, Info, Parked } from "@llm4ts/flow/FlowEvents";
|
|
11
|
+
import { lintCommand, reviewWith } from "@llm4ts/flow/Review";
|
|
12
|
+
import { Reviewer } from "@llm4ts/flow/Reviewer";
|
|
13
|
+
import { commandFor, criterionTags, parseJUnit, statusFromReport, testPaths } from "@llm4ts/flow/TestEvidence";
|
|
14
|
+
import { nodeProcessExecutor } from "@llm4ts/runner";
|
|
15
|
+
// ---- Evidence ---------------------------------------------------------------
|
|
16
|
+
/**
|
|
17
|
+
* The status of each tag in a checkout. `written(tag)` says the test sources
|
|
18
|
+
* carry it, so a tag a report does not show (a suite that cannot load yet)
|
|
19
|
+
* reads red rather than missing.
|
|
20
|
+
*/
|
|
21
|
+
export const evidenceAt = (source, unit, workDir, tags, written, events,
|
|
22
|
+
/** The checkout's uncommitted paths, to refuse a report git would commit. */
|
|
23
|
+
uncommitted) => Effect.gen(function* () {
|
|
24
|
+
const appRoot = join(workDir, unit.appDir);
|
|
25
|
+
const statuses = new Map();
|
|
26
|
+
if (source._tag === "Report") {
|
|
27
|
+
if (unit.testGate === undefined) {
|
|
28
|
+
return yield* FlowAborted.make({
|
|
29
|
+
message: `LLM4TS_TEST_REPORT is set but the gates name no test command to write it`
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const report = join(appRoot, source.path);
|
|
33
|
+
yield* unit.files.remove(report);
|
|
34
|
+
// Red is the point of a red phase: the gate's verdict is read from the report.
|
|
35
|
+
yield* unit.testGate(workDir, events);
|
|
36
|
+
const cases = parseJUnit((yield* unit.files.read(report)) ?? "");
|
|
37
|
+
// A report git can see would be committed by a story and dirty the
|
|
38
|
+
// epic checkout: it must be ignored, and it never outlives the read.
|
|
39
|
+
const relative = join(unit.appDir, source.path);
|
|
40
|
+
const visible = uncommitted === undefined ? false : (yield* uncommitted).includes(relative);
|
|
41
|
+
yield* unit.files.remove(report);
|
|
42
|
+
if (visible) {
|
|
43
|
+
return yield* FlowAborted.make({
|
|
44
|
+
message: `the test report ${relative} is not git-ignored: add it to .gitignore, then rerun`
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
for (const tag of tags) {
|
|
48
|
+
statuses.set(tag, statusFromReport(tag, cases, written(tag)));
|
|
49
|
+
}
|
|
50
|
+
return statuses;
|
|
51
|
+
}
|
|
52
|
+
for (const tag of tags) {
|
|
53
|
+
const result = yield* lintCommand(nodeProcessExecutor, events, commandFor(source.argv, tag), appRoot);
|
|
54
|
+
statuses.set(tag, result.isClean ? "green" : written(tag) ? "red" : "missing");
|
|
55
|
+
}
|
|
56
|
+
return statuses;
|
|
57
|
+
});
|
|
58
|
+
/**
|
|
59
|
+
* Without per-test evidence: the test gate's one verdict for every tag the
|
|
60
|
+
* tests carry. A failing gate reads red, a passing one green; with no test
|
|
61
|
+
* gate the tests are not run and a written tag reads red, unproven.
|
|
62
|
+
*/
|
|
63
|
+
export const gateEvidence = (unit, workDir, tags, written, events) => Effect.gen(function* () {
|
|
64
|
+
const verdict = unit.testGate === undefined
|
|
65
|
+
? "red"
|
|
66
|
+
: (yield* unit.testGate(workDir, events)).isClean
|
|
67
|
+
? "green"
|
|
68
|
+
: "red";
|
|
69
|
+
return new Map(tags.map((tag) => [tag, written(tag) ? verdict : "missing"]));
|
|
70
|
+
});
|
|
71
|
+
// ---- The red phase ----------------------------------------------------------
|
|
72
|
+
export const redTestsPrompt = (story, tags) => [
|
|
73
|
+
`Red phase of the story "${story.title}" (test-first). Write ONLY tests now — no production code.`,
|
|
74
|
+
"",
|
|
75
|
+
"For each outcome below, write one or more tests whose NAME contains its tag exactly, for",
|
|
76
|
+
'example it("[story-id#1] shows the balance", …). The tests assert the observable outcome and',
|
|
77
|
+
"MUST FAIL now, because the behaviour does not exist yet; importing a module the story will",
|
|
78
|
+
"create is fine. Put them in the story's owned test paths, beside the code they cover, in the",
|
|
79
|
+
"repository's test style. Do not commit. Once written, these tests are frozen: the",
|
|
80
|
+
"implementation will be judged by them alone.",
|
|
81
|
+
"",
|
|
82
|
+
...story.acceptance.map((outcome, index) => `${tags[index] ?? ""} ${outcome}`)
|
|
83
|
+
].join("\n");
|
|
84
|
+
/** The one lens on the red tests: do they pin down the outcomes, and only them. */
|
|
85
|
+
export const redTestsLens = Reviewer.make({
|
|
86
|
+
name: "red-tests",
|
|
87
|
+
systemPrompt: [
|
|
88
|
+
"You review tests written BEFORE the implementation, which will be the only check of it.",
|
|
89
|
+
"For each tagged outcome, check that its tests assert the outcome itself (not an",
|
|
90
|
+
"implementation detail), would fail on a wrong implementation, and cannot pass vacuously",
|
|
91
|
+
"(no assertion, a mocked subject, a hard-coded expectation). Report only those gaps, one",
|
|
92
|
+
"finding per gap, naming the tag. Production code is absent on purpose; never report that."
|
|
93
|
+
].join("\n"),
|
|
94
|
+
screen: "The tests leave an outcome unasserted, assert a detail, or could pass vacuously."
|
|
95
|
+
});
|
|
96
|
+
const tagsWritten = (files, workDir, paths) => Effect.map(Effect.forEach(paths, (path) => files.read(join(workDir, path))), (texts) => texts.filter((text) => text !== undefined).join("\n"));
|
|
97
|
+
/**
|
|
98
|
+
* The story's red phase: the coder writes tagged tests, one review round
|
|
99
|
+
* reads them, one fix turn answers it, then the tests are run. A criterion
|
|
100
|
+
* with no tagged test gets one more turn; one whose tests already pass is
|
|
101
|
+
* parked or noted, as the policy says. The changed test files are frozen.
|
|
102
|
+
*/
|
|
103
|
+
export const redPhaseOf = (policy, unit) => (story, seats, workDir, system, events) => Effect.gen(function* () {
|
|
104
|
+
const git = seats.context.git;
|
|
105
|
+
const tags = criterionTags(story.id, story.acceptance);
|
|
106
|
+
const chat = yield* makeChat(seats.context.coder, { system, events, agent: "coder" });
|
|
107
|
+
yield* chat.ask(redTestsPrompt(story, tags));
|
|
108
|
+
const reviewer = seats.context.roster?.forRole("reviewer") ?? seats.context.reasoning;
|
|
109
|
+
const review = yield* reviewWith(reviewer, events, redTestsLens, `red tests: ${story.title}`, yield* git.diffAll);
|
|
110
|
+
if (!review.isClean) {
|
|
111
|
+
yield* chat.ask([
|
|
112
|
+
"A reviewer read your tests. Fix these gaps in the tests (still no production code):",
|
|
113
|
+
...review.issues.map((issue) => `- ${issue.title}: ${issue.description}`)
|
|
114
|
+
].join("\n"));
|
|
115
|
+
}
|
|
116
|
+
const check = Effect.gen(function* () {
|
|
117
|
+
const changed = testPaths(yield* git.uncommittedFiles);
|
|
118
|
+
const text = yield* tagsWritten(unit.files, workDir, changed);
|
|
119
|
+
const written = (tag) => text.includes(tag);
|
|
120
|
+
const statuses = policy.evidence === undefined
|
|
121
|
+
? yield* gateEvidence(unit, workDir, tags, written, events)
|
|
122
|
+
: yield* evidenceAt(policy.evidence, unit, workDir, tags, written, events, git.uncommittedFiles);
|
|
123
|
+
return { changed, statuses };
|
|
124
|
+
});
|
|
125
|
+
let seen = yield* check;
|
|
126
|
+
const missing = () => tags.filter((tag) => seen.statuses.get(tag) === "missing");
|
|
127
|
+
if (missing().length > 0) {
|
|
128
|
+
yield* chat.ask(`No test names these outcomes yet: ${missing().join(", ")}. Write them, with the tag in the test name.`);
|
|
129
|
+
seen = yield* check;
|
|
130
|
+
}
|
|
131
|
+
if (missing().length > 0 && (policy.strict || seen.changed.length === 0)) {
|
|
132
|
+
return yield* StoryFailed.make({
|
|
133
|
+
story: story.id,
|
|
134
|
+
reason: policy.strict
|
|
135
|
+
? `red phase: no test names ${missing().join(", ")}`
|
|
136
|
+
: "red phase: no test was written"
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
if (missing().length > 0) {
|
|
140
|
+
yield* events.publish(Info.make({
|
|
141
|
+
message: `story ${story.id}: red phase: no test names ${missing().join(", ")}; the story goes on, the judge still scores its tests`
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
if (policy.evidence === undefined && unit.testGate === undefined) {
|
|
145
|
+
yield* events.publish(Info.make({
|
|
146
|
+
message: `story ${story.id}: red phase: the gates name no test command, so the red tests were written but not run`
|
|
147
|
+
}));
|
|
148
|
+
}
|
|
149
|
+
const parked = [];
|
|
150
|
+
const green = [];
|
|
151
|
+
for (const [index, tag] of tags.entries()) {
|
|
152
|
+
const status = seen.statuses.get(tag) ?? "missing";
|
|
153
|
+
yield* events.publish(CriterionChecked.make({ story: story.id, tag, status }));
|
|
154
|
+
if (status === "green") {
|
|
155
|
+
const item = `${tag} ${story.acceptance[index] ?? ""}`;
|
|
156
|
+
const reason = "its tests pass before implementation: check the outcome or its test";
|
|
157
|
+
green.push(tag);
|
|
158
|
+
if (policy.park) {
|
|
159
|
+
parked.push(`${item} — ${reason}`);
|
|
160
|
+
yield* events.publish(Parked.make({ story: story.id, item, reason, mvp: false }));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (!policy.park && green.length > 0) {
|
|
165
|
+
yield* events.publish(Info.make({
|
|
166
|
+
message: `story ${story.id}: red phase: the tests pass before implementation (${green.join(", ")}); they may not pin the new behaviour`
|
|
167
|
+
}));
|
|
168
|
+
}
|
|
169
|
+
return { frozen: seen.changed, parked };
|
|
170
|
+
});
|
|
171
|
+
/**
|
|
172
|
+
* Whether a story gets a red phase under epic-stories: it names acceptance
|
|
173
|
+
* criteria to test, its plan does not excuse it from tests, and its job is
|
|
174
|
+
* not to rewrite existing tests.
|
|
175
|
+
*/
|
|
176
|
+
export const needsRedPhase = (story) => story.acceptance.length > 0 && story.testsDeferred === undefined && !story.testsChange;
|
|
177
|
+
/**
|
|
178
|
+
* epic-stories' test-first policy (ADR 0053): the red phase for every story
|
|
179
|
+
* that needs one, proved by the test gate, or per criterion when the
|
|
180
|
+
* environment names per-test evidence. A missing tag or a test green too
|
|
181
|
+
* early is noted, not fatal: the review and the judge still run.
|
|
182
|
+
*/
|
|
183
|
+
export const storiesTestFirst = (evidence) => (unit) => {
|
|
184
|
+
const phase = redPhaseOf({ evidence, strict: false, park: false }, unit);
|
|
185
|
+
return {
|
|
186
|
+
redPhase: (story, seats, workDir, system, events) => needsRedPhase(story)
|
|
187
|
+
? phase(story, seats, workDir, system, events)
|
|
188
|
+
: Effect.succeed(noRedPhase)
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
const noRedPhase = { frozen: [], parked: [] };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@llm4ts/shell",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.11.0",
|
|
4
4
|
"description": "Interactive shell and CLI for llm4ts: flow discovery, run-a-flow, and view",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@effect/platform-node": "4.1.4",
|
|
48
48
|
"@effect/platform-node-shared": "4.1.4",
|
|
49
|
-
"@llm4ts/core": "4.
|
|
50
|
-
"@llm4ts/flow": "4.
|
|
51
|
-
"@llm4ts/runner": "4.
|
|
49
|
+
"@llm4ts/core": "4.11.0",
|
|
50
|
+
"@llm4ts/flow": "4.11.0",
|
|
51
|
+
"@llm4ts/runner": "4.11.0"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"effect": "4.1.4"
|