@llm4ts/flow 2.30.1 → 2.31.1
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/AutonomyContract.d.ts +12 -0
- package/dist/AutonomyContract.d.ts.map +1 -0
- package/dist/AutonomyContract.js +51 -0
- package/dist/AutonomyContract.js.map +1 -0
- package/dist/CarriedNotes.d.ts +10 -0
- package/dist/CarriedNotes.d.ts.map +1 -1
- package/dist/CarriedNotes.js +27 -2
- package/dist/CarriedNotes.js.map +1 -1
- package/dist/Evidence.d.ts +12 -0
- package/dist/Evidence.d.ts.map +1 -0
- package/dist/Evidence.js +30 -0
- package/dist/Evidence.js.map +1 -0
- package/dist/Flow.d.ts +35 -3
- package/dist/Flow.d.ts.map +1 -1
- package/dist/Flow.js +58 -4
- package/dist/Flow.js.map +1 -1
- package/dist/FlowEvents.d.ts +20 -5
- package/dist/FlowEvents.d.ts.map +1 -1
- package/dist/FlowEvents.js +32 -9
- package/dist/FlowEvents.js.map +1 -1
- package/dist/GateTriage.d.ts +81 -0
- package/dist/GateTriage.d.ts.map +1 -0
- package/dist/GateTriage.js +161 -0
- package/dist/GateTriage.js.map +1 -0
- package/dist/Gates.d.ts +35 -0
- package/dist/Gates.d.ts.map +1 -0
- package/dist/Gates.js +63 -0
- package/dist/Gates.js.map +1 -0
- package/dist/OracleGuard.d.ts +53 -0
- package/dist/OracleGuard.d.ts.map +1 -0
- package/dist/OracleGuard.js +165 -0
- package/dist/OracleGuard.js.map +1 -0
- package/dist/Pack.d.ts +7 -0
- package/dist/Pack.d.ts.map +1 -1
- package/dist/Pack.js +9 -0
- package/dist/Pack.js.map +1 -1
- package/dist/Retro.d.ts.map +1 -1
- package/dist/Retro.js +5 -0
- package/dist/Retro.js.map +1 -1
- package/dist/Review.d.ts +68 -2
- package/dist/Review.d.ts.map +1 -1
- package/dist/Review.js +158 -27
- package/dist/Review.js.map +1 -1
- package/dist/Roster.d.ts +20 -9
- package/dist/Roster.d.ts.map +1 -1
- package/dist/Roster.js +54 -18
- package/dist/Roster.js.map +1 -1
- package/dist/RosterSeats.d.ts +6 -3
- package/dist/RosterSeats.d.ts.map +1 -1
- package/dist/RosterSeats.js +7 -4
- package/dist/RosterSeats.js.map +1 -1
- package/dist/Stories.d.ts +36 -2
- package/dist/Stories.d.ts.map +1 -1
- package/dist/Stories.js +159 -12
- package/dist/Stories.js.map +1 -1
- package/dist/StoryPlan.d.ts +6 -0
- package/dist/StoryPlan.d.ts.map +1 -1
- package/dist/StoryPlan.js +9 -2
- package/dist/StoryPlan.js.map +1 -1
- package/package.json +7 -2
- package/src/AutonomyContract.ts +61 -0
- package/src/CarriedNotes.ts +37 -2
- package/src/Evidence.ts +43 -0
- package/src/Flow.ts +109 -3
- package/src/FlowEvents.ts +33 -11
- package/src/GateTriage.ts +250 -0
- package/src/Gates.ts +104 -0
- package/src/OracleGuard.ts +205 -0
- package/src/Pack.ts +16 -0
- package/src/Retro.ts +7 -0
- package/src/Review.ts +261 -34
- package/src/Roster.ts +89 -40
- package/src/RosterSeats.ts +13 -6
- package/src/Stories.ts +289 -16
- package/src/StoryPlan.ts +11 -1
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
// Gates with a memory (ADR 0027): what the target's gates said on the code a
|
|
2
|
+
// change started from, and which failing lines the change can be charged
|
|
3
|
+
// with. Pure helpers and a small store; the seams are lintCommand and
|
|
4
|
+
// reviewAndFixLoop (Review.ts), implementPlanFlow (Flow.ts) and the story
|
|
5
|
+
// executor (Stories.ts). Gates.ts re-exports this module beside gatesIn.
|
|
6
|
+
import * as Effect from "effect/Effect"
|
|
7
|
+
import * as Schema from "effect/Schema"
|
|
8
|
+
import type { PersistenceError } from "./FlowError.ts"
|
|
9
|
+
import type { PlainFileStoreShape } from "./Persistence.ts"
|
|
10
|
+
import { ReviewIssue, ReviewResult } from "./Review.ts"
|
|
11
|
+
import { fingerprintOf } from "./ReviewCache.ts"
|
|
12
|
+
|
|
13
|
+
export const GateClass = Schema.Literals(["red", "hang", "crash"])
|
|
14
|
+
export type GateClass = typeof GateClass.Type
|
|
15
|
+
|
|
16
|
+
export const FailureOrigin = Schema.Literals(["new", "base", "flaky"])
|
|
17
|
+
export type FailureOrigin = typeof FailureOrigin.Type
|
|
18
|
+
|
|
19
|
+
export class GateBaseline extends Schema.Class<GateBaseline>("GateBaseline")({
|
|
20
|
+
baseCommit: Schema.String,
|
|
21
|
+
appDir: Schema.String,
|
|
22
|
+
/** Each gate command as configured, joined with one space. */
|
|
23
|
+
commands: Schema.Array(Schema.String),
|
|
24
|
+
failingLines: Schema.Array(Schema.String),
|
|
25
|
+
/** Tests passing on the base, when the test gate's output said (the oracle guard compares). */
|
|
26
|
+
passedCount: Schema.optionalKey(Schema.Int),
|
|
27
|
+
recordedAt: Schema.Number
|
|
28
|
+
}) {}
|
|
29
|
+
|
|
30
|
+
/** Every baseline a run recorded, by `baselineKey`; one file, deleted on land. */
|
|
31
|
+
const Baselines = Schema.Record(Schema.String, GateBaseline)
|
|
32
|
+
const BaselinesJson = Schema.fromJsonString(Baselines)
|
|
33
|
+
const decodeBaselines = Schema.decodeUnknownEffect(BaselinesJson)
|
|
34
|
+
const encodeBaselines = Schema.encodeSync(BaselinesJson)
|
|
35
|
+
|
|
36
|
+
// Built from the escape code point so the pattern holds no control character literal.
|
|
37
|
+
const ansi = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "gu")
|
|
38
|
+
const duration = /\b\d+(?:\.\d+)?\s?(?:ms|s|m)\b/gu
|
|
39
|
+
const isoTimestamp = /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?/gu
|
|
40
|
+
const stackFrame = /^\s*at\s/u
|
|
41
|
+
const summaryLine =
|
|
42
|
+
/^\s*(?:Test Files|Tests|Duration|Start at|Snapshots|Found \d+ errors?|\d+ (?:passing|failing|pending))\b/u
|
|
43
|
+
const failureMarker =
|
|
44
|
+
/FAIL|✗|×|✘|✖|❯|error|Error|AssertionError|Expected|Received|expected|TS\d{4}/u
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The lines of a gate's output a change can be blamed for, made comparable
|
|
48
|
+
* across runs and worktrees: colours, timings, timestamps and the given root
|
|
49
|
+
* prefixes removed; stack frames, summaries and blank lines dropped; only
|
|
50
|
+
* lines carrying a failure marker kept, each once. A heuristic by design:
|
|
51
|
+
* per-tool parsers are kit material (a pack `diagnostics:` command, later).
|
|
52
|
+
*/
|
|
53
|
+
export const normalizeGateOutput = (
|
|
54
|
+
text: string,
|
|
55
|
+
roots: ReadonlyArray<string>
|
|
56
|
+
): ReadonlyArray<string> => {
|
|
57
|
+
const prefixes = roots.filter((root) => root.length > 0).map((root) => root.replace(/\/+$/u, ""))
|
|
58
|
+
const seen = new Set<string>()
|
|
59
|
+
const out: Array<string> = []
|
|
60
|
+
for (const raw of text.split(/\r?\n/u)) {
|
|
61
|
+
let line = raw.replace(ansi, "")
|
|
62
|
+
for (const prefix of prefixes) {
|
|
63
|
+
line = line.replaceAll(`${prefix}/`, "")
|
|
64
|
+
}
|
|
65
|
+
line = line.replace(isoTimestamp, "<ts>").replace(duration, "<t>").trim()
|
|
66
|
+
if (line.length === 0 || stackFrame.test(line) || summaryLine.test(line)) {
|
|
67
|
+
continue
|
|
68
|
+
}
|
|
69
|
+
if (!failureMarker.test(line)) {
|
|
70
|
+
continue
|
|
71
|
+
}
|
|
72
|
+
line = line.replace(/\s+/gu, " ")
|
|
73
|
+
if (!seen.has(line)) {
|
|
74
|
+
seen.add(line)
|
|
75
|
+
out.push(line)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return out
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The title prefix `lintCommand` gives every gate issue; nothing else is a gate. */
|
|
82
|
+
export const gateIssuePrefix = "lint failed: "
|
|
83
|
+
|
|
84
|
+
export const isGateIssue = (issue: ReviewIssue): boolean => issue.title.startsWith(gateIssuePrefix)
|
|
85
|
+
|
|
86
|
+
/** Every gate issue's normalized failing lines, in order, each once. */
|
|
87
|
+
export const failingLinesOf = (
|
|
88
|
+
result: ReviewResult,
|
|
89
|
+
roots: ReadonlyArray<string>
|
|
90
|
+
): ReadonlyArray<string> =>
|
|
91
|
+
Array.from(
|
|
92
|
+
new Set(
|
|
93
|
+
result.issues
|
|
94
|
+
.filter(isGateIssue)
|
|
95
|
+
.flatMap((issue) => normalizeGateOutput(issue.description, roots))
|
|
96
|
+
)
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
export interface GateTriage {
|
|
100
|
+
/** The lint result with only the failures the change caused; clean when it caused none. */
|
|
101
|
+
readonly blocking: ReviewResult
|
|
102
|
+
readonly newLines: ReadonlyArray<string>
|
|
103
|
+
/** Failing lines already red on the base: listed, never charged. */
|
|
104
|
+
readonly inherited: ReadonlyArray<string>
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Splits a lint result against the baseline. A gate issue whose every
|
|
109
|
+
* failing line is on the baseline is dropped (inherited); one with new lines
|
|
110
|
+
* is kept with `origin: "new"` and its description reduced to those lines,
|
|
111
|
+
* so the fix prompt names only what the change broke. A gate issue with no
|
|
112
|
+
* recognizable failing line at all (a hang, a crash, an unparsed output) is
|
|
113
|
+
* kept whole. Non-gate issues (the perimeter, the oracle guard) pass through.
|
|
114
|
+
* Without a baseline the result is returned as is.
|
|
115
|
+
*/
|
|
116
|
+
export const triageGates = (
|
|
117
|
+
result: ReviewResult,
|
|
118
|
+
baseline: GateBaseline | undefined,
|
|
119
|
+
roots: ReadonlyArray<string>
|
|
120
|
+
): GateTriage => {
|
|
121
|
+
if (baseline === undefined || result.isClean) {
|
|
122
|
+
return { blocking: result, newLines: [], inherited: [] }
|
|
123
|
+
}
|
|
124
|
+
const known = new Set(baseline.failingLines)
|
|
125
|
+
const newLines: Array<string> = []
|
|
126
|
+
const inherited: Array<string> = []
|
|
127
|
+
const issues: Array<ReviewIssue> = []
|
|
128
|
+
for (const issue of result.issues) {
|
|
129
|
+
if (!isGateIssue(issue)) {
|
|
130
|
+
issues.push(issue)
|
|
131
|
+
continue
|
|
132
|
+
}
|
|
133
|
+
const lines = normalizeGateOutput(issue.description, roots)
|
|
134
|
+
const fresh = lines.filter((line) => !known.has(line))
|
|
135
|
+
inherited.push(...lines.filter((line) => known.has(line)))
|
|
136
|
+
if (lines.length > 0 && fresh.length === 0) {
|
|
137
|
+
continue
|
|
138
|
+
}
|
|
139
|
+
newLines.push(...fresh)
|
|
140
|
+
issues.push(
|
|
141
|
+
ReviewIssue.make({
|
|
142
|
+
...issue,
|
|
143
|
+
origin: "new",
|
|
144
|
+
description: fresh.length > 0 ? fresh.join("\n") : issue.description
|
|
145
|
+
})
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
blocking: ReviewResult.make({
|
|
150
|
+
issues,
|
|
151
|
+
summary: issues.length === 0 ? "lint passed (inherited failures only)" : result.summary
|
|
152
|
+
}),
|
|
153
|
+
newLines: Array.from(new Set(newLines)),
|
|
154
|
+
inherited: Array.from(new Set(inherited))
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export const baselineKey = (parts: {
|
|
159
|
+
readonly baseCommit: string
|
|
160
|
+
readonly appDir: string
|
|
161
|
+
readonly commands: ReadonlyArray<ReadonlyArray<string>>
|
|
162
|
+
}): string =>
|
|
163
|
+
fingerprintOf([
|
|
164
|
+
parts.baseCommit,
|
|
165
|
+
parts.appDir,
|
|
166
|
+
...parts.commands.map((command) => command.join(" "))
|
|
167
|
+
]).slice(0, 16)
|
|
168
|
+
|
|
169
|
+
/** The one file a run keeps its baselines in. */
|
|
170
|
+
export const baselinesPath = (stateDir: string): string =>
|
|
171
|
+
`${stateDir.replace(/\/+$/u, "")}/gates/baselines.json`
|
|
172
|
+
|
|
173
|
+
const readAll = (
|
|
174
|
+
files: PlainFileStoreShape,
|
|
175
|
+
path: string
|
|
176
|
+
): Effect.Effect<Readonly<Record<string, GateBaseline>>, PersistenceError> =>
|
|
177
|
+
files.read(path).pipe(
|
|
178
|
+
Effect.flatMap((text) =>
|
|
179
|
+
text === undefined
|
|
180
|
+
? Effect.succeed({})
|
|
181
|
+
: decodeBaselines(text).pipe(
|
|
182
|
+
// An unreadable file is no baseline: the caller records a fresh one.
|
|
183
|
+
Effect.catch(() => Effect.succeed({}))
|
|
184
|
+
)
|
|
185
|
+
)
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
export const readBaseline = (
|
|
189
|
+
files: PlainFileStoreShape,
|
|
190
|
+
stateDir: string,
|
|
191
|
+
key: string
|
|
192
|
+
): Effect.Effect<GateBaseline | undefined, PersistenceError> =>
|
|
193
|
+
Effect.map(readAll(files, baselinesPath(stateDir)), (all) => all[key])
|
|
194
|
+
|
|
195
|
+
export interface EnsureBaselineArgs<E> {
|
|
196
|
+
readonly files: PlainFileStoreShape
|
|
197
|
+
readonly stateDir: string
|
|
198
|
+
/** The commit the change starts from. */
|
|
199
|
+
readonly commit: string
|
|
200
|
+
readonly appDir: string
|
|
201
|
+
readonly commands: ReadonlyArray<ReadonlyArray<string>>
|
|
202
|
+
/** Runs the gates on that commit; called only when no baseline is stored. */
|
|
203
|
+
readonly run: Effect.Effect<ReviewResult, E>
|
|
204
|
+
/** Root prefixes stripped from gate output (the work dir, the app dir). */
|
|
205
|
+
readonly roots: ReadonlyArray<string>
|
|
206
|
+
readonly now: Effect.Effect<number>
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* The baseline for a commit: the stored one, or a fresh one recorded from
|
|
211
|
+
* `run`. Lazy on purpose, so a second change on an unchanged commit costs
|
|
212
|
+
* no gate run.
|
|
213
|
+
*/
|
|
214
|
+
export const ensureBaseline = <E>(
|
|
215
|
+
args: EnsureBaselineArgs<E>
|
|
216
|
+
): Effect.Effect<GateBaseline, E | PersistenceError> =>
|
|
217
|
+
Effect.gen(function* () {
|
|
218
|
+
const key = baselineKey({
|
|
219
|
+
baseCommit: args.commit,
|
|
220
|
+
appDir: args.appDir,
|
|
221
|
+
commands: args.commands
|
|
222
|
+
})
|
|
223
|
+
const stored = yield* readBaseline(args.files, args.stateDir, key)
|
|
224
|
+
if (stored !== undefined) {
|
|
225
|
+
return stored
|
|
226
|
+
}
|
|
227
|
+
const result = yield* args.run
|
|
228
|
+
const baseline = GateBaseline.make({
|
|
229
|
+
baseCommit: args.commit,
|
|
230
|
+
appDir: args.appDir,
|
|
231
|
+
commands: args.commands.map((command) => command.join(" ")),
|
|
232
|
+
failingLines: failingLinesOf(result, args.roots),
|
|
233
|
+
...(result.passed === undefined ? {} : { passedCount: result.passed }),
|
|
234
|
+
recordedAt: yield* args.now
|
|
235
|
+
})
|
|
236
|
+
yield* writeBaseline(args.files, args.stateDir, key, baseline)
|
|
237
|
+
return baseline
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
export const writeBaseline = (
|
|
241
|
+
files: PlainFileStoreShape,
|
|
242
|
+
stateDir: string,
|
|
243
|
+
key: string,
|
|
244
|
+
baseline: GateBaseline
|
|
245
|
+
): Effect.Effect<void, PersistenceError> => {
|
|
246
|
+
const path = baselinesPath(stateDir)
|
|
247
|
+
return Effect.flatMap(readAll(files, path), (all) =>
|
|
248
|
+
files.writeAtomic(path, encodeBaselines({ ...all, [key]: baseline }))
|
|
249
|
+
)
|
|
250
|
+
}
|
package/src/Gates.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// The target's gates as a module (ADR 0027): run them in a directory with a
|
|
2
|
+
// timeout and a log per gate, remember what they said on a base, and keep
|
|
3
|
+
// only what matters when an epic lands. The pure half lives in
|
|
4
|
+
// GateTriage.ts and is re-exported here.
|
|
5
|
+
import { join } from "node:path"
|
|
6
|
+
import type * as Duration from "effect/Duration"
|
|
7
|
+
import * as Effect from "effect/Effect"
|
|
8
|
+
import type { ProcessExecutorShape } from "@llm4ts/core/ProcessExecutor"
|
|
9
|
+
import type { FlowError } from "./FlowError.ts"
|
|
10
|
+
import type { FlowEventsShape } from "./FlowEvents.ts"
|
|
11
|
+
import { baselinesPath, normalizeGateOutput } from "./GateTriage.ts"
|
|
12
|
+
import type { PlainFileStoreShape } from "./Persistence.ts"
|
|
13
|
+
import { lintCommand, mergeReviewResults, type ReviewResult } from "./Review.ts"
|
|
14
|
+
|
|
15
|
+
export * from "./GateTriage.ts"
|
|
16
|
+
|
|
17
|
+
export interface GateLogDir {
|
|
18
|
+
readonly files: PlainFileStoreShape
|
|
19
|
+
readonly dir: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface GateRunOptions {
|
|
23
|
+
readonly timeout?: Duration.Duration
|
|
24
|
+
/** Where this runner's logs go unless a call names its own; `undefined` writes none. */
|
|
25
|
+
readonly logDir?: GateLogDir
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** `<index>-<command slug>.log`: one file per gate command, overwritten each run. */
|
|
29
|
+
export const gateLogName = (index: number, command: ReadonlyArray<string>): string =>
|
|
30
|
+
`${index}-${command
|
|
31
|
+
.join(" ")
|
|
32
|
+
.replace(/[^a-z0-9]+/giu, "-")
|
|
33
|
+
.replace(/^-|-$/gu, "")
|
|
34
|
+
.toLowerCase()}.log`
|
|
35
|
+
|
|
36
|
+
/** Runs the gates in a directory, stopping at the first red one (later output would be noise). */
|
|
37
|
+
export const gatesIn =
|
|
38
|
+
(
|
|
39
|
+
process: ProcessExecutorShape,
|
|
40
|
+
events: FlowEventsShape,
|
|
41
|
+
commands: ReadonlyArray<ReadonlyArray<string>>,
|
|
42
|
+
options: GateRunOptions = {}
|
|
43
|
+
) =>
|
|
44
|
+
(
|
|
45
|
+
workDir: string,
|
|
46
|
+
laneEvents?: FlowEventsShape,
|
|
47
|
+
log?: GateLogDir
|
|
48
|
+
): Effect.Effect<ReviewResult, FlowError> =>
|
|
49
|
+
Effect.gen(function* () {
|
|
50
|
+
const sink = log ?? options.logDir
|
|
51
|
+
const results: Array<ReviewResult> = []
|
|
52
|
+
for (const [index, command] of commands.entries()) {
|
|
53
|
+
const result = yield* lintCommand(process, laneEvents ?? events, command, workDir, {
|
|
54
|
+
...(options.timeout === undefined ? {} : { timeout: options.timeout }),
|
|
55
|
+
...(sink === undefined
|
|
56
|
+
? {}
|
|
57
|
+
: { log: { files: sink.files, path: join(sink.dir, gateLogName(index, command)) } })
|
|
58
|
+
})
|
|
59
|
+
results.push(result)
|
|
60
|
+
if (!result.isClean) {
|
|
61
|
+
break
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return mergeReviewResults(results)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
/** A landed epic keeps why a gate was red, not the target's whole test output. */
|
|
68
|
+
export const compactGateLog = (text: string, roots: ReadonlyArray<string>): string =>
|
|
69
|
+
normalizeGateOutput(text, roots).join("\n")
|
|
70
|
+
|
|
71
|
+
/** The gate log directory of one story under a run's state folder. */
|
|
72
|
+
export const storyGateLogDir = (stateDir: string, storyId: string): string =>
|
|
73
|
+
join(stateDir, "stories", storyId, "gates")
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* What `--land` keeps of the gates: no baselines (reproducible), and each
|
|
77
|
+
* story's gate logs reduced to their failing lines. Logs are enumerated from
|
|
78
|
+
* the story ids and the gate commands, so no listing is needed.
|
|
79
|
+
*/
|
|
80
|
+
export const compactGateArtifacts = Effect.fn("@llm4ts/flow/Gates.compactArtifacts")(function* (
|
|
81
|
+
files: PlainFileStoreShape,
|
|
82
|
+
stateDir: string,
|
|
83
|
+
storyIds: ReadonlyArray<string>,
|
|
84
|
+
commands: ReadonlyArray<ReadonlyArray<string>>
|
|
85
|
+
): Effect.fn.Return<{ readonly baselines: number; readonly logs: number }, FlowError> {
|
|
86
|
+
const path = baselinesPath(stateDir)
|
|
87
|
+
const hadBaselines = (yield* files.read(path)) !== undefined
|
|
88
|
+
if (hadBaselines) {
|
|
89
|
+
yield* files.remove(path)
|
|
90
|
+
}
|
|
91
|
+
let logs = 0
|
|
92
|
+
for (const storyId of storyIds) {
|
|
93
|
+
for (const [index, command] of commands.entries()) {
|
|
94
|
+
const logPath = join(storyGateLogDir(stateDir, storyId), gateLogName(index, command))
|
|
95
|
+
const text = yield* files.read(logPath)
|
|
96
|
+
if (text === undefined) {
|
|
97
|
+
continue
|
|
98
|
+
}
|
|
99
|
+
yield* files.writeAtomic(logPath, compactGateLog(text, []))
|
|
100
|
+
logs += 1
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return { baselines: hadBaselines ? 1 : 0, logs }
|
|
104
|
+
})
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// The oracle guard (ADR 0027, decision 4): a change may not delete a test
|
|
2
|
+
// file, add a skip or focus marker, or lower the passed-test count unless
|
|
3
|
+
// its plan entry says it may. Deterministic, from the diff and the gate
|
|
4
|
+
// output; a violation is a gate failure the fix round can undo.
|
|
5
|
+
import * as Schema from "effect/Schema"
|
|
6
|
+
import { ReviewIssue } from "./Review.ts"
|
|
7
|
+
|
|
8
|
+
export class OracleRules extends Schema.Class<OracleRules>("OracleRules")({
|
|
9
|
+
/** Regex source: a path matching it is a test file. */
|
|
10
|
+
testFiles: Schema.String,
|
|
11
|
+
/** Substrings whose appearance on an added line marks a skipped or focused test. */
|
|
12
|
+
markers: Schema.Array(Schema.String)
|
|
13
|
+
}) {}
|
|
14
|
+
|
|
15
|
+
export const defaultOracleRules = OracleRules.make({
|
|
16
|
+
testFiles:
|
|
17
|
+
"(?:^|/)(?:__tests__|tests?|spec|src/test)/|\\.(?:test|spec)\\.[cm]?[jt]sx?$|_test\\.(?:go|py|rs)$|Tests?\\.(?:java|kt|scala|cs)$|^tests?_.*\\.py$",
|
|
18
|
+
markers: [
|
|
19
|
+
".skip(",
|
|
20
|
+
".only(",
|
|
21
|
+
"xit(",
|
|
22
|
+
"xdescribe(",
|
|
23
|
+
"xtest(",
|
|
24
|
+
"test.todo(",
|
|
25
|
+
"it.todo(",
|
|
26
|
+
"@Ignore",
|
|
27
|
+
"@Disabled",
|
|
28
|
+
"@pytest.mark.skip",
|
|
29
|
+
"#[ignore]"
|
|
30
|
+
]
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
/** The parsed body of a pack's `## Oracle` section: `- tests: <regex>` and `- markers: a, b`. */
|
|
34
|
+
export const oracleRulesFrom = (fields: {
|
|
35
|
+
readonly tests?: string
|
|
36
|
+
readonly markers?: ReadonlyArray<string>
|
|
37
|
+
}): OracleRules =>
|
|
38
|
+
OracleRules.make({
|
|
39
|
+
testFiles: fields.tests ?? defaultOracleRules.testFiles,
|
|
40
|
+
markers: [...defaultOracleRules.markers, ...(fields.markers ?? [])]
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
export interface AddedLine {
|
|
44
|
+
readonly file: string
|
|
45
|
+
readonly line: number
|
|
46
|
+
readonly text: string
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface DiffShape {
|
|
50
|
+
/** Files the diff deletes outright. */
|
|
51
|
+
readonly deleted: ReadonlyArray<string>
|
|
52
|
+
/** Lines the diff adds, with the path and the new line number. */
|
|
53
|
+
readonly added: ReadonlyArray<AddedLine>
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const fileHeader = /^diff --git a\/(.+?) b\/(.+)$/u
|
|
57
|
+
const hunkHeader = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/u
|
|
58
|
+
|
|
59
|
+
/** The deletions and added lines of a unified diff; pure, tolerant of noise between files. */
|
|
60
|
+
export const parseUnifiedDiff = (diff: string): DiffShape => {
|
|
61
|
+
const deleted: Array<string> = []
|
|
62
|
+
const added: Array<AddedLine> = []
|
|
63
|
+
let file: string | undefined
|
|
64
|
+
let line = 0
|
|
65
|
+
let inHunk = false
|
|
66
|
+
for (const raw of diff.split(/\r?\n/u)) {
|
|
67
|
+
const header = fileHeader.exec(raw)
|
|
68
|
+
if (header !== null) {
|
|
69
|
+
file = header[2]
|
|
70
|
+
inHunk = false
|
|
71
|
+
continue
|
|
72
|
+
}
|
|
73
|
+
if (file === undefined) continue
|
|
74
|
+
if (raw.startsWith("deleted file mode")) {
|
|
75
|
+
deleted.push(file)
|
|
76
|
+
continue
|
|
77
|
+
}
|
|
78
|
+
const hunk = hunkHeader.exec(raw)
|
|
79
|
+
if (hunk !== null) {
|
|
80
|
+
line = Number.parseInt(hunk[1] ?? "0", 10)
|
|
81
|
+
inHunk = true
|
|
82
|
+
continue
|
|
83
|
+
}
|
|
84
|
+
if (!inHunk) continue
|
|
85
|
+
if (raw.startsWith("+++") || raw.startsWith("---")) continue
|
|
86
|
+
if (raw.startsWith("+")) {
|
|
87
|
+
added.push({ file, line, text: raw.slice(1) })
|
|
88
|
+
line += 1
|
|
89
|
+
} else if (raw.startsWith("-")) {
|
|
90
|
+
// a removed line: the new file's numbering does not advance
|
|
91
|
+
} else if (raw.startsWith("\\")) {
|
|
92
|
+
// ""
|
|
93
|
+
} else {
|
|
94
|
+
line += 1
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return { deleted, added }
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const vitestLike = /\bTests\b[^\n]*?(\d+)\s+passed/u
|
|
101
|
+
const jestLike = /\bTests:\s[^\n]*?(\d+)\s+passed/u
|
|
102
|
+
const pytestLike = /(?:^|\n)[^\n]*?\b(\d+)\s+passed\b[^\n]*\bin\s+[\d.]+s/u
|
|
103
|
+
const cargoLike = /test result:[^\n]*?(\d+)\s+passed/u
|
|
104
|
+
const mochaLike = /(?:^|\n)\s*(\d+)\s+passing\b/u
|
|
105
|
+
const junitLike =
|
|
106
|
+
/Tests run:\s*(\d+),\s*Failures:\s*(\d+),\s*Errors:\s*(\d+)(?:,\s*Skipped:\s*(\d+))?/gu
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The passed-test count in a test runner's output, when a summary line the
|
|
110
|
+
* guard knows is present (Vitest, Jest, pytest, cargo test, mocha, JUnit
|
|
111
|
+
* via Maven/Gradle); `undefined` otherwise, which the guard reports as an
|
|
112
|
+
* Info rather than a verdict.
|
|
113
|
+
*/
|
|
114
|
+
export const passedCountIn = (output: string): number | undefined => {
|
|
115
|
+
for (const pattern of [vitestLike, jestLike, cargoLike, pytestLike, mochaLike]) {
|
|
116
|
+
const match = pattern.exec(output)
|
|
117
|
+
if (match?.[1] !== undefined) {
|
|
118
|
+
return Number.parseInt(match[1], 10)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Maven prints a line per class and one grand total; the largest run is the total.
|
|
122
|
+
let largestRun = -1
|
|
123
|
+
let passedOfLargest: number | undefined
|
|
124
|
+
junitLike.lastIndex = 0
|
|
125
|
+
for (let match = junitLike.exec(output); match !== null; match = junitLike.exec(output)) {
|
|
126
|
+
const run = Number.parseInt(match[1] ?? "0", 10)
|
|
127
|
+
const failures = Number.parseInt(match[2] ?? "0", 10)
|
|
128
|
+
const errors = Number.parseInt(match[3] ?? "0", 10)
|
|
129
|
+
const skipped = Number.parseInt(match[4] ?? "0", 10)
|
|
130
|
+
if (run >= largestRun) {
|
|
131
|
+
largestRun = run
|
|
132
|
+
passedOfLargest = run - failures - errors - skipped
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return passedOfLargest
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export interface OracleCounts {
|
|
139
|
+
/** Tests passing on the base, from its baseline; `undefined` when unknown. */
|
|
140
|
+
readonly base: number | undefined
|
|
141
|
+
/** Tests passing on the change, from its test gate; `undefined` when unknown. */
|
|
142
|
+
readonly current: number | undefined
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export const oracleIssuePrefix = "oracle: "
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* The guard's verdict on a change: one Critical per deleted test file, one
|
|
149
|
+
* per added marker (with `file:line`), one for a passed-count drop; empty
|
|
150
|
+
* when `declared` (the plan entry says tests may change). Counts are judged
|
|
151
|
+
* only when both are known; a caller reports the unknown case as an Info.
|
|
152
|
+
*/
|
|
153
|
+
export const checkOracle = (
|
|
154
|
+
diff: DiffShape,
|
|
155
|
+
counts: OracleCounts | undefined,
|
|
156
|
+
rules: OracleRules,
|
|
157
|
+
declared: boolean
|
|
158
|
+
): ReadonlyArray<ReviewIssue> => {
|
|
159
|
+
if (declared) {
|
|
160
|
+
return []
|
|
161
|
+
}
|
|
162
|
+
const testFile = new RegExp(rules.testFiles, "u")
|
|
163
|
+
const issues: Array<ReviewIssue> = []
|
|
164
|
+
for (const path of diff.deleted) {
|
|
165
|
+
if (testFile.test(path)) {
|
|
166
|
+
issues.push(
|
|
167
|
+
ReviewIssue.make({
|
|
168
|
+
severity: "Critical",
|
|
169
|
+
title: `${oracleIssuePrefix}test file deleted: ${path}`,
|
|
170
|
+
description:
|
|
171
|
+
"Restore it. A story may not delete a test unless its plan entry declares `testsChange: true`.",
|
|
172
|
+
file: path
|
|
173
|
+
})
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
for (const line of diff.added) {
|
|
178
|
+
if (!testFile.test(line.file)) continue
|
|
179
|
+
const marker = rules.markers.find((candidate) => line.text.includes(candidate))
|
|
180
|
+
if (marker === undefined) continue
|
|
181
|
+
issues.push(
|
|
182
|
+
ReviewIssue.make({
|
|
183
|
+
severity: "Critical",
|
|
184
|
+
title: `${oracleIssuePrefix}skip or focus marker added: ${marker.trim()}`,
|
|
185
|
+
description: `${line.file}:${line.line}: ${line.text.trim()}\nRemove the marker and make the test pass, or report the test as wrong in your Findings.`,
|
|
186
|
+
file: line.file,
|
|
187
|
+
line: line.line
|
|
188
|
+
})
|
|
189
|
+
)
|
|
190
|
+
}
|
|
191
|
+
if (counts?.base !== undefined && counts.current !== undefined && counts.current < counts.base) {
|
|
192
|
+
issues.push(
|
|
193
|
+
ReviewIssue.make({
|
|
194
|
+
severity: "Critical",
|
|
195
|
+
title: `${oracleIssuePrefix}fewer tests pass than on the base (${counts.current} < ${counts.base})`,
|
|
196
|
+
description:
|
|
197
|
+
"Tests were removed, skipped or no longer discovered. Restore them; declare `testsChange: true` on the story if the change is intended."
|
|
198
|
+
})
|
|
199
|
+
)
|
|
200
|
+
}
|
|
201
|
+
return issues
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export const isOracleIssue = (issue: ReviewIssue): boolean =>
|
|
205
|
+
issue.title.startsWith(oracleIssuePrefix)
|
package/src/Pack.ts
CHANGED
|
@@ -3,6 +3,7 @@ import * as Schema from "effect/Schema"
|
|
|
3
3
|
import { Dimension } from "@llm4ts/core/eval/Eval"
|
|
4
4
|
import type { ConsolidateRules } from "./Domains.ts"
|
|
5
5
|
import { PlanParseError } from "./FlowError.ts"
|
|
6
|
+
import { oracleRulesFrom, type OracleRules } from "./OracleGuard.ts"
|
|
6
7
|
import { parseReviewer, type Reviewer } from "./Reviewer.ts"
|
|
7
8
|
import { CoverageRule } from "./SpecChecks.ts"
|
|
8
9
|
import type { WorkspaceError, WorkspaceShape } from "./Workspace.ts"
|
|
@@ -67,6 +68,12 @@ export interface Pack {
|
|
|
67
68
|
* fragment as context (`context:`). Absent: every program is its own feature.
|
|
68
69
|
*/
|
|
69
70
|
readonly consolidate: ConsolidateRules | undefined
|
|
71
|
+
/**
|
|
72
|
+
* The `## Oracle` section (ADR 0027): `- tests: <regex>` for what a test
|
|
73
|
+
* file is and `- markers: a, b` for extra skip or focus markers, merged
|
|
74
|
+
* over the defaults. Absent: the defaults.
|
|
75
|
+
*/
|
|
76
|
+
readonly oracle: OracleRules | undefined
|
|
70
77
|
readonly dir: string
|
|
71
78
|
readonly gate: (name: string) => ReadonlyArray<string> | undefined
|
|
72
79
|
readonly prompt: (name: string) => string | undefined
|
|
@@ -266,6 +273,14 @@ export const loadPack = Effect.fn("@llm4ts/flow/Pack.load")(function* (
|
|
|
266
273
|
message: `pack manifest 'spec-schema:' must be 'pagespec' when set, got: ${specSchema}`
|
|
267
274
|
})
|
|
268
275
|
}
|
|
276
|
+
const oracleValues = namedItems(section(manifest.sections, "Oracle"))
|
|
277
|
+
const oracle: OracleRules | undefined =
|
|
278
|
+
section(manifest.sections, "Oracle") === undefined
|
|
279
|
+
? undefined
|
|
280
|
+
: oracleRulesFrom({
|
|
281
|
+
...(oracleValues.tests === undefined ? {} : { tests: oracleValues.tests }),
|
|
282
|
+
markers: commaList(oracleValues.markers)
|
|
283
|
+
})
|
|
269
284
|
const consolidateValues = namedItems(section(manifest.sections, "Consolidate"))
|
|
270
285
|
const consolidate: ConsolidateRules | undefined =
|
|
271
286
|
section(manifest.sections, "Consolidate") === undefined
|
|
@@ -330,6 +345,7 @@ export const loadPack = Effect.fn("@llm4ts/flow/Pack.load")(function* (
|
|
|
330
345
|
featureFiles,
|
|
331
346
|
specSchema,
|
|
332
347
|
consolidate,
|
|
348
|
+
oracle,
|
|
333
349
|
dir: directory,
|
|
334
350
|
gate: (name) => gates[name],
|
|
335
351
|
prompt: (name) => prompts[name],
|
package/src/Retro.ts
CHANGED
|
@@ -461,6 +461,13 @@ export const renderRetroDigest = (inputs: RetroInputs): string => {
|
|
|
461
461
|
case "CapabilityUnenforceable":
|
|
462
462
|
runLines.push(`- capability unenforceable: ${event.detail}`)
|
|
463
463
|
break
|
|
464
|
+
case "EvidenceChecked":
|
|
465
|
+
if (event.unverified > 0) {
|
|
466
|
+
runLines.push(
|
|
467
|
+
`- fabricated status: task "${event.task}"${event.lane === undefined ? "" : ` (story ${event.lane})`} claimed ${event.unverified} command(s) that never ran`
|
|
468
|
+
)
|
|
469
|
+
}
|
|
470
|
+
break
|
|
464
471
|
case "ExecutorExcluded":
|
|
465
472
|
runLines.push(`- executor excluded: ${event.executor} — ${event.reason}`)
|
|
466
473
|
break
|