iterate-plugin 3.5.7 → 3.6.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/README.md +64 -20
- package/README.zh-CN.md +53 -17
- package/dist/approval-gate.js +143 -23
- package/dist/atomic-fs.js +148 -17
- package/dist/config-loader.js +509 -34
- package/dist/config-write.js +83 -22
- package/dist/evidence.js +141 -87
- package/dist/file-lock.js +165 -0
- package/dist/index.js +54 -28
- package/dist/jobs.js +56 -11
- package/dist/live.js +52 -13
- package/dist/meta-review.js +132 -28
- package/dist/method-scope.js +31 -8
- package/dist/review-scope.js +32 -9
- package/dist/review.js +96 -17
- package/dist/session-hooks.js +55 -13
- package/dist/skill-prompt.js +396 -66
- package/dist/tools/checkpoint.js +85 -19
- package/dist/tools/config.js +44 -2
- package/dist/tools/context.js +22 -5
- package/dist/tools/decision-log.js +111 -27
- package/dist/tools/defense-events.js +90 -31
- package/dist/tools/defense-store.js +28 -3
- package/dist/tools/experience-bank.js +108 -43
- package/dist/tools/experience-store.js +54 -4
- package/dist/tools/fix.js +347 -119
- package/dist/tools/history.js +68 -14
- package/dist/tools/present.js +80 -0
- package/dist/tools/prune.js +150 -53
- package/dist/tools/quality-gate.js +52 -2
- package/dist/tools/quality-store.js +17 -1
- package/dist/tools/review.js +158 -7
- package/dist/tools/transcript.js +173 -36
- package/dist/tools/triage.js +67 -12
- package/dist/tools/validate.js +115 -24
- package/dist/transcript.js +267 -4
- package/lib/client.js +945 -181
- package/lib/parse.js +760 -57
- package/package.json +14 -12
- package/src/approval-gate.ts +160 -23
- package/src/atomic-fs.ts +152 -17
- package/src/client/index.ts +600 -129
- package/src/config-loader.ts +542 -35
- package/src/config-write.ts +108 -26
- package/src/evidence.ts +194 -92
- package/src/file-lock.ts +184 -0
- package/src/index.ts +53 -29
- package/src/jobs.ts +63 -12
- package/src/live.ts +48 -11
- package/src/meta-review.ts +151 -34
- package/src/method-scope.ts +31 -8
- package/src/review-scope.ts +33 -10
- package/src/review.ts +96 -17
- package/src/session-hooks.ts +54 -12
- package/src/skill-prompt.ts +396 -66
- package/src/tools/checkpoint.ts +81 -19
- package/src/tools/config.ts +44 -2
- package/src/tools/context.ts +25 -5
- package/src/tools/decision-log.ts +115 -22
- package/src/tools/defense-events.ts +87 -31
- package/src/tools/defense-store.ts +30 -3
- package/src/tools/experience-bank.ts +112 -44
- package/src/tools/experience-store.ts +54 -5
- package/src/tools/fix.ts +258 -20
- package/src/tools/history.ts +74 -15
- package/src/tools/present.ts +89 -0
- package/src/tools/prune.ts +154 -51
- package/src/tools/quality-gate.ts +57 -2
- package/src/tools/quality-store.ts +18 -1
- package/src/tools/review.ts +155 -6
- package/src/tools/transcript.ts +178 -36
- package/src/tools/triage.ts +70 -13
- package/src/tools/validate.ts +138 -32
- package/src/transcript.ts +279 -4
- package/src/types.ts +29 -1
package/dist/skill-prompt.js
CHANGED
|
@@ -22,7 +22,7 @@ You have the iterate plugin installed, which registers these tools:
|
|
|
22
22
|
- \`iterate_status\` — summarize the current run: mode, round, fixes applied, architectural remaining, decision-log size, checkpoint presence, and whether the run was interrupted (a checkpoint on disk with no newer decision-log activity means the previous run was interrupted and can be resumed)
|
|
23
23
|
- \`iterate_history\` — inspect the runtime state in detail: decision-log entries and applied fixes (optionally scoped to a round or a fixed file)
|
|
24
24
|
- \`iterate_prune\` — remove stale runtime artifacts (\`.iterate/\` entries). Defaults to a read-only dry-run that reports what WOULD be removed; pass \`dryRun:false\` to actually prune.
|
|
25
|
-
- \`iterate_transcript\` — runtime observatory file (\`.iterate/transcript.json\`). \`read\` fetches the persisted manifest including any steering \`nudge\` for this run's reviewers; \`capture\` (call once after the final report) persists the per-reviewer threads, convergence trend, findings, fixes, checkpoint, and timeline so the client observatory panel reflects the run; \`nudge\` sets/clears steering text the next round's reviewers read. Purely local, never touches source files.
|
|
25
|
+
- \`iterate_transcript\` — runtime observatory file (\`.iterate/transcript.json\`). \`read\` fetches the persisted manifest including any steering \`nudge\` for this run's reviewers; \`capture\` (call once after the final report) persists the per-reviewer threads, convergence trend, findings, fixes, checkpoint, per-round validation results (\`validations\`: command + exitCode + allowed + rejectReason), and timeline so the client observatory panel reflects the run; \`nudge\` sets/clears steering text the next round's reviewers read. Purely local, never touches source files.
|
|
26
26
|
- \`iterate_experience\` — experience bank (\`.iterate/experience.json\`): \`list\`/\`search\`/\`get\` recall verified fixes and patterns from past sessions (read the bank before fixing so proven fixes are applied first); \`add\` records a new verified fix — re-adding the same pattern+dimension bumps its hit count instead of duplicating it; \`remove\` deletes a stale or incorrect entry by \`id\` so bad experiences never resurface.
|
|
27
27
|
- \`iterate_quality_gate\` — quality certificate: \`read\` loads the persisted dimension convergence rates / verification pass rate / PASS-FAIL status; \`compute\` recomputes a fresh snapshot from this round's findings + validation results (supply \`findingsByRound\` for real convergence) and persists it to \`.iterate/quality-gate.json\`; \`clear\` removes the persisted certificate to reset a stale gate before a fresh iteration.
|
|
28
28
|
- \`iterate_defense_events\` — defense event stream (\`.iterate/defense-events.json\`): \`list\`/\`counts\` review precondition failures, rollbacks, invariant violations, and falsified assumptions; \`record\` logs a new event when a defense fires. Human-readable labels follow the project \`language\` (en/zh).
|
|
@@ -62,6 +62,7 @@ final review report. NO file writes, NO git, NO branches, NO worktree.
|
|
|
62
62
|
Canonical script — reproduce this structure exactly (adjust dims via the plan):
|
|
63
63
|
|
|
64
64
|
\`\`\`js
|
|
65
|
+
// args = { mode: "dry-run", maxRounds?, subagentProvider?, subagentModel?, attachments? }
|
|
65
66
|
phase('plan')
|
|
66
67
|
// Optional per-run backend override for sub-agents (omit to inherit the session backend).
|
|
67
68
|
const subAgentProvider = (args && args.subagentProvider) || undefined
|
|
@@ -70,7 +71,7 @@ const backend = Object.assign({}, subAgentProvider ? { provider: subAgentProvide
|
|
|
70
71
|
// User-attached image evidence relayed into reviewer prompts (metadata only).
|
|
71
72
|
const attachments = (args && Array.isArray(args.attachments)) ? args.attachments : []
|
|
72
73
|
const planRes = await agent(
|
|
73
|
-
'Call iterate_review({operation:"plan", mode:"dry-run"}) and return the plan JSON.',
|
|
74
|
+
'Call iterate_review({operation:"plan", mode:"dry-run"' + (args.maxRounds ? ', maxReviewRounds:' + args.maxRounds : '') + '}) and return the plan JSON.',
|
|
74
75
|
Object.assign({ label: 'review:plan' }, backend)
|
|
75
76
|
)
|
|
76
77
|
const plan = (planRes && planRes.plan) ? planRes.plan : null
|
|
@@ -88,25 +89,31 @@ let lastRoundOk = true
|
|
|
88
89
|
// run starts at startRound > 1, so the round NUMBER is not a valid array index.
|
|
89
90
|
let roundSlot = -1
|
|
90
91
|
|
|
91
|
-
phase('transcript')
|
|
92
|
-
// Read any steering nudge written (via iterate_transcript nudge) for this run's reviewers.
|
|
93
|
-
const transRead = await agent(
|
|
94
|
-
'Call iterate_transcript({operation:"read"}) and return {nudge:<transcript.nudge ? transcript.nudge.text : null>}.',
|
|
95
|
-
Object.assign({ label: 'transcript:read' }, backend)
|
|
96
|
-
)
|
|
97
|
-
const steering = transRead && typeof transRead.nudge === 'string' && transRead.nudge ? transRead.nudge : null
|
|
98
|
-
|
|
99
92
|
phase('review')
|
|
100
93
|
for (let r = 1; r <= maxRounds; r++) {
|
|
94
|
+
// Re-read the steering nudge at the start of EVERY round (not once before
|
|
95
|
+
// the loop): iterate_transcript nudge promises to steer "the next round's
|
|
96
|
+
// reviewers", so a nudge written mid-run must reach round 2+ — a single
|
|
97
|
+
// pre-loop read froze the round-1 nudge for the whole run.
|
|
98
|
+
const transRead = await agent(
|
|
99
|
+
'Call iterate_transcript({operation:"read"}) and return {nudge:<transcript.nudge ? transcript.nudge.text : null>}.',
|
|
100
|
+
Object.assign({ label: 'transcript:read:r' + r }, backend)
|
|
101
|
+
)
|
|
102
|
+
const steering = transRead && typeof transRead.nudge === 'string' && transRead.nudge ? transRead.nudge : null
|
|
101
103
|
log('round ' + r + ' of ' + maxRounds + ' — finding NEW issues only')
|
|
102
104
|
roundSlot = rounds.length
|
|
103
105
|
let agg = null
|
|
104
106
|
let schemaInvalid = false
|
|
105
107
|
let attempts = 0
|
|
106
|
-
// Declared OUTSIDE the do-block:
|
|
107
|
-
// block-scoped
|
|
108
|
-
// canonical workflows after the first round)
|
|
108
|
+
// Declared OUTSIDE the do-block: both are read after the retry loop exits,
|
|
109
|
+
// and block-scoped consts here raised ReferenceError at runtime (crashing
|
|
110
|
+
// both canonical workflows after the first round) whenever the aggregate
|
|
111
|
+
// subagent resolved null — or an object without a report — and the
|
|
112
|
+
// convergence fallback below reached thisRound.findings.
|
|
109
113
|
let reviewersOk = true
|
|
114
|
+
// Safe empty shape: the do-block always overwrites it, but the post-loop
|
|
115
|
+
// read must never depend on block scope again.
|
|
116
|
+
let thisRound = { round: r, findings: [], readFiles: [] }
|
|
110
117
|
do {
|
|
111
118
|
attempts += 1
|
|
112
119
|
// Schema validation retry: on the 2nd+ pass, nudge reviewers toward strict JSON.
|
|
@@ -135,7 +142,7 @@ for (let r = 1; r <= maxRounds; r++) {
|
|
|
135
142
|
// round is NOT a clean pass — it is inconclusive, so the convergence gate
|
|
136
143
|
// below refuses it before any "converged" signal fires.
|
|
137
144
|
reviewersOk = raw.length > 0 ? raw.some(x => x !== null && typeof x === 'object') : true
|
|
138
|
-
|
|
145
|
+
thisRound = {
|
|
139
146
|
round: r,
|
|
140
147
|
findings: [].concat(...raw.map(x => x && x.findings ? x.findings : [])),
|
|
141
148
|
// readFiles are threaded through so the aggregate/meta-review coverage
|
|
@@ -210,10 +217,45 @@ const metaRes = await agent(
|
|
|
210
217
|
const finalReport = metaRes && metaRes.finalReport ? metaRes.finalReport : null
|
|
211
218
|
const metaAudit = finalReport && finalReport.metaReview ? finalReport.metaReview : null
|
|
212
219
|
|
|
220
|
+
// Compute the final flags ONCE, before the capture: the capture must persist
|
|
221
|
+
// the SAME stoppedReason the caller receives. Previously the capture omitted
|
|
222
|
+
// the computed reason, so the transcript tool derived a wrong one from the
|
|
223
|
+
// trend (an inconclusive run was stored as "converged"/"max_rounds_reached").
|
|
224
|
+
const convergedFinal = report.convergence.converged && lastRoundOk
|
|
225
|
+
// The aggregate's convergence flag is only trustworthy when the last round
|
|
226
|
+
// was usable — an all-failed/schema-invalid final round looks like "0 new"
|
|
227
|
+
// to the convergence math but is an inconclusive run, never a clean pass.
|
|
228
|
+
const stoppedReason = report.convergence.converged && !lastRoundOk
|
|
229
|
+
? 'inconclusive'
|
|
230
|
+
: report.convergence.stoppedReason
|
|
231
|
+
|
|
232
|
+
// F8 (quality gate): persist a certificate for the read-only review too, so
|
|
233
|
+
// the quality tab has data after a dry-run as well. A dry-run never fixes
|
|
234
|
+
// anything (fixedByDimension omitted → 0) and never executes a validation
|
|
235
|
+
// command (validationResults omitted → verification 0/0, never a fabricated
|
|
236
|
+
// check) — the snapshot reflects review findings + convergence only.
|
|
237
|
+
const drySeries = Object.create(null)
|
|
238
|
+
for (const dim of dims) drySeries[dim] = new Array(rounds.length).fill(0)
|
|
239
|
+
for (let i = 0; i < rounds.length; i++) {
|
|
240
|
+
for (const f of (rounds[i].findings || [])) {
|
|
241
|
+
if (f && typeof f === 'object') {
|
|
242
|
+
const s = drySeries[String(f.dimension)]
|
|
243
|
+
if (Array.isArray(s) && i < s.length) s[i] += 1
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
await agent(
|
|
248
|
+
'Call iterate_quality_gate({operation:"compute", dimensions:' + JSON.stringify(dims) +
|
|
249
|
+
', findings:' + JSON.stringify(Array.isArray(report.findings) ? report.findings : known) +
|
|
250
|
+
', findingsByRound:' + JSON.stringify(drySeries) + '}) and return {ok, snapshot, warnings}.',
|
|
251
|
+
Object.assign({ label: 'quality-gate:compute' }, backend)
|
|
252
|
+
)
|
|
253
|
+
|
|
213
254
|
// Persist the run's observatory transcript (reviewer threads, trend, findings)
|
|
214
255
|
// so the client observatory panel reflects this review. Writes ONLY .iterate/transcript.json.
|
|
256
|
+
// A dry-run executes no validation commands, so its \`validations\` is always [].
|
|
215
257
|
await agent(
|
|
216
|
-
'Call iterate_transcript({operation:"capture", mode:"dry-run", goal:' + JSON.stringify(report.goal) + ', maxRounds:' + maxRounds + ', roundsExecuted:' + report.convergence.totalRounds + ', findingsByRound:' + JSON.stringify(report.convergence.findingsByRound || []) + ', rounds:' + JSON.stringify(rounds.map(rr => ({ round: rr.round, findings: rr.findings, readFiles: rr.readFiles }))) + '}). Return {operation:"ok"}.',
|
|
258
|
+
'Call iterate_transcript({operation:"capture", mode:"dry-run", goal:' + JSON.stringify(report.goal) + ', maxRounds:' + maxRounds + ', roundsExecuted:' + report.convergence.totalRounds + ', findingsByRound:' + JSON.stringify(report.convergence.findingsByRound || []) + ', stoppedReason:"' + stoppedReason + '", validations:[], rounds:' + JSON.stringify(rounds.map(rr => ({ round: rr.round, findings: rr.findings, readFiles: rr.readFiles }))) + '}). Return {operation:"ok"}.',
|
|
217
259
|
Object.assign({ label: 'transcript:capture' }, backend)
|
|
218
260
|
)
|
|
219
261
|
|
|
@@ -221,13 +263,8 @@ return {
|
|
|
221
263
|
mode: 'dry-run',
|
|
222
264
|
goal: report.goal,
|
|
223
265
|
rounds: rounds.length,
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
// to the convergence math but is an inconclusive run, never a clean pass.
|
|
227
|
-
converged: report.convergence.converged && lastRoundOk,
|
|
228
|
-
stoppedReason: report.convergence.converged && !lastRoundOk
|
|
229
|
-
? 'inconclusive'
|
|
230
|
-
: report.convergence.stoppedReason,
|
|
266
|
+
converged: convergedFinal,
|
|
267
|
+
stoppedReason: stoppedReason,
|
|
231
268
|
findingsByRound: report.convergence.findingsByRound,
|
|
232
269
|
totalFindings: report.summary.totalFindings,
|
|
233
270
|
bySeverity: { critical: report.summary.critical, high: report.summary.high, medium: report.summary.medium, low: report.summary.low },
|
|
@@ -246,7 +283,7 @@ Key rules for dry-run:
|
|
|
246
283
|
- Stop when a round reports 0 new findings (converged) or maxReviewRounds is reached.
|
|
247
284
|
- The report (with per-round convergence stats + suggested fix priorities) is the deliverable.
|
|
248
285
|
- **Meta-review**: after building the report, audit it with \`iterate_review({operation:"meta-review"})\` for internal consistency (counts, severity buckets, dimension sums, sort order, convergence math). The meta-review ALSO runs the hard code-evidence gate (default on): every finding's file/line is validated against real files on disk, so any fabricated location surfaces as a critical \`EVIDENCE_VIOLATION\` and flips the verdict to \`needs_revision\`. The \`finalReport.verdict\` is \`approved\` only when the report passes every check AND every finding anchors to real, read code; otherwise \`needs_revision\`. Surface the final report and its verdict as the closing deliverable.
|
|
249
|
-
- Only a single \`report\` entry may be appended to the decision log; nothing else is written to source files. The final \`iterate_transcript capture\` writes ONLY the observatory file (\`.iterate/transcript.json\`) so the client panel reflects the run — it is not a source-code write.
|
|
286
|
+
- Only a single \`report\` entry may be appended to the decision log; nothing else is written to source files. The final \`iterate_transcript capture\` writes ONLY the observatory file (\`.iterate/transcript.json\`) so the client panel reflects the run — it is not a source-code write. The capture carries the computed \`stoppedReason\` (e.g. \`inconclusive\` for a run whose last round was unusable) so the panel shows why the run actually ended instead of the tool guessing from the trend.
|
|
250
287
|
|
|
251
288
|
### Normal-mode workflow (autonomous closed loop)
|
|
252
289
|
Set \`args.mode = "normal"\`. Loop: resume → plan → parallel review ×N → atomic fixes via \`iterate_fix\` → validate → rollback on failure → checkpoint → loop → auto-stop when zero findings remain.
|
|
@@ -260,18 +297,60 @@ const subAgentModel = (args && args.subagentModel) || undefined
|
|
|
260
297
|
const backend = Object.assign({}, subAgentProvider ? { provider: subAgentProvider } : {}, subAgentModel ? { model: subAgentModel } : {})
|
|
261
298
|
// User-attached image evidence relayed into reviewer prompts (metadata only).
|
|
262
299
|
const attachments = (args && Array.isArray(args.attachments)) ? args.attachments : []
|
|
300
|
+
phase('preflight')
|
|
301
|
+
// PREFLIGHT (#2): with NO configured validation.commands this loop would run
|
|
302
|
+
// zero validations every round and still report green (fails OPEN). Read the
|
|
303
|
+
// config BEFORE any work and stop with an actionable message — unless the
|
|
304
|
+
// caller explicitly opted into an unverified run (args.unverified === true).
|
|
305
|
+
const preCfgRes = await agent(
|
|
306
|
+
'Call iterate_config({}) and return the config JSON.',
|
|
307
|
+
Object.assign({ label: 'config:preflight' }, backend)
|
|
308
|
+
)
|
|
309
|
+
const preCfg = (preCfgRes && preCfgRes.config) ? preCfgRes.config : null
|
|
310
|
+
const validationCmds = []
|
|
311
|
+
const cfgCommands = preCfg && preCfg.validation && preCfg.validation.commands
|
|
312
|
+
if (cfgCommands && typeof cfgCommands === 'object') {
|
|
313
|
+
for (const group of Object.values(cfgCommands)) {
|
|
314
|
+
if (Array.isArray(group)) {
|
|
315
|
+
for (const c of group) { if (typeof c === 'string' && c.trim()) validationCmds.push(c) }
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
// Explicit USER opt-in: proceed knowing nothing will be verified (UNVERIFIED).
|
|
320
|
+
const unverified = !!(args && args.unverified === true)
|
|
321
|
+
if (validationCmds.length === 0 && !unverified) {
|
|
322
|
+
throw new Error(
|
|
323
|
+
'preflight failed: iterate.config.yaml has NO validation.commands — this iteration would be protected by NO test. ' +
|
|
324
|
+
'Configure at least one trusted command with iterate_config({operation:"write", updates:{validation:{commands:{test:["<command>"]}}}}) ' +
|
|
325
|
+
'(e.g. "npm test"), then re-run; or pass args.unverified:true to proceed WITHOUT verification — the run will then be reported as UNVERIFIED (zero-validation), never as a verified pass.'
|
|
326
|
+
)
|
|
327
|
+
}
|
|
328
|
+
if (validationCmds.length === 0) {
|
|
329
|
+
log('preflight: no validation.commands configured — proceeding as an EXPLICIT unverified run (args.unverified); every round is UNVERIFIED')
|
|
330
|
+
}
|
|
263
331
|
phase('resume')
|
|
264
332
|
// If a previous run was interrupted, resume from its checkpoint instead of restarting.
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
333
|
+
// Use operation:"resume" (NOT plain "load"): the tool loads, bumps AND PERSISTS
|
|
334
|
+
// resumeCount itself, so a run that is interrupted again before its first save
|
|
335
|
+
// still counts this resumption — and re-adding +1 here on top of the tool's
|
|
336
|
+
// bump would double-count. A failed resume (fresh run with no checkpoint, or a
|
|
337
|
+
// persist error on a real one) falls back to a plain "load" so the state is
|
|
338
|
+
// never lost.
|
|
339
|
+
const resumeRes = await agent(
|
|
340
|
+
'Call iterate_checkpoint({ operation: "resume" }) and return {ok, checkpoint, error}.',
|
|
341
|
+
Object.assign({ label: 'checkpoint:resume' }, backend)
|
|
268
342
|
)
|
|
269
|
-
|
|
343
|
+
let checkpoint = (resumeRes && resumeRes.ok !== false && resumeRes.checkpoint) ? resumeRes.checkpoint : null
|
|
344
|
+
if (!checkpoint) {
|
|
345
|
+
const loadRes = await agent(
|
|
346
|
+
'Call iterate_checkpoint({ operation: "load" }) and return the checkpoint JSON.',
|
|
347
|
+
Object.assign({ label: 'checkpoint:load' }, backend)
|
|
348
|
+
)
|
|
349
|
+
checkpoint = (loadRes && loadRes.checkpoint) ? loadRes.checkpoint : null
|
|
350
|
+
}
|
|
270
351
|
const startRound = (checkpoint && typeof checkpoint.round === 'number') ? checkpoint.round + 1 : 1
|
|
271
|
-
//
|
|
272
|
-
const
|
|
273
|
-
// The effective count AFTER this recovery: this run counts as one more resume.
|
|
274
|
-
const effectiveResumeCount = checkpoint ? resumeCount + 1 : 0
|
|
352
|
+
// Already-bumped count returned by the tool's resume (0 when there was nothing to resume).
|
|
353
|
+
const effectiveResumeCount = (checkpoint && typeof checkpoint.resumeCount === 'number') ? checkpoint.resumeCount : 0
|
|
275
354
|
if (checkpoint) {
|
|
276
355
|
// A previous run left a checkpoint — record the recovery so the decision log
|
|
277
356
|
// shows the resume, then continue where it left off.
|
|
@@ -298,15 +377,37 @@ const knownIntentional = (plan.knownIntentional || []) // config personalizati
|
|
|
298
377
|
const dims = plan.dimensions.map(d => d.id)
|
|
299
378
|
const maxRounds = plan.maxReviewRounds
|
|
300
379
|
const rounds = [] // findings per review round (each on the then-current code state)
|
|
380
|
+
// Per-round AGGREGATE findings (deduped / known_intentional-filtered /
|
|
381
|
+
// schema-validated — the same set \`atomic\`/\`remaining\` act on). F8's quality
|
|
382
|
+
// certificate is computed from these, never from raw reviewer output.
|
|
383
|
+
const roundReports = []
|
|
301
384
|
// Restore previously-unfixed architectural findings when resuming an interrupted run.
|
|
302
385
|
const architectural = (checkpoint && Array.isArray(checkpoint.findings)) ? checkpoint.findings : [] // findings deliberately left unfixed (reported at the end)
|
|
303
386
|
let fixedCount = (checkpoint && typeof checkpoint.fixedCount === 'number') ? checkpoint.fixedCount : 0
|
|
304
387
|
let converged = false
|
|
305
388
|
let abortedByValidation = false
|
|
306
389
|
let schemaFailed = false // last round produced no usable reviewer output (schema-invalid after retries / all reviewers failed)
|
|
390
|
+
let validationUnavailable = false // the validate subagent itself failed (null / no results) — validation could not run, so the round is UNVERIFIED
|
|
307
391
|
let failedCommands = []
|
|
308
392
|
let configErrors = [] // validation commands NOT in validation.commands (config gap, no rollback)
|
|
309
393
|
const fixRecords = [] // observatory fix records collected round by round
|
|
394
|
+
// Every validation outcome captured for the transcript (round + command +
|
|
395
|
+
// exitCode + allowed) — persisted via \`iterate_transcript capture\` so the run
|
|
396
|
+
// console can show WHICH commands ran and whether they passed (#6).
|
|
397
|
+
const validationRecords = []
|
|
398
|
+
// F10 (defense events): rollbacks / precondition failures fire during the
|
|
399
|
+
// loop; \`recordDefense\` logs each one to \`.iterate/defense-events.json\`.
|
|
400
|
+
// Labels follow the project \`language\` inside the tool.
|
|
401
|
+
const recordDefense = (type, roundNo, description, defense, outcome) =>
|
|
402
|
+
agent(
|
|
403
|
+
'Call iterate_defense_events({operation:"record", type:' + JSON.stringify(type) +
|
|
404
|
+
', round:' + roundNo +
|
|
405
|
+
', severity:' + (type === 'rollback' ? '"high"' : '"medium"') +
|
|
406
|
+
', description:' + JSON.stringify(description) +
|
|
407
|
+
', defense:' + JSON.stringify(defense) +
|
|
408
|
+
', outcome:' + JSON.stringify(outcome) + '}). Return {operation:"ok"}.',
|
|
409
|
+
Object.assign({ label: 'defense:' + type + ':r' + roundNo }, backend)
|
|
410
|
+
)
|
|
310
411
|
// Slot index of the current round within this run's rounds array. A resumed
|
|
311
412
|
// run starts at startRound > 1, so the round NUMBER is not a valid array index.
|
|
312
413
|
let roundSlot = -1
|
|
@@ -314,15 +415,17 @@ let roundSlot = -1
|
|
|
314
415
|
// reports its true round, not the count of rounds it happened to run).
|
|
315
416
|
let lastRound = startRound - 1
|
|
316
417
|
|
|
317
|
-
// Read any steering nudge intended for this run's reviewers.
|
|
318
|
-
const transRead = await agent(
|
|
319
|
-
'Call iterate_transcript({operation:"read"}) and return {nudge:<transcript.nudge ? transcript.nudge.text : null>}.',
|
|
320
|
-
Object.assign({ label: 'transcript:read' }, backend)
|
|
321
|
-
)
|
|
322
|
-
const steering = transRead && typeof transRead.nudge === 'string' && transRead.nudge ? transRead.nudge : null
|
|
323
|
-
|
|
324
418
|
phase('loop')
|
|
325
419
|
for (let r = startRound; r <= maxRounds; r++) {
|
|
420
|
+
// Re-read the steering nudge at the start of EVERY round (not once before
|
|
421
|
+
// the loop): iterate_transcript nudge promises to steer "the next round's
|
|
422
|
+
// reviewers", so a nudge written mid-run must reach round 2+ — a single
|
|
423
|
+
// pre-loop read froze the round-1 nudge for the whole run.
|
|
424
|
+
const transRead = await agent(
|
|
425
|
+
'Call iterate_transcript({operation:"read"}) and return {nudge:<transcript.nudge ? transcript.nudge.text : null>}.',
|
|
426
|
+
Object.assign({ label: 'transcript:read:r' + r }, backend)
|
|
427
|
+
)
|
|
428
|
+
const steering = transRead && typeof transRead.nudge === 'string' && transRead.nudge ? transRead.nudge : null
|
|
326
429
|
log('round ' + r + ' of ' + maxRounds + ' — review current state, fix atomics via iterate_fix, validate')
|
|
327
430
|
roundSlot = rounds.length
|
|
328
431
|
lastRound = r
|
|
@@ -334,10 +437,14 @@ for (let r = startRound; r <= maxRounds; r++) {
|
|
|
334
437
|
let agg = null
|
|
335
438
|
let schemaInvalid = false
|
|
336
439
|
let attempts = 0
|
|
337
|
-
// Declared OUTSIDE the do-block:
|
|
338
|
-
// block-scoped
|
|
339
|
-
// canonical workflows after the first round)
|
|
440
|
+
// Declared OUTSIDE the do-block: both are read after the retry loop exits,
|
|
441
|
+
// and block-scoped consts here raised ReferenceError at runtime (crashing
|
|
442
|
+
// both canonical workflows after the first round) whenever the aggregate
|
|
443
|
+
// subagent resolved null — the findings fallback below read thisRound.
|
|
340
444
|
let reviewersOk = true
|
|
445
|
+
// Safe empty shape: the do-block always overwrites it, but the post-loop
|
|
446
|
+
// read must never depend on block scope again.
|
|
447
|
+
let thisRound = { round: r, findings: [], readFiles: [] }
|
|
341
448
|
do {
|
|
342
449
|
attempts += 1
|
|
343
450
|
// Schema validation retry: on the 2nd+ pass, nudge reviewers toward strict JSON.
|
|
@@ -362,7 +469,7 @@ for (let r = startRound; r <= maxRounds; r++) {
|
|
|
362
469
|
// no usable output — an empty aggregate must not read like a clean
|
|
363
470
|
// "nothing to fix" convergence. Gate the loop exit + convergence on it.
|
|
364
471
|
reviewersOk = raw.length > 0 ? raw.some(x => x !== null && typeof x === 'object') : true
|
|
365
|
-
|
|
472
|
+
thisRound = {
|
|
366
473
|
round: r,
|
|
367
474
|
findings: [].concat(...raw.map(x => x && x.findings ? x.findings : [])),
|
|
368
475
|
readFiles: [].concat(...raw.map(x => x && Array.isArray(x.readFiles) ? x.readFiles : [])),
|
|
@@ -385,6 +492,11 @@ for (let r = startRound; r <= maxRounds; r++) {
|
|
|
385
492
|
log('retry ' + attempts + ': round ' + r + ' output failed schema validation — re-running reviewers with strict-JSON emphasis')
|
|
386
493
|
}
|
|
387
494
|
} while (schemaInvalid && attempts < 3)
|
|
495
|
+
// Freeze the round's aggregate findings for the final F8 gate — the raw
|
|
496
|
+
// reviewer output above may still hold duplicates the aggregate dropped.
|
|
497
|
+
roundReports[roundSlot] = (agg && agg.report && Array.isArray(agg.report.findings))
|
|
498
|
+
? agg.report.findings
|
|
499
|
+
: thisRound.findings
|
|
388
500
|
if (schemaInvalid || !reviewersOk) {
|
|
389
501
|
// Bounded exit: never loop forever, and never let an all-failed/empty round
|
|
390
502
|
// read like a clean convergence. Stop the run WITHOUT applying fixes for
|
|
@@ -397,6 +509,8 @@ for (let r = startRound; r <= maxRounds; r++) {
|
|
|
397
509
|
'Call iterate_decision_log({operation:"append", type:"round_failed", round:' + r + ', data:{reason:"' + (schemaInvalid ? 'schema_invalid' : 'no_usable_reviewer_output') + '", rolledBack:0}})',
|
|
398
510
|
Object.assign({ label: 'log:schemaFailed:r' + r }, backend)
|
|
399
511
|
)
|
|
512
|
+
// F10: an unusable round is a precondition failure the gate could not clear.
|
|
513
|
+
await recordDefense('precondition_failed', r, 'reviewer output unusable: ' + (schemaInvalid ? 'schema-invalid after 3 attempts' : 'all reviewers failed'), 'reviewer output schema gate', 'round inconclusive; run stopped WITHOUT fixes (never reported as converged)')
|
|
400
514
|
break
|
|
401
515
|
}
|
|
402
516
|
const findings = (agg && agg.report && agg.report.findings) ? agg.report.findings : thisRound.findings
|
|
@@ -409,7 +523,13 @@ for (let r = startRound; r <= maxRounds; r++) {
|
|
|
409
523
|
// calling iterate_fix per finding (the ONLY sanctioned writer), then
|
|
410
524
|
// iterate_diff to verify — so the same file is never edited concurrently;
|
|
411
525
|
// different files still run in parallel.
|
|
412
|
-
|
|
526
|
+
// Null-prototype map: f.file is MODEL-CONTROLLED, and on a plain {} a
|
|
527
|
+
// finding with file "__proto__" or "constructor" resolves to
|
|
528
|
+
// Object.prototype/Object — the "|| []" keeps that inherited object and
|
|
529
|
+
// ".push(f)" then throws TypeError, killing the whole run. With
|
|
530
|
+
// Object.create(null) every key is an own property, and Object.keys(byFile)
|
|
531
|
+
// (the only downstream usage) works unchanged.
|
|
532
|
+
const byFile = Object.create(null)
|
|
413
533
|
atomic.forEach(f => { (byFile[f.file] = byFile[f.file] || []).push(f) })
|
|
414
534
|
const fixRes = await parallel(Object.keys(byFile).map(file => () => agent(
|
|
415
535
|
'Apply the fixes for ' + JSON.stringify(file) + ' using iterate_fix. For EACH finding in this list, ' +
|
|
@@ -444,6 +564,14 @@ for (let r = startRound; r <= maxRounds; r++) {
|
|
|
444
564
|
}
|
|
445
565
|
}
|
|
446
566
|
}
|
|
567
|
+
// F10: a fix iterate_fix REFUSED (at this point in the round success:false
|
|
568
|
+
// can only mean the tool refused it — rollbacks flip records later) means
|
|
569
|
+
// the reviewer's \`is_atomic\` assumption was wrong: the change did not fit
|
|
570
|
+
// the atomic limit. That is a falsified assumption, not a code failure.
|
|
571
|
+
const refusedFixes = fixRecords.filter(fr => fr.round === r && fr.success === false)
|
|
572
|
+
if (refusedFixes.length > 0) {
|
|
573
|
+
await recordDefense('assumption_falsified', r, refusedFixes.length + ' finding(s) marked atomic could not be applied by iterate_fix', 'finding judged is_atomic (change ≤ ' + atomicMaxLines + ' lines in one file)', 'fix refused — the atomicity assumption was wrong for these findings; they stay open for a follow-up round')
|
|
574
|
+
}
|
|
447
575
|
}
|
|
448
576
|
|
|
449
577
|
// Cross-round dedupe of architectural findings before accumulating.
|
|
@@ -458,17 +586,73 @@ for (let r = startRound; r <= maxRounds; r++) {
|
|
|
458
586
|
// when a command is NOT in validation.commands (a config gap, NOT a code
|
|
459
587
|
// failure) — those abort the run WITHOUT rolling back (the code changes are
|
|
460
588
|
// fine; the trust list just needs fixing).
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
589
|
+
let valResults = []
|
|
590
|
+
if (unverified) {
|
|
591
|
+
// Explicit user opt-in chosen at the preflight above: NOTHING is configured
|
|
592
|
+
// to validate, so validation is skipped DELIBERATELY — never silently.
|
|
593
|
+
// The round runs UNVERIFIED and the final report/stoppedReason carry
|
|
594
|
+
// zeroValidation so it can never read as a verified pass.
|
|
595
|
+
log('round ' + r + ' UNVERIFIED (args.unverified, no validation.commands) — skipping validation for this round')
|
|
596
|
+
} else {
|
|
597
|
+
const valRes = await agent(
|
|
598
|
+
'Read iterate.config.yaml validation.commands, then call iterate_validate({ command: <cmd> }) for EACH configured command ' +
|
|
599
|
+
'(one tool call per command). Return all results as {command, exitCode, allowed, rejectReason} entries — include \`allowed\` and \`rejectReason\` exactly as returned by iterate_validate (allowed:false means the command is not in validation.commands).',
|
|
600
|
+
Object.assign({ label: 'validate:r' + r, phase: 'validate', schema: {
|
|
601
|
+
type: 'object', additionalProperties: false,
|
|
602
|
+
properties: {
|
|
603
|
+
results: { type: 'array', items: { type: 'object', additionalProperties: false, properties: { command: { type: 'string' }, exitCode: { type: 'integer' }, allowed: { type: 'boolean' }, rejectReason: { type: 'string' } }, required: ['command', 'exitCode'] } }
|
|
604
|
+
},
|
|
605
|
+
required: ['results'] } }, backend)
|
|
606
|
+
)
|
|
607
|
+
if (!valRes || !Array.isArray(valRes.results)) {
|
|
608
|
+
// A FAILED validate subagent (null / missing results) must abort the run
|
|
609
|
+
// exactly like a validation failure: collapsing it to [] would mark every
|
|
610
|
+
// command as passed, skip the failure branch below, and continue as if the
|
|
611
|
+
// round were verified (fails OPEN). Stop here — before the checkpoint save
|
|
612
|
+
// and the next round — keeping the round's fixes on disk (they may be
|
|
613
|
+
// fine) but UNVERIFIED, with the checkpoint left in place for a resume.
|
|
614
|
+
validationUnavailable = true
|
|
615
|
+
abortedByValidation = true
|
|
616
|
+
log('round ' + r + ' validation could NOT run (iterate_validate subagent failed) — stopping run; fixes from this round are kept but UNVERIFIED')
|
|
617
|
+
await agent(
|
|
618
|
+
'Call iterate_decision_log({operation:"append", type:"round_failed", round:' + r + ', data:{reason:"validation_unavailable", rolledBack:0}})',
|
|
619
|
+
Object.assign({ label: 'log:valUnavailable:r' + r }, backend)
|
|
620
|
+
)
|
|
621
|
+
await recordDefense('precondition_failed', r, 'validation subagent failed — no command could run', 'validate subagent unavailable', 'round stopped with fixes kept UNVERIFIED (no rollback)')
|
|
622
|
+
break
|
|
623
|
+
}
|
|
624
|
+
valResults = valRes.results
|
|
625
|
+
if (valResults.length === 0) {
|
|
626
|
+
// ZERO results (#2): the validator returned an EMPTY set, so NO
|
|
627
|
+
// configured command was actually executed this round. An empty result
|
|
628
|
+
// is NOT a pass — treat it exactly like a failed validator (fail CLOSED)
|
|
629
|
+
// instead of letting a zero-verification round look green. The preflight
|
|
630
|
+
// above already blocks the "no commands configured" case, so reaching
|
|
631
|
+
// here means the run simply verified nothing.
|
|
632
|
+
validationUnavailable = true
|
|
633
|
+
abortedByValidation = true
|
|
634
|
+
log('round ' + r + ' validation produced ZERO results — stopping run (a round with no executed validation is never a pass)')
|
|
635
|
+
await agent(
|
|
636
|
+
'Call iterate_decision_log({operation:"append", type:"round_failed", round:' + r + ', data:{reason:"zero_validation_results", rolledBack:0}})',
|
|
637
|
+
Object.assign({ label: 'log:zeroValidation:r' + r }, backend)
|
|
638
|
+
)
|
|
639
|
+
await recordDefense('precondition_failed', r, 'validation produced zero results — no command ran', 'validation result gate', 'round stopped with fixes kept UNVERIFIED (no rollback)')
|
|
640
|
+
break
|
|
641
|
+
}
|
|
642
|
+
// Persist every outcome for the transcript console (#6): command, exit
|
|
643
|
+
// code, allow-list verdict, and the reject reason when the list refused it.
|
|
644
|
+
for (const v of valResults) {
|
|
645
|
+
if (v && typeof v === 'object') {
|
|
646
|
+
validationRecords.push({
|
|
647
|
+
round: r,
|
|
648
|
+
command: typeof v.command === 'string' ? v.command : '',
|
|
649
|
+
exitCode: typeof v.exitCode === 'number' && isFinite(v.exitCode) ? Math.floor(v.exitCode) : null,
|
|
650
|
+
allowed: v.allowed === true,
|
|
651
|
+
rejectReason: (typeof v.rejectReason === 'string' && v.rejectReason) ? v.rejectReason : undefined
|
|
652
|
+
})
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
}
|
|
472
656
|
configErrors = valResults.filter(v => v.allowed === false).map(v => v.rejectReason || (v.command + ' was rejected'))
|
|
473
657
|
failedCommands = valResults.filter(v => !(v.allowed === false) && v.exitCode !== 0).map(v => v.command)
|
|
474
658
|
if (configErrors.length > 0) {
|
|
@@ -478,6 +662,7 @@ for (let r = startRound; r <= maxRounds; r++) {
|
|
|
478
662
|
'Call iterate_decision_log({operation:"append", type:"round_failed", round:' + r + ', data:{configErrors:' + JSON.stringify(configErrors) + ', rolledBack:0, reason:"command not in validation.commands"}})',
|
|
479
663
|
Object.assign({ label: 'log:configError:r' + r }, backend)
|
|
480
664
|
)
|
|
665
|
+
await recordDefense('precondition_failed', r, 'command not in validation.commands: ' + configErrors.join(' | '), 'validation command allow-list', 'run aborted WITHOUT rollback; the trust list needs updating')
|
|
481
666
|
break
|
|
482
667
|
}
|
|
483
668
|
if (failedCommands.length > 0) {
|
|
@@ -493,14 +678,69 @@ for (let r = startRound; r <= maxRounds; r++) {
|
|
|
493
678
|
},
|
|
494
679
|
required: ['results'] } }, backend)
|
|
495
680
|
)
|
|
681
|
+
// The round's fixes were reverted on disk — the observatory records and
|
|
682
|
+
// the running fixedCount must stop counting them as applied, otherwise
|
|
683
|
+
// findingsFixed / the final capture would report rolled-back work as
|
|
684
|
+
// done. Each roundFixId was pushed with success:true exactly once, so
|
|
685
|
+
// the guard keeps the decrement single-shot per fix.
|
|
686
|
+
for (const rec of fixRecords) {
|
|
687
|
+
if (rec.round === r && rec.success && roundFixIds.indexOf(rec.id) >= 0) {
|
|
688
|
+
rec.success = false
|
|
689
|
+
fixedCount -= 1
|
|
690
|
+
}
|
|
691
|
+
}
|
|
496
692
|
}
|
|
497
693
|
await agent(
|
|
498
694
|
'Call iterate_decision_log({operation:"append", type:"round_failed", round:' + r + ', data:{failedCommands:' + JSON.stringify(failedCommands) + ', rolledBack:' + roundFixIds.length + '}})',
|
|
499
695
|
Object.assign({ label: 'log:failed:r' + r }, backend)
|
|
500
696
|
)
|
|
697
|
+
// F10: every rollback is a defense event the F10 tab surfaces as a count.
|
|
698
|
+
await recordDefense('rollback', r, 'validation failed on: ' + failedCommands.join(', '), 'iterate_rollback reverted the round-' + r + ' fixes', roundFixIds.length + ' fix(es) reverted; run stopped (checkpoint kept for resume)')
|
|
501
699
|
break
|
|
502
700
|
}
|
|
503
701
|
|
|
702
|
+
// F9 (experience bank): validation PASSED for this round, so these fixes are
|
|
703
|
+
// VERIFIED — bank them before moving on. An UNVERIFIED run banks NOTHING:
|
|
704
|
+
// with no validation command executed there is no proof the fix worked.
|
|
705
|
+
// \`iterate_experience add\` dedupes on
|
|
706
|
+
// pattern+dimension (repeat = hit count bump), so a re-discovered finding
|
|
707
|
+
// never floods the bank. Each successful fix record is paired with the next
|
|
708
|
+
// unused atomic finding of the same file (fixes are per-file, in order).
|
|
709
|
+
if (roundFixIds.length > 0 && !unverified) {
|
|
710
|
+
const expByFile = Object.create(null)
|
|
711
|
+
for (const f of atomic) { (expByFile[f.file] = expByFile[f.file] || []).push(f) }
|
|
712
|
+
const expUsed = Object.create(null)
|
|
713
|
+
const expEntries = []
|
|
714
|
+
for (const rec of fixRecords) {
|
|
715
|
+
if (rec.round !== r || !rec.success || roundFixIds.indexOf(rec.id) < 0) continue
|
|
716
|
+
const pool = expByFile[rec.file] || []
|
|
717
|
+
let finding = null
|
|
718
|
+
for (let i = 0; i < pool.length; i++) {
|
|
719
|
+
const key = rec.file + '#' + i
|
|
720
|
+
if (!expUsed[key]) { expUsed[key] = true; finding = pool[i]; break }
|
|
721
|
+
}
|
|
722
|
+
if (!finding) continue
|
|
723
|
+
expEntries.push({
|
|
724
|
+
pattern: String(finding.summary || finding.dimension || 'atomic fix'),
|
|
725
|
+
dimension: String(finding.dimension || 'general'),
|
|
726
|
+
description: String(finding.failure_scenario || finding.summary || 'Verified atomic fix from this iteration.'),
|
|
727
|
+
verifiedFix: String(finding.suggested_fix || finding.summary || 'Applied via iterate_fix.'),
|
|
728
|
+
findingSummary: String(finding.summary || ''),
|
|
729
|
+
severity: (finding.severity === 'critical' || finding.severity === 'high' || finding.severity === 'medium' || finding.severity === 'low') ? finding.severity : 'medium',
|
|
730
|
+
files: [rec.file],
|
|
731
|
+
tags: ['iterate', 'round-' + r],
|
|
732
|
+
})
|
|
733
|
+
}
|
|
734
|
+
if (expEntries.length > 0) {
|
|
735
|
+
await agent(
|
|
736
|
+
'Fixes from round ' + r + ' PASSED validation. For EACH entry below call ' +
|
|
737
|
+
'iterate_experience({operation:"add", entry:<that entry>}) (the tool dedupes on pattern+dimension — a repeat bumps its hit count). ' +
|
|
738
|
+
'Entries: ' + JSON.stringify(expEntries) + '. Return {added:<number of entries the tool reported as new>}.',
|
|
739
|
+
Object.assign({ label: 'experience:add:r' + r }, backend)
|
|
740
|
+
)
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
|
|
504
744
|
await agent(
|
|
505
745
|
'Call iterate_decision_log({operation:"append", type:"review_result", round:' + r +
|
|
506
746
|
', data:{atomic:' + atomic.length + ', architectural:' + remaining.length + ', fixedSoFar:' + fixedCount + '}})',
|
|
@@ -524,18 +764,93 @@ phase('report')
|
|
|
524
764
|
await agent(
|
|
525
765
|
'Call iterate_decision_log({operation:"append", type:"report", round:' + lastRound +
|
|
526
766
|
', data:{mode:"normal", fixed:' + fixedCount + ', architectural:' + architectural.length + '}})',
|
|
527
|
-
{ label: 'report:log' }
|
|
767
|
+
Object.assign({ label: 'report:log' }, backend)
|
|
528
768
|
)
|
|
529
769
|
const statusRes = await agent(
|
|
530
770
|
'Call iterate_status() and return the status JSON.',
|
|
531
|
-
{ label: 'status:final' }
|
|
771
|
+
Object.assign({ label: 'status:final' }, backend)
|
|
532
772
|
)
|
|
533
773
|
const status = (statusRes && statusRes.ok) ? statusRes : null
|
|
534
|
-
|
|
774
|
+
// F8 (quality gate): persist the run's quality certificate so the command
|
|
775
|
+
// panel shows PASS/FAIL + per-dimension scores instead of an empty tab.
|
|
776
|
+
// Inputs are assembled defensively:
|
|
777
|
+
// - \`gateFindings\` holds only what is still OPEN on disk: architectural
|
|
778
|
+
// findings (never auto-fixed) plus round findings no successful fix closed
|
|
779
|
+
// (same round + file, paired in order). A finding that was fixed and stayed
|
|
780
|
+
// fixed must NOT fail the final gate.
|
|
781
|
+
// - \`gateSeries\` is the per-dimension NEW-finding series, pre-zeroed to the
|
|
782
|
+
// number of executed rounds so a round that found nothing in a dimension
|
|
783
|
+
// still advances its convergence reading.
|
|
784
|
+
// - \`gateValidation\` maps a null exitCode (command never produced one) to 1 —
|
|
785
|
+
// fail CLOSED, never as a pass.
|
|
786
|
+
const gateAll = []
|
|
787
|
+
for (let si = 0; si < rounds.length; si++) {
|
|
788
|
+
const roundNo = rounds[si] && typeof rounds[si].round === 'number' ? rounds[si].round : si + 1
|
|
789
|
+
const perFile = Object.create(null)
|
|
790
|
+
for (const f of (roundReports[si] || [])) {
|
|
791
|
+
if (!f || typeof f !== 'object') continue
|
|
792
|
+
const fk = (typeof f.file === 'string') ? f.file : ''
|
|
793
|
+
const idx = perFile[fk] || 0
|
|
794
|
+
perFile[fk] = idx + 1
|
|
795
|
+
gateAll.push({ f: f, key: roundNo + '#' + fk + '#' + idx })
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
const gateClosed = Object.create(null)
|
|
799
|
+
for (const rec of fixRecords) {
|
|
800
|
+
if (!rec.success) continue
|
|
801
|
+
const prefix = rec.round + '#' + rec.file + '#'
|
|
802
|
+
for (let i = 0; i < gateAll.length; i++) {
|
|
803
|
+
if (!gateClosed[gateAll[i].key] && gateAll[i].key.indexOf(prefix) === 0) { gateClosed[gateAll[i].key] = true; break }
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
const gateFindings = []
|
|
807
|
+
const gateSeen = Object.create(null)
|
|
808
|
+
const gatePush = (f) => {
|
|
809
|
+
if (!f || typeof f !== 'object') return
|
|
810
|
+
const key = String(f.file || '') + '|' + String(f.dimension || '') + '|' + String(f.summary || '')
|
|
811
|
+
if (gateSeen[key]) return
|
|
812
|
+
gateSeen[key] = true
|
|
813
|
+
gateFindings.push(f)
|
|
814
|
+
}
|
|
815
|
+
for (const a of architectural) gatePush(a)
|
|
816
|
+
for (const e of gateAll) if (!gateClosed[e.key]) gatePush(e.f)
|
|
817
|
+
const gateSeries = Object.create(null)
|
|
818
|
+
for (const dim of dims) gateSeries[dim] = new Array(rounds.length).fill(0)
|
|
819
|
+
for (let i = 0; i < rounds.length; i++) {
|
|
820
|
+
for (const f of (roundReports[i] || [])) {
|
|
821
|
+
if (f && typeof f === 'object') {
|
|
822
|
+
const s = gateSeries[String(f.dimension)]
|
|
823
|
+
if (Array.isArray(s) && i < s.length) s[i] += 1
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
const gateFixed = Object.create(null)
|
|
828
|
+
const gateFixedSeen = Object.create(null)
|
|
829
|
+
for (const e of gateAll) {
|
|
830
|
+
if (!gateClosed[e.key]) continue
|
|
831
|
+
const key = String(e.f.file || '') + '|' + String(e.f.dimension || '') + '|' + String(e.f.summary || '')
|
|
832
|
+
if (gateFixedSeen[key]) continue
|
|
833
|
+
gateFixedSeen[key] = true
|
|
834
|
+
const d = String(e.f.dimension || '')
|
|
835
|
+
if (d) gateFixed[d] = (gateFixed[d] || 0) + 1
|
|
836
|
+
}
|
|
837
|
+
const gateValidation = validationRecords.map(v => ({
|
|
838
|
+
command: v.command,
|
|
839
|
+
exitCode: (typeof v.exitCode === 'number' && isFinite(v.exitCode)) ? Math.floor(v.exitCode) : 1,
|
|
840
|
+
}))
|
|
841
|
+
await agent(
|
|
842
|
+
'Call iterate_quality_gate({operation:"compute", dimensions:' + JSON.stringify(dims) +
|
|
843
|
+
', findings:' + JSON.stringify(gateFindings) +
|
|
844
|
+
', findingsByRound:' + JSON.stringify(gateSeries) +
|
|
845
|
+
', fixedByDimension:' + JSON.stringify(gateFixed) +
|
|
846
|
+
', validationResults:' + JSON.stringify(gateValidation) + '}) and return {ok, snapshot, warnings}.',
|
|
847
|
+
Object.assign({ label: 'quality-gate:compute' }, backend)
|
|
848
|
+
)
|
|
849
|
+
if (!abortedByValidation && !schemaFailed && !validationUnavailable) {
|
|
535
850
|
// Iteration finished cleanly → clear the checkpoint so the next run starts fresh.
|
|
536
851
|
await agent(
|
|
537
852
|
'Call iterate_checkpoint({ operation: "clear" }) and return {ok, existed}.',
|
|
538
|
-
{ label: 'checkpoint:clear' }
|
|
853
|
+
Object.assign({ label: 'checkpoint:clear' }, backend)
|
|
539
854
|
)
|
|
540
855
|
}
|
|
541
856
|
// Persist the run's observatory transcript (threads, trend, fixes, checkpoint)
|
|
@@ -554,10 +869,16 @@ if (!abortedByValidation && !schemaFailed) {
|
|
|
554
869
|
? 'schema_invalid'
|
|
555
870
|
: abortedByValidation
|
|
556
871
|
? (configErrors.length > 0 ? 'aborted_by_config' : 'aborted_by_validation')
|
|
557
|
-
|
|
872
|
+
// Clean stop with ZERO recorded validations = an UNVERIFIED run (the
|
|
873
|
+
// explicit args.unverified opt-in from preflight). Never report it as a
|
|
874
|
+
// verified \`converged\`/\`max_rounds_reached\` — the suffix marks that no
|
|
875
|
+
// test ever ran (#2).
|
|
876
|
+
: (validationRecords.length === 0
|
|
877
|
+
? (converged ? 'converged_unverified' : 'max_rounds_unverified')
|
|
878
|
+
: (converged ? 'converged' : 'max_rounds_reached'))
|
|
558
879
|
await agent(
|
|
559
|
-
'Call iterate_transcript({operation:"capture", mode:"normal", goal:' + JSON.stringify(plan.goal) + ', maxRounds:' + maxRounds + ', roundsExecuted:' + lastRound + ', findingsByRound:' + JSON.stringify(rounds.map(rr => (rr.findings && rr.findings.length) ? rr.findings.length : 0)) + ', stoppedReason:"' + stopReason + '", fixes:' + JSON.stringify(fixRecords) + ', checkpoint:' + JSON.stringify(obsCheckpoint) + ', rounds:' + JSON.stringify(rounds.map(rr => ({ round: rr.round, findings: rr.findings, readFiles: rr.readFiles }))) + '}). Return {operation:"ok"}.',
|
|
560
|
-
{ label: 'transcript:capture' }
|
|
880
|
+
'Call iterate_transcript({operation:"capture", mode:"normal", goal:' + JSON.stringify(plan.goal) + ', maxRounds:' + maxRounds + ', roundsExecuted:' + lastRound + ', findingsByRound:' + JSON.stringify(rounds.map(rr => (rr.findings && rr.findings.length) ? rr.findings.length : 0)) + ', stoppedReason:"' + stopReason + '", fixes:' + JSON.stringify(fixRecords) + ', checkpoint:' + JSON.stringify(obsCheckpoint) + ', validations:' + JSON.stringify(validationRecords) + ', rounds:' + JSON.stringify(rounds.map(rr => ({ round: rr.round, findings: rr.findings, readFiles: rr.readFiles }))) + '}). Return {operation:"ok"}.',
|
|
881
|
+
Object.assign({ label: 'transcript:capture' }, backend)
|
|
561
882
|
)
|
|
562
883
|
return {
|
|
563
884
|
mode: 'normal',
|
|
@@ -567,9 +888,16 @@ return {
|
|
|
567
888
|
converged: converged,
|
|
568
889
|
abortedByValidation: abortedByValidation,
|
|
569
890
|
schemaFailed: schemaFailed,
|
|
891
|
+
validationUnavailable: validationUnavailable,
|
|
570
892
|
failedCommands: failedCommands,
|
|
571
893
|
configErrors: configErrors,
|
|
572
894
|
stoppedReason: stopReason,
|
|
895
|
+
// #2 close-out: the caller/UI can tell a verified run from one where no
|
|
896
|
+
// validation command ever executed, and which commands were in play.
|
|
897
|
+
zeroValidation: validationRecords.length === 0,
|
|
898
|
+
unverified: unverified,
|
|
899
|
+
validationCommands: validationCmds,
|
|
900
|
+
validations: validationRecords,
|
|
573
901
|
findingsFixed: fixedCount,
|
|
574
902
|
remainingArchitecturalCount: architectural.length,
|
|
575
903
|
remainingArchitectural: architectural,
|
|
@@ -585,16 +913,18 @@ return {
|
|
|
585
913
|
\`\`\`
|
|
586
914
|
|
|
587
915
|
Key rules for normal mode:
|
|
916
|
+
- **Preflight before ANY work**: read \`validation.commands\` via \`iterate_config({})\` and abort with the actionable message when it is empty/missing (it points at \`iterate_config({operation:"write"...})\`) — unless the caller explicitly passed \`args.unverified === true\`. An unverified run is labelled everywhere (log line, \`unverified:true\`/\`zeroValidation:true\` in the return, \`*_unverified\` stoppedReason). "No commands configured" must NEVER read as a green, converged run.
|
|
588
917
|
- Fixers are the ONLY agents allowed to write files, and they must go through \`iterate_fix\` — never edit files directly. That is what gives every change a backup, a diff, and a rollback path. Reviewers read only. Architectural findings are reported, never auto-fixed.
|
|
589
918
|
- Aggregate the current round deterministically (\`report.findings\`) before fixing, so fixes act on deduped/filtered/sorted findings.
|
|
590
919
|
- **Schema validation & retry**: when \`reviewer.output_schema_validation\` is on (default), retry the round's reviewers up to 2 times (3 attempts total) when \`aggregate\` reports \`schemaValidation\` valid=false for it, then re-aggregate. Never forward schema-invalid findings into \`iterate_fix\`. If the output is still schema-invalid after the 3rd attempt — or every reviewer subagent failed outright (no usable output at all) — the round is INCONCLUSIVE: \`break\` the loop, log a \`round_failed\` entry, set \`schemaFailed = true\`, and report \`stoppedReason:"schema_invalid"\`/\`"no_usable_reviewer_output"\`. Never report an inconclusive round as a clean convergence, and keep the checkpoint so the run can be resumed after the reviewer configuration is fixed.
|
|
591
920
|
- Apply atomic fixes **per file**: one fixer agent handles all findings for a given file serially (so the same file is never edited concurrently); different files are fixed in parallel.
|
|
592
|
-
- **Resume**:
|
|
593
|
-
- **Validate after every round** of fixes; on ANY validation failure, roll back the round's fixes via \`iterate_rollback\` and stop (the checkpoint is left in place so the run can be resumed). EXCEPTION: \`iterate_validate\` returning \`allowed:false\` means the command is simply not in \`validation.commands\` — a config gap, not broken code. In that case abort WITHOUT rolling back the round's fixes and surface the missing command + file so the user can fix the trust list.
|
|
594
|
-
- **Checkpoint after every round**; clear it only when the iteration completes cleanly.
|
|
595
|
-
- Stop when a round produces nothing to fix (converged), maxReviewRounds is reached, validation aborts the run, or a round yields no usable reviewer output (\`stoppedReason:"schema_invalid"\`).
|
|
921
|
+
- **Resume**: read the checkpoint with \`operation:"resume"\` (the tool loads it, bumps \`resumeCount\` AND persists it back — that is what keeps a run interrupted again before its first save counted; never add +1 yourself on top of the tool's bump); fall back to a plain \`operation:"load"\` only when there is no checkpoint to resume. If a previous run left one, continue from \`checkpoint.round + 1\` (its \`fixedCount\` and deduped \`findings\` are carried forward).
|
|
922
|
+
- **Validate after every round** of fixes; on ANY validation failure, roll back the round's fixes via \`iterate_rollback\` and stop (the checkpoint is left in place so the run can be resumed). A rollback must also flip that round's fix records to \`success:false\` and decrement \`fixedCount\`, so \`findingsFixed\` and the final capture never count rolled-back work as applied. EXCEPTION: \`iterate_validate\` returning \`allowed:false\` means the command is simply not in \`validation.commands\` — a config gap, not broken code. In that case abort WITHOUT rolling back the round's fixes and surface the missing command + file so the user can fix the trust list. And if the validate SUBAGENT itself fails (resolves null / no \`results\`), validation did NOT run: stop with \`validationUnavailable = true\` (and \`abortedByValidation = true\`) BEFORE the checkpoint save — never collapse a failed validator into an empty, apparently-passing result. The SAME fail-closed rule applies to an EMPTY result set (\`results: []\`): zero commands executed means zero verification, so log \`reason:"zero_validation_results"\`, set \`validationUnavailable = true\`, record the defense event, and stop — an empty result is not a pass.
|
|
923
|
+
- **Checkpoint after every round**; clear it only when the iteration completes cleanly (never after a validation, schema, or unavailable-validator abort — the checkpoint must stay for a resume).
|
|
924
|
+
- Stop when a round produces nothing to fix (converged), maxReviewRounds is reached, validation aborts the run (including an unavailable validator: \`stoppedReason:"aborted_by_validation"\` with \`validationUnavailable:true\`), or a round yields no usable reviewer output (\`stoppedReason:"schema_invalid"\`). A run that ends cleanly having executed ZERO validation commands reports \`stoppedReason:"converged_unverified"\`/\`"max_rounds_unverified"\` — never a plain \`converged\`/\`"max_rounds_reached"\`.
|
|
596
925
|
- Every round, every rollback, and the final report go to the append-only decision log.
|
|
597
|
-
- Close with \`
|
|
926
|
+
- **Close-out for the command-center tabs (F8/F9/F10)**: after the report compute the quality certificate with \`iterate_quality_gate({operation:"compute", dimensions, findings, findingsByRound, fixedByDimension, validationResults})\` (label \`quality-gate:compute\`) — pass only findings still OPEN (architectural + findings no successful fix closed), the per-dimension series, and the recorded validations (a null exitCode counts as failed). During the loop: every validation-passed fix batch is banked via \`iterate_experience add\` (the tool dedupes pattern+dimension into hit counts), and every rollback / precondition failure (validator failed, zero results, allow-list gap, schema-invalid round) or falsified assumption (a fix \`iterate_fix\` refused) is recorded with \`recordDefense\`. Dry-run computes ONLY the quality gate — it applies no fixes (no F9) and triggers no defenses (no F10), because it writes nothing outside the transcript.
|
|
927
|
+
- Close with \`iterate_status\` metrics and surface the convergence indicators (fixed count, remaining architectural count, abort reason, verified vs UNVERIFIED) in the final summary.
|
|
598
928
|
|
|
599
929
|
### Finding schema (for reviewer agents)
|
|
600
930
|
{ "dimension": string, "file": string (relative path), "line": number (REQUIRED for line-targeted issues — the exact line you READ; use 0 for whole-file/module-level issues),
|