@mcoda/mswarm 0.1.135-codali.41 → 0.1.135-codali.47
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/vendor/codali/cli/TerminalCommand.js +2 -2
- package/dist/vendor/codali/cli/tui/TerminalPresentation.js +1 -1
- package/dist/vendor/codali/config/OrchestrationConfig.d.ts +1 -0
- package/dist/vendor/codali/config/OrchestrationConfig.d.ts.map +1 -1
- package/dist/vendor/codali/config/OrchestrationConfig.js +3 -1
- package/dist/vendor/codali/docdex/DocdexClient.d.ts +11 -0
- package/dist/vendor/codali/docdex/DocdexClient.d.ts.map +1 -1
- package/dist/vendor/codali/docdex/DocdexClient.js +55 -1
- package/dist/vendor/codali/eval/fixtures/ContractReviewProvider.d.ts +5 -0
- package/dist/vendor/codali/eval/fixtures/ContractReviewProvider.d.ts.map +1 -1
- package/dist/vendor/codali/eval/fixtures/ContractReviewProvider.js +63 -0
- package/dist/vendor/codali/eval/fixtures/MixedMediaRecoveryJourney.js +2 -2
- package/dist/vendor/codali/eval/fixtures/TerminalRecoveryJourney.js +2 -2
- package/dist/vendor/codali/permissions/PermissionGate.d.ts +7 -0
- package/dist/vendor/codali/permissions/PermissionGate.d.ts.map +1 -1
- package/dist/vendor/codali/permissions/PermissionGate.js +27 -1
- package/dist/vendor/codali/providers/ClaudeCliProvider.d.ts.map +1 -1
- package/dist/vendor/codali/providers/ClaudeCliProvider.js +1 -0
- package/dist/vendor/codali/providers/CodexCliProvider.d.ts.map +1 -1
- package/dist/vendor/codali/providers/CodexCliProvider.js +1 -0
- package/dist/vendor/codali/providers/ConfiguredProvider.d.ts +2 -0
- package/dist/vendor/codali/providers/ConfiguredProvider.d.ts.map +1 -1
- package/dist/vendor/codali/providers/ConfiguredProvider.js +29 -0
- package/dist/vendor/codali/providers/ModelServiceError.d.ts +16 -2
- package/dist/vendor/codali/providers/ModelServiceError.d.ts.map +1 -1
- package/dist/vendor/codali/providers/ModelServiceError.js +18 -1
- package/dist/vendor/codali/providers/OllamaRemoteProvider.d.ts.map +1 -1
- package/dist/vendor/codali/providers/OllamaRemoteProvider.js +1 -0
- package/dist/vendor/codali/providers/OpenAiCompatibleProvider.d.ts.map +1 -1
- package/dist/vendor/codali/providers/OpenAiCompatibleProvider.js +4 -0
- package/dist/vendor/codali/providers/ProviderTypes.d.ts +4 -0
- package/dist/vendor/codali/providers/ProviderTypes.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/AnswerEdits.d.ts +39 -0
- package/dist/vendor/codali/runtime/AnswerEdits.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/AnswerEdits.js +134 -0
- package/dist/vendor/codali/runtime/AnswerVerification.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/AnswerVerification.js +4 -2
- package/dist/vendor/codali/runtime/AuditGuards.d.ts +41 -0
- package/dist/vendor/codali/runtime/AuditGuards.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/AuditGuards.js +81 -0
- package/dist/vendor/codali/runtime/CompletionReport.d.ts +4 -2
- package/dist/vendor/codali/runtime/CompletionReport.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/CompletionReport.js +8 -3
- package/dist/vendor/codali/runtime/ContextCompression.d.ts +5 -0
- package/dist/vendor/codali/runtime/ContextCompression.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/ContextCompression.js +16 -4
- package/dist/vendor/codali/runtime/DeliveryDocs.d.ts +21 -0
- package/dist/vendor/codali/runtime/DeliveryDocs.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/DeliveryDocs.js +148 -0
- package/dist/vendor/codali/runtime/FigureCheck.d.ts +61 -2
- package/dist/vendor/codali/runtime/FigureCheck.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/FigureCheck.js +210 -14
- package/dist/vendor/codali/runtime/GatewayRequest.d.ts +13 -0
- package/dist/vendor/codali/runtime/GatewayRequest.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/GatewayRequest.js +54 -1
- package/dist/vendor/codali/runtime/InspectionConvergence.d.ts +4 -0
- package/dist/vendor/codali/runtime/InspectionConvergence.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/InspectionConvergence.js +24 -1
- package/dist/vendor/codali/runtime/InteractionContract.d.ts +15 -0
- package/dist/vendor/codali/runtime/InteractionContract.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/InteractionContract.js +33 -0
- package/dist/vendor/codali/runtime/InteractionRouter.d.ts +3 -3
- package/dist/vendor/codali/runtime/InteractionRouter.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/InteractionRouter.js +1 -1
- package/dist/vendor/codali/runtime/NumericProvenance.d.ts +102 -0
- package/dist/vendor/codali/runtime/NumericProvenance.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/NumericProvenance.js +411 -0
- package/dist/vendor/codali/runtime/OutageWait.d.ts +46 -5
- package/dist/vendor/codali/runtime/OutageWait.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/OutageWait.js +81 -8
- package/dist/vendor/codali/runtime/ResearchEvidence.d.ts +14 -0
- package/dist/vendor/codali/runtime/ResearchEvidence.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/ResearchEvidence.js +139 -3
- package/dist/vendor/codali/runtime/ReviewCoordinator.d.ts +22 -0
- package/dist/vendor/codali/runtime/ReviewCoordinator.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/ReviewCoordinator.js +203 -25
- package/dist/vendor/codali/runtime/ReviewSource.d.ts +5 -0
- package/dist/vendor/codali/runtime/ReviewSource.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/ReviewSource.js +6 -1
- package/dist/vendor/codali/runtime/SessionController.d.ts +85 -10
- package/dist/vendor/codali/runtime/SessionController.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/SessionController.js +996 -176
- package/dist/vendor/codali/runtime/StructuralEvidence.d.ts +10 -0
- package/dist/vendor/codali/runtime/StructuralEvidence.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/StructuralEvidence.js +10 -0
- package/dist/vendor/codali/runtime/TaskReview.d.ts +10 -0
- package/dist/vendor/codali/runtime/TaskReview.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/TaskReview.js +31 -3
- package/dist/vendor/codali/runtime/VerificationCommand.d.ts +8 -0
- package/dist/vendor/codali/runtime/VerificationCommand.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/VerificationCommand.js +114 -0
- package/dist/vendor/codali/runtime/WorkingStyle.d.ts +20 -0
- package/dist/vendor/codali/runtime/WorkingStyle.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/WorkingStyle.js +71 -0
- package/dist/vendor/codali/tools/ToolRegistry.d.ts.map +1 -1
- package/dist/vendor/codali/tools/ToolRegistry.js +30 -4
- package/dist/vendor/codali/tools/ToolTypes.d.ts +3 -0
- package/dist/vendor/codali/tools/ToolTypes.d.ts.map +1 -1
- package/dist/vendor/codali/tools/browser/BrowserTool.d.ts +23 -1
- package/dist/vendor/codali/tools/browser/BrowserTool.d.ts.map +1 -1
- package/dist/vendor/codali/tools/browser/BrowserTool.js +83 -4
- package/dist/vendor/codali/tools/browser/BrowserWorker.js +142 -2
- package/dist/vendor/codali/tools/browser/HttpFallback.d.ts +39 -0
- package/dist/vendor/codali/tools/browser/HttpFallback.d.ts.map +1 -0
- package/dist/vendor/codali/tools/browser/HttpFallback.js +240 -0
- package/dist/vendor/codali/tools/calculation/CalculatorTool.d.ts +16 -1
- package/dist/vendor/codali/tools/calculation/CalculatorTool.d.ts.map +1 -1
- package/dist/vendor/codali/tools/calculation/CalculatorTool.js +321 -26
- package/dist/vendor/codali/tools/deterministic/DeterministicTools.js +1 -1
- package/dist/vendor/codali/tools/deterministic/node-worker.cjs +10 -10
- package/dist/vendor/codali/tools/shell/AsyncProcess.d.ts +2 -0
- package/dist/vendor/codali/tools/shell/AsyncProcess.d.ts.map +1 -1
- package/dist/vendor/codali/tools/shell/AsyncProcess.js +38 -5
- package/dist/vendor/codali/tools/shell/IsolatedExecutor.d.ts +29 -1
- package/dist/vendor/codali/tools/shell/IsolatedExecutor.d.ts.map +1 -1
- package/dist/vendor/codali/tools/shell/IsolatedExecutor.js +179 -9
- package/dist/vendor/codali/tools/shell/ShellTool.d.ts +2 -0
- package/dist/vendor/codali/tools/shell/ShellTool.d.ts.map +1 -1
- package/dist/vendor/codali/tools/shell/ShellTool.js +33 -3
- package/dist/vendor/codali/tools/verification/CodeRunTool.d.ts +19 -0
- package/dist/vendor/codali/tools/verification/CodeRunTool.d.ts.map +1 -0
- package/dist/vendor/codali/tools/verification/CodeRunTool.js +104 -0
- package/dist/vendor/codali/tools/verification/JavaScriptVerificationTool.d.ts.map +1 -1
- package/dist/vendor/codali/tools/verification/JavaScriptVerificationTool.js +21 -10
- package/dist/vendor/codali/tools/verification/VitestTool.d.ts +27 -0
- package/dist/vendor/codali/tools/verification/VitestTool.d.ts.map +1 -1
- package/dist/vendor/codali/tools/verification/VitestTool.js +232 -18
- package/dist/vendor/config/deterministic/node-worker.mjs +15 -2
- package/dist/vendor/config/skills/code-implementation/SKILL.md +1 -1
- package/dist/vendor/config/skills/planning/SKILL.md +1 -1
- package/dist/vendor/config/skills/testing-and-verification/SKILL.md +5 -5
- package/dist/vendor/config/skills/ui-ux-design/SKILL.md +1 -1
- package/dist/vendor/config/skills/webapp-testing/SKILL.md +4 -0
- package/dist/vendor/config/skills/webapp-testing/journey-driver.mjs +186 -0
- package/package.json +3 -3
|
@@ -26,6 +26,16 @@ export function researchPacket(tool, input, output) {
|
|
|
26
26
|
catch { /* Docdex may return source-labelled text instead of JSON. */ }
|
|
27
27
|
return output.trim() ? { source: tool, passage: output.slice(0, 4000), tool, query } : undefined;
|
|
28
28
|
}
|
|
29
|
+
/** A page's identity across link spellings (scheme, www., trailing slash, fragment). */
|
|
30
|
+
const sourceKey = (value) => {
|
|
31
|
+
try {
|
|
32
|
+
const url = new URL(value);
|
|
33
|
+
return `${url.host.toLowerCase().replace(/^www\./u, "")}${url.pathname.replace(/\/+$/u, "")}${url.search}`;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return value.trim().toLowerCase();
|
|
37
|
+
}
|
|
38
|
+
};
|
|
29
39
|
const squash = (text) => text.toLowerCase().replace(/[‘’]/gu, "'").replace(/[“”]/gu, '"').replace(/[‐-―−]/gu, "-").replace(/\s+/gu, " ");
|
|
30
40
|
/** Exact quotes and specific figures/identifiers in a draft: the claims an
|
|
31
41
|
* audit must be able to check against the passage they came from. */
|
|
@@ -55,10 +65,50 @@ export function selectResearchEvidence(packets, request, draft, maxChars = 48000
|
|
|
55
65
|
const overlap = [...terms].filter(term => words.has(term)).length;
|
|
56
66
|
return { packet, index, score: overlap / Math.sqrt(Math.max(1, terms.size)) + (packet.query ? 1 : 0) };
|
|
57
67
|
}).sort((a, b) => b.score - a.score || a.index - b.index);
|
|
68
|
+
// The pages the draft cites come first: for each, its passages that share
|
|
69
|
+
// most with the lines citing it. In cycle 7 the audit was not shown the
|
|
70
|
+
// passage behind a cited claim with no figure in it ("a further three
|
|
71
|
+
// months") and rewrote the claim as unsupported.
|
|
72
|
+
const anchored = [];
|
|
73
|
+
let anchorChars = 0;
|
|
74
|
+
const citing = new Map();
|
|
75
|
+
for (const line of draft.split(/\n+/u)) {
|
|
76
|
+
for (const url of line.match(/https?:\/\/[^\s<>()\[\]"'`\\]+/gu) ?? []) {
|
|
77
|
+
const key = sourceKey(url.replace(/[.,;:!?*]+$/u, ""));
|
|
78
|
+
const words = citing.get(key) ?? new Set();
|
|
79
|
+
for (const word of line.toLowerCase().match(/[\p{L}\p{N}_]{4,}/gu) ?? [])
|
|
80
|
+
words.add(word);
|
|
81
|
+
citing.set(key, words);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (citing.size) {
|
|
85
|
+
const cited = ranked.map(value => {
|
|
86
|
+
const words = citing.get(sourceKey(value.packet.source));
|
|
87
|
+
if (!words)
|
|
88
|
+
return undefined;
|
|
89
|
+
const terms = new Set(value.packet.passage.toLowerCase().match(/[\p{L}\p{N}_]{4,}/gu) ?? []);
|
|
90
|
+
return { value, key: sourceKey(value.packet.source), overlap: [...words].filter(word => terms.has(word)).length };
|
|
91
|
+
}).filter(item => item !== undefined).sort((a, b) => b.overlap - a.overlap || a.value.index - b.value.index);
|
|
92
|
+
// Best passage of every cited page first, then further passages of them.
|
|
93
|
+
const firsts = new Set();
|
|
94
|
+
const order = [...cited.filter(item => !firsts.has(item.key) && firsts.add(item.key)), ...cited];
|
|
95
|
+
for (const { value } of order) {
|
|
96
|
+
if (anchored.includes(value))
|
|
97
|
+
continue;
|
|
98
|
+
const size = JSON.stringify(value.packet).length + 1;
|
|
99
|
+
if (anchorChars + size > maxChars * 0.35)
|
|
100
|
+
continue;
|
|
101
|
+
anchorChars += size;
|
|
102
|
+
anchored.push(value);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
58
105
|
// Greedy cover of the draft's anchors, within part of the budget.
|
|
59
|
-
const anchors = draftAnchors(draft), uncovered = new Set(anchors)
|
|
106
|
+
const anchors = draftAnchors(draft), uncovered = new Set(anchors);
|
|
60
107
|
const passages = new Map(ranked.map(value => [value.index, squash(value.packet.passage)]));
|
|
61
|
-
|
|
108
|
+
for (const value of anchored)
|
|
109
|
+
for (const anchor of [...uncovered])
|
|
110
|
+
if (passages.get(value.index).includes(anchor))
|
|
111
|
+
uncovered.delete(anchor);
|
|
62
112
|
while (uncovered.size) {
|
|
63
113
|
let best, bestHits = 0;
|
|
64
114
|
for (const value of ranked) {
|
|
@@ -74,7 +124,7 @@ export function selectResearchEvidence(packets, request, draft, maxChars = 48000
|
|
|
74
124
|
if (!best)
|
|
75
125
|
break;
|
|
76
126
|
const size = JSON.stringify(best.packet).length + 1;
|
|
77
|
-
if (anchorChars + size > maxChars * 0.
|
|
127
|
+
if (anchorChars + size > maxChars * 0.7)
|
|
78
128
|
break;
|
|
79
129
|
anchorChars += size;
|
|
80
130
|
anchored.push(best);
|
|
@@ -99,3 +149,89 @@ export function selectResearchEvidence(packets, request, draft, maxChars = 48000
|
|
|
99
149
|
}
|
|
100
150
|
return selected;
|
|
101
151
|
}
|
|
152
|
+
/** What an investigation found, as a report, for when its answer could not be
|
|
153
|
+
* written: the model service was down or the final request would have run past
|
|
154
|
+
* the time limit. In cycle 6 a 41-minute investigation delivered nothing
|
|
155
|
+
* because that request hit three gateway timeouts in its last three minutes.
|
|
156
|
+
* Built without a model, so it is ready at once. It says plainly that it is
|
|
157
|
+
* evidence and not an answer, and quotes at most 25 words from any one source:
|
|
158
|
+
* the sentence that shares most with the request, figures and dates first. */
|
|
159
|
+
export function evidenceReport(packets, request, reason, maxSources = 30) {
|
|
160
|
+
// A search result packet carries several pages as JSON (possibly cut short); read each as its own source.
|
|
161
|
+
const pages = packets.flatMap(packet => /^https?:/.test(packet.source) ? [{ source: packet.source, passage: packet.passage }]
|
|
162
|
+
: [...packet.passage.matchAll(/"url"\s*:\s*"(https?:[^"\s]{1,1000})"\s*,\s*"content"\s*:\s*"((?:[^"\\]|\\.){0,3000})/gu)]
|
|
163
|
+
.map(match => ({ source: match[1], passage: match[2].replace(/\\[nrt]/gu, " ").replace(/\\(["\\/])/gu, "$1") })))
|
|
164
|
+
.filter(page => page.passage.trim().length >= 40);
|
|
165
|
+
if (!pages.length)
|
|
166
|
+
return undefined;
|
|
167
|
+
const terms = new Set(request.toLowerCase().match(/[\p{L}\p{N}_]{4,}/gu) ?? []);
|
|
168
|
+
const best = new Map();
|
|
169
|
+
for (const packet of pages) {
|
|
170
|
+
for (const sentence of packet.passage.replace(/\s+/gu, " ").split(/(?<=[.!?])\s+|\s+[-•|]\s+/u)) {
|
|
171
|
+
const words = sentence.trim().split(" ").filter(Boolean);
|
|
172
|
+
if (words.length < 5)
|
|
173
|
+
continue;
|
|
174
|
+
const overlap = new Set(words.map(word => word.toLowerCase().replace(/[^\p{L}\p{N}_]/gu, "")).filter(word => terms.has(word))).size;
|
|
175
|
+
const score = overlap * 2 + Math.min(4, words.filter(word => /\d/.test(word)).length);
|
|
176
|
+
const current = best.get(packet.source);
|
|
177
|
+
if (!current || score > current.score)
|
|
178
|
+
best.set(packet.source, { score, excerpt: words.slice(0, 25).join(" ") + (words.length > 25 ? " …" : "") });
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const ranked = [...best.entries()].sort((a, b) => b[1].score - a[1].score).slice(0, maxSources);
|
|
182
|
+
if (!ranked.length)
|
|
183
|
+
return undefined;
|
|
184
|
+
return [`I could not finish writing the answer: ${reason}. What follows is the evidence gathered, not an answer: the pages that were read, each with the one short excerpt closest to the question. Nothing here has been checked against the question as a whole, and points it does not cover remain unanswered.`,
|
|
185
|
+
"", ...ranked.map(([source, { excerpt }], index) => `${index + 1}. ${source}\n "${excerpt}"`)].join("\n");
|
|
186
|
+
}
|
|
187
|
+
const OPEN_POINT = /\b(?:unverified|not (?:been )?(?:independently )?verified|unconfirmed|(?:could not|couldn't|can ?not|cannot|was unable to|were unable to|unable to|failed to|did not manage to) (?:be )?(?:independently )?(?:verif(?:y|ied)|confirm(?:ed)?|find|found|locate[d]?|access(?:ed)?|retrieved?|determined?|establish(?:ed)?|open(?:ed)?)|no (?:primary|official|direct|reliable|authoritative) (?:source|page|document|record|figure|confirmation)s? (?:was|were|has been|have been|could be) (?:found|located|retrieved|identified)|(?:was|were) not found (?:during|in) (?:this|the|my) (?:research|search|investigation|review)|remains? (?:unclear|unconfirmed|to be (?:confirmed|verified|determined))|to be (?:confirmed|determined|verified)|tbd)\b/iu;
|
|
188
|
+
/** A whole table cell that says the row's fact was not settled by the research. */
|
|
189
|
+
const GAP_CELL = /^(?:(?:still |yet )?not (?:yet )?(?:been )?(?:established|found|located|confirmed|verified|determined|identified|retrieved)(?: (?:yet|in (?:this|the) (?:research|search)|from (?:a |any )?(?:primary|official) sources?))?|unverified|unconfirmed|no (?:primary |official )?(?:source|data|figure|record)s? found|to be (?:confirmed|determined|verified)|tbd|\?+)[.!]?$/iu;
|
|
190
|
+
/** The row of a markdown table one of whose cells is a gap marker, as "cell — cell". */
|
|
191
|
+
function tableGapRow(block) {
|
|
192
|
+
const row = block.trim();
|
|
193
|
+
if (!row.startsWith("|") || /^\|[\s:|-]+\|?$/u.test(row))
|
|
194
|
+
return undefined;
|
|
195
|
+
const cells = row.replace(/^\||\|$/gu, "").split("|").map(cell => cell.replace(/\*\*|__|`/gu, "").replace(/\s+/gu, " ").trim());
|
|
196
|
+
if (cells.length < 2 || !cells.slice(1).some(cell => GAP_CELL.test(cell)))
|
|
197
|
+
return undefined;
|
|
198
|
+
return cells.filter(cell => cell && !/^[-–—/]+$/u.test(cell)).join(" — ").slice(0, 240);
|
|
199
|
+
}
|
|
200
|
+
/** The points a research draft itself leaves open: the sentences or list items
|
|
201
|
+
* in which it says something was not found, not verified or only alleged.
|
|
202
|
+
* A draft that says so with time left has not finished its research; in cycle
|
|
203
|
+
* 6 one called a core fact "alleged" and stopped with a quarter of its time
|
|
204
|
+
* unused. Decided from the draft's own words, not from the question. */
|
|
205
|
+
export function openResearchPoints(draft, limit = 8) {
|
|
206
|
+
const points = [], seen = new Set();
|
|
207
|
+
for (const block of draft.split(/\n+/u)) {
|
|
208
|
+
const line = block.replace(/^[\s>#*|-]+|[\s*|]+$/gu, "").replace(/\*\*/gu, "");
|
|
209
|
+
// A table of findings marks its gaps with a bare status cell ("Not
|
|
210
|
+
// established") rather than a sentence. In cycle 7 a draft with half its
|
|
211
|
+
// rows in that state was read as having no open points.
|
|
212
|
+
const gapRow = tableGapRow(block);
|
|
213
|
+
if (gapRow) {
|
|
214
|
+
const key = gapRow.toLowerCase().slice(0, 80);
|
|
215
|
+
if (!seen.has(key)) {
|
|
216
|
+
seen.add(key);
|
|
217
|
+
points.push(gapRow);
|
|
218
|
+
}
|
|
219
|
+
if (points.length >= limit)
|
|
220
|
+
return points;
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
if (line.length < 12 || !OPEN_POINT.test(line))
|
|
224
|
+
continue;
|
|
225
|
+
// Only the sentences that carry the admission, not the settled ones beside them.
|
|
226
|
+
for (const sentence of line.split(/(?<=[.!?])\s+(?=[\p{Lu}\d"“(])/u).filter(part => OPEN_POINT.test(part))) {
|
|
227
|
+
const point = sentence.replace(/\s+/gu, " ").trim().slice(0, 240), key = point.toLowerCase().slice(0, 80);
|
|
228
|
+
if (seen.has(key))
|
|
229
|
+
continue;
|
|
230
|
+
seen.add(key);
|
|
231
|
+
points.push(point);
|
|
232
|
+
if (points.length >= limit)
|
|
233
|
+
return points;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return points;
|
|
237
|
+
}
|
|
@@ -10,6 +10,17 @@ export interface TaskReviewAssessment {
|
|
|
10
10
|
workspaceSnapshotHash: string;
|
|
11
11
|
}
|
|
12
12
|
export declare function reviewWorkspaceHash(hashes: Readonly<Record<string, string>>): string;
|
|
13
|
+
/** Checks of one requirement area are reviewed together, and one call reviews
|
|
14
|
+
* at most this many. A single call over 52 checks passed a build that omitted
|
|
15
|
+
* two of them; smaller portions keep each clause in view. */
|
|
16
|
+
export declare const REVIEW_CHECKS_PER_CALL = 8;
|
|
17
|
+
export declare const MAX_REVIEW_BATCHES = 64;
|
|
18
|
+
/** Content words of a text: identifiers are split at camelCase and
|
|
19
|
+
* snake_case, words are stemmed to five letters, numbers of three or more
|
|
20
|
+
* digits (a status code, a port, a limit) are kept, common words dropped. */
|
|
21
|
+
export declare const contentWords: (text: string) => Set<string>;
|
|
22
|
+
/** Whether a cited quotation is about the check at all: it shares a content word with it. */
|
|
23
|
+
export declare const sharesContent: (quote: string, reference: string) => boolean;
|
|
13
24
|
/** Review one scope without loading every sibling's source into the prompt.
|
|
14
25
|
* Assessments are created only by the controller after separate successful
|
|
15
26
|
* reviews; the caller must fence the complete snapshot before accepting them. */
|
|
@@ -30,6 +41,17 @@ export declare function reviewTaskScope(options: {
|
|
|
30
41
|
summary: string;
|
|
31
42
|
assessments?: readonly TaskReviewAssessment[];
|
|
32
43
|
authoritativeInputs?: readonly ReviewContractSource[];
|
|
44
|
+
/** Statements from delivered documents; whole-goal review checks each one. */
|
|
45
|
+
deliveredClaims?: readonly {
|
|
46
|
+
path: string;
|
|
47
|
+
text: string;
|
|
48
|
+
}[];
|
|
49
|
+
/** At most this many review portions (calls before paging and repair); the
|
|
50
|
+
* caller lowers it as the deadline nears. Checks that do not fit are
|
|
51
|
+
* returned as unreviewed, highest priority reviewed first. */
|
|
52
|
+
maxPortions?: number;
|
|
53
|
+
/** Called once per review portion, so a caller can share one budget across reviews. */
|
|
54
|
+
onPortion?: () => void;
|
|
33
55
|
readSource: (file: string, maxChars: number) => Promise<{
|
|
34
56
|
content: string;
|
|
35
57
|
truncated: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReviewCoordinator.d.ts","sourceRoot":"","sources":["../../src/runtime/ReviewCoordinator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAmB,MAAM,+BAA+B,CAAC;AAC/E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAgD,KAAK,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC9G,OAAO,EAAuB,KAAK,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AACrF,OAAO,EAAiB,KAAK,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"ReviewCoordinator.d.ts","sourceRoot":"","sources":["../../src/runtime/ReviewCoordinator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAmB,MAAM,+BAA+B,CAAC;AAC/E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAgD,KAAK,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC9G,OAAO,EAAuB,KAAK,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AACrF,OAAO,EAAiB,KAAK,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAK9F,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,qBAAqB,EAAE,MAAM,CAAC;CAC/B;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,MAAM,CAGpF;AAaD;;6DAE6D;AAC7D,eAAO,MAAM,sBAAsB,IAAI,CAAC;AACxC,eAAO,MAAM,kBAAkB,KAAK,CAAC;AAMrC;;6EAE6E;AAC7E,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,KAAG,GAAG,CAAC,MAAM,CAEgE,CAAC;AACvH,6FAA6F;AAC7F,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,EAAE,WAAW,MAAM,KAAG,OAGhE,CAAC;AAEF;;iFAEiF;AACjF,wBAAsB,eAAe,CAAC,OAAO,EAAE;IAC7C,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC;IAC5C,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,QAAQ,EAAE,SAAS;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACnH,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,SAAS,oBAAoB,EAAE,CAAC;IAC9C,mBAAmB,CAAC,EAAE,SAAS,oBAAoB,EAAE,CAAC;IACtD,8EAA8E;IAC9E,eAAe,CAAC,EAAE,SAAS;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC5D;;kEAE8D;IAC9D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uFAAuF;IACvF,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IACjG,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC5E,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAC3C,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA8N5B"}
|
|
@@ -2,7 +2,9 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { prepareReviewContract, reviewContractSources } from "./ReviewContract.js";
|
|
3
3
|
import { reviewPromptContext } from "./TaskReviewContext.js";
|
|
4
4
|
import { runTaskReview } from "./TaskReview.js";
|
|
5
|
+
import { REVIEW_PAGE_CHARS } from "./ReviewSource.js";
|
|
5
6
|
import { validationOutputExcerpt } from "./ValidationOutput.js";
|
|
7
|
+
import { isDeliveryDocument } from "./DeliveryDocs.js";
|
|
6
8
|
export function reviewWorkspaceHash(hashes) {
|
|
7
9
|
return createHash("sha256").update(JSON.stringify(Object.fromEntries(Object.entries(hashes)
|
|
8
10
|
.sort(([a], [b]) => a.localeCompare(b))))).digest("hex");
|
|
@@ -14,7 +16,30 @@ const reviewInstructions = [
|
|
|
14
16
|
{ role: "system", content: "taskAssessments are controller-recorded successful reviews of the identified task criteria at this exact workspaceSnapshotHash during this verification. Their sourcePaths were reviewed in those task scopes and remain available for sourceRequests. Use these assessments for already-reviewed criteria in later scoped reviews as well as integration; inspect the source needed for this task's own behavior and cross-task interactions. For integration, check the complete original goal, global constraints, architecture, cross-task interactions and remaining deliverables using these fresh assessments plus the current evidence. Do not demand an already assessed module's entire source merely to repeat its scoped review; request the specific files needed to investigate an integration defect. An assessment never certifies a different criterion, snapshot or missing deliverable. Empty findings still require sufficient evidence for every obligation." },
|
|
15
17
|
{ role: "system", content: "contractChecklist.checks preserves every prepared check. Each check's quoteId refers to the exact sourceId and contractQuote in contractChecklist.quotes. Identical quotations from the same source are stored once; every expectedBehavior remains separate. Follow those references when comparing a check to its authoritative text." },
|
|
16
18
|
{ role: "system", content: "When checklistBatch is present, this is one bounded portion of the prepared checklist, with the complete original contract and current evidence retained. Scrutinize every check in this portion and its interactions with the original contract. Other prepared checks are reviewed separately against this same snapshot; the controller requires every portion to pass. Your verdict covers this portion, never acceptance of an unreviewed portion. Do not reject solely because other checklist portions are absent; reject any actual defect or insufficient evidence for the checks you are reviewing. The complete original requirements remain authoritative in every portion." },
|
|
19
|
+
{ role: "system", content: 'An approval must prove every check in contractChecklist.checks. Add "evidence" to a passing verdict: {"passed":true,"findings":[],"evidence":{"<check id>":[{"receipt":"<receipt id>","observed":"text copied exactly from that receipt output"} or {"path":"<sourceRoles path>","quote":"text copied exactly from that file"}]}}. The controller confirms each quotation against the receipt output or the current file and rejects the approval when a check has none that matches. A quotation must be about the check (share its words). For a check that a named file stays unchanged, cite {"unchanged":"<that path>"}; the controller confirms the work did not change it. A non-goal is met by absence and needs no citation; reject the approval if the work does it. For behaviour a user or client sees (a page, an API response, a refusal, a state after reload), cite receipt output that shows it; a passing test proves only what its output or its assertions show. A source quote proves what that code does: quote the lines that implement the check, not a comment, a plan or the requirement text. When requirements say an action is unavailable or blocked and explained, only a visible disabled control or notice that states the reason meets it; a missing control is a defect. A check you cannot prove from the evidence is a blocking finding, not an approval.' },
|
|
20
|
+
{ role: "system", content: "Checks whose sourceId starts with delivered: are statements from a document delivered with the work (a README or delivery notes). Pass such a check only when source or receipt evidence shows the statement is true of the current build; a different number, duration or limit, a feature that is absent, or a check that never ran is a blocking finding that names the document and the statement. The document cannot prove its own statements." },
|
|
17
21
|
];
|
|
22
|
+
/** Checks of one requirement area are reviewed together, and one call reviews
|
|
23
|
+
* at most this many. A single call over 52 checks passed a build that omitted
|
|
24
|
+
* two of them; smaller portions keep each clause in view. */
|
|
25
|
+
export const REVIEW_CHECKS_PER_CALL = 8;
|
|
26
|
+
export const MAX_REVIEW_BATCHES = 64;
|
|
27
|
+
const MIN_QUOTE_CHARS = 8;
|
|
28
|
+
const normalText = (text) => text.replace(/\s+/g, " ").trim();
|
|
29
|
+
const STOP_WORDS = new Set(("the and for with that this from must should shall will when each are not any all its into than then them they their "
|
|
30
|
+
+ "has have had was were been being can may also only does did done use used uses using via per such other more most some same "
|
|
31
|
+
+ "const let var function return export import async await true false null undefined new class def self this end").split(" "));
|
|
32
|
+
/** Content words of a text: identifiers are split at camelCase and
|
|
33
|
+
* snake_case, words are stemmed to five letters, numbers of three or more
|
|
34
|
+
* digits (a status code, a port, a limit) are kept, common words dropped. */
|
|
35
|
+
export const contentWords = (text) => new Set(text.replace(/([a-z])([A-Z0-9])|([0-9])([A-Za-z])/g, "$1$3 $2$4").toLowerCase()
|
|
36
|
+
.split(/[^a-z0-9]+/).filter(word => /^\d{3,}$/.test(word) || /^[a-z]{3,}$/.test(word) && !STOP_WORDS.has(word))
|
|
37
|
+
.map(word => /^\d/.test(word) ? word : (word.length > 4 ? word.replace(/(?:ing|ed|es|s)$/, "") : word).slice(0, 5)));
|
|
38
|
+
/** Whether a cited quotation is about the check at all: it shares a content word with it. */
|
|
39
|
+
export const sharesContent = (quote, reference) => {
|
|
40
|
+
const words = contentWords(reference);
|
|
41
|
+
return [...contentWords(quote)].some(word => words.has(word));
|
|
42
|
+
};
|
|
18
43
|
/** Review one scope without loading every sibling's source into the prompt.
|
|
19
44
|
* Assessments are created only by the controller after separate successful
|
|
20
45
|
* reviews; the caller must fence the complete snapshot before accepting them. */
|
|
@@ -31,7 +56,13 @@ export async function reviewTaskScope(options) {
|
|
|
31
56
|
return { passed: false, findings: contract.findings };
|
|
32
57
|
const quotes = {};
|
|
33
58
|
const quoteIds = new Map();
|
|
34
|
-
|
|
59
|
+
// Statements with numbers or settings come first when they must be sampled.
|
|
60
|
+
const delivered = (options.scope.reviewScope === "whole_goal" ? options.deliveredClaims ?? [] : [])
|
|
61
|
+
.map((claim, order) => ({ claim, order, weight: /\d/.test(claim.text) ? 0 : 1 }))
|
|
62
|
+
.sort((a, b) => a.weight - b.weight || a.order - b.order)
|
|
63
|
+
.map(({ claim }) => ({ sourceId: `delivered:${claim.path}`,
|
|
64
|
+
contractQuote: claim.text, expectedBehavior: "This statement in the delivered document is true of the current build." }));
|
|
65
|
+
const allChecks = [...contract.checks, ...delivered].map(({ sourceId, contractQuote, expectedBehavior }, index) => {
|
|
35
66
|
const key = JSON.stringify([sourceId, contractQuote]);
|
|
36
67
|
let quoteId = quoteIds.get(key);
|
|
37
68
|
if (quoteId === undefined) {
|
|
@@ -39,8 +70,9 @@ export async function reviewTaskScope(options) {
|
|
|
39
70
|
quoteIds.set(key, quoteId);
|
|
40
71
|
quotes[quoteId] = { sourceId, contractQuote };
|
|
41
72
|
}
|
|
42
|
-
return { quoteId, expectedBehavior };
|
|
73
|
+
return { id: `C${index + 1}`, quoteId, expectedBehavior };
|
|
43
74
|
});
|
|
75
|
+
let checks = allChecks;
|
|
44
76
|
const assessedPaths = new Set(assessments.flatMap(value => value.sourcePaths));
|
|
45
77
|
// A later report/integration review can inspect an already assessed module
|
|
46
78
|
// without attributing its edits or requirements to the current task.
|
|
@@ -69,34 +101,179 @@ export async function reviewTaskScope(options) {
|
|
|
69
101
|
// Bound generated aids independently of authoritative requirements. Every
|
|
70
102
|
// batch retains the full contract and requires its own successful verdict;
|
|
71
103
|
// a large checklist cannot crowd out all source or silently lose checks.
|
|
104
|
+
// Batches follow requirement areas (the checks' source) and hold at most
|
|
105
|
+
// REVIEW_CHECKS_PER_CALL checks.
|
|
72
106
|
const checklistLimit = options.maxInputChars - Math.min(16000, Math.floor(options.maxInputChars / 4));
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
107
|
+
const portionLimit = Math.max(1, Math.min(MAX_REVIEW_BATCHES, Math.floor(options.maxPortions ?? MAX_REVIEW_BATCHES)));
|
|
108
|
+
input.checklistBatch = allChecks.length > REVIEW_CHECKS_PER_CALL ? { index: MAX_REVIEW_BATCHES - 1, count: MAX_REVIEW_BATCHES, totalChecks: allChecks.length } : undefined;
|
|
109
|
+
const fits = (selected) => { input.contractChecklist = checklist(selected); return JSON.stringify(messages()).length <= checklistLimit; };
|
|
110
|
+
const plan = (selected, perCall) => {
|
|
111
|
+
const areas = new Map();
|
|
112
|
+
for (const check of selected) {
|
|
113
|
+
const area = quotes[check.quoteId].sourceId;
|
|
114
|
+
areas.set(area, [...areas.get(area) ?? [], check]);
|
|
115
|
+
}
|
|
116
|
+
const chunks = [...areas.values()].flatMap(area => Array.from({ length: Math.ceil(area.length / perCall) }, (_, i) => area.slice(i * perCall, (i + 1) * perCall)));
|
|
117
|
+
const planned = [];
|
|
78
118
|
let batch = [];
|
|
79
|
-
for (const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
119
|
+
for (const chunk of chunks) {
|
|
120
|
+
if (batch.length && (batch.length + chunk.length > perCall || !fits([...batch, ...chunk]))) {
|
|
121
|
+
planned.push(batch);
|
|
122
|
+
batch = [];
|
|
123
|
+
}
|
|
124
|
+
for (const check of chunk) {
|
|
125
|
+
if (batch.length && !fits([...batch, check])) {
|
|
126
|
+
planned.push(batch);
|
|
84
127
|
batch = [];
|
|
85
128
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
findings: ["Required review authority and one checklist item exceed the configured evidence budget. Split the task or select a larger compatible reviewer; acceptance is not established."] };
|
|
129
|
+
if (!batch.length && !fits([check]))
|
|
130
|
+
return "oversized";
|
|
131
|
+
batch.push(check);
|
|
90
132
|
}
|
|
91
|
-
batch.push(check);
|
|
92
133
|
}
|
|
93
134
|
if (batch.length)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
135
|
+
planned.push(batch);
|
|
136
|
+
return planned;
|
|
137
|
+
};
|
|
138
|
+
// Portions never grow past REVIEW_CHECKS_PER_CALL: one call over dozens of
|
|
139
|
+
// checks is the failure this review replaced. Over the portion budget, the
|
|
140
|
+
// highest-priority checks are reviewed and the rest are reported unreviewed
|
|
141
|
+
// (not rejected): requirements first, then inputs, constraints, delivered
|
|
142
|
+
// statements (those with numbers first) and non-goals.
|
|
143
|
+
const priority = (check) => {
|
|
144
|
+
const source = quotes[check.quoteId].sourceId;
|
|
145
|
+
return /^(?:requirement|goal)\b/.test(source) ? 0 : source.startsWith("input:") ? 1 : source.startsWith("constraint:") ? 2 : source.startsWith("delivered:") ? 3 : 4;
|
|
146
|
+
};
|
|
147
|
+
const ordered = allChecks.map((check, order) => ({ check, order })).sort((a, b) => priority(a.check) - priority(b.check) || a.order - b.order).map(({ check }) => check);
|
|
148
|
+
let batches = plan(checks, REVIEW_CHECKS_PER_CALL);
|
|
149
|
+
if (batches !== "oversized" && batches.length > portionLimit) {
|
|
150
|
+
let low = 0;
|
|
151
|
+
let high = ordered.length;
|
|
152
|
+
while (low < high) {
|
|
153
|
+
const middle = Math.ceil((low + high) / 2);
|
|
154
|
+
const candidate = plan(ordered.slice(0, middle), REVIEW_CHECKS_PER_CALL);
|
|
155
|
+
if (candidate !== "oversized" && candidate.length <= portionLimit)
|
|
156
|
+
low = middle;
|
|
157
|
+
else
|
|
158
|
+
high = middle - 1;
|
|
159
|
+
}
|
|
160
|
+
checks = ordered.slice(0, low);
|
|
161
|
+
batches = plan(checks, REVIEW_CHECKS_PER_CALL);
|
|
98
162
|
}
|
|
163
|
+
if (batches === "oversized")
|
|
164
|
+
return { passed: false,
|
|
165
|
+
findings: ["Required review authority and one checklist item exceed the configured evidence budget. Split the task or select a larger compatible reviewer; acceptance is not established."] };
|
|
166
|
+
const reviewedIds = new Set(checks.map(check => check.id));
|
|
167
|
+
const unreviewed = allChecks.filter(check => !reviewedIds.has(check.id))
|
|
168
|
+
.map(check => ({ id: check.id, sourceId: quotes[check.quoteId].sourceId, expectedBehavior: check.expectedBehavior }));
|
|
169
|
+
// Every cited quotation must exist in the receipt output or current file.
|
|
170
|
+
// A file too large to read whole is checked against the pages shown.
|
|
171
|
+
const shown = new Map();
|
|
172
|
+
const show = (file, content) => shown.set(file, [...shown.get(file) ?? [], normalText(content)]);
|
|
173
|
+
const readSourcePage = async (file, offset) => {
|
|
174
|
+
const page = await options.readSourcePage(file, offset);
|
|
175
|
+
if (!page.unavailable)
|
|
176
|
+
show(file, page.content);
|
|
177
|
+
return page;
|
|
178
|
+
};
|
|
179
|
+
const fileTexts = new Map();
|
|
180
|
+
const fileText = (file) => {
|
|
181
|
+
if (!fileTexts.has(file))
|
|
182
|
+
fileTexts.set(file, options.readSource(file, 128 * 1024)
|
|
183
|
+
.then(source => /^\[(?:missing|binary|large)/.test(source.content) ? undefined : source.truncated ? [] : [normalText(source.content)], () => undefined));
|
|
184
|
+
return fileTexts.get(file).then(texts => texts && [...texts, ...shown.get(file) ?? []]);
|
|
185
|
+
};
|
|
186
|
+
const inputPaths = new Set(authoritativeInputs.map(value => value.id.replace(/^input:/, "")));
|
|
187
|
+
const receiptsById = new Map(options.receipts.map(receipt => [receipt.id, receipt]));
|
|
188
|
+
const answerOnly = !options.scope.changedPaths.length;
|
|
189
|
+
const citationProblem = async (entry, check) => {
|
|
190
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
191
|
+
return "an evidence entry is not an object";
|
|
192
|
+
const { sourceId, contractQuote } = quotes[check.quoteId];
|
|
193
|
+
const statement = sourceId.startsWith("delivered:");
|
|
194
|
+
const cited = entry;
|
|
195
|
+
const quoted = (value) => typeof value === "string" && normalText(value).length >= MIN_QUOTE_CHARS ? normalText(value) : undefined;
|
|
196
|
+
// A quotation must be about the check, not any eight characters of any file.
|
|
197
|
+
const unrelated = (quote) => sharesContent(quote, `${contractQuote} ${check.expectedBehavior}`) ? undefined
|
|
198
|
+
: `"${quote.slice(0, 80)}" shares no words with this check; quote the lines that show it`;
|
|
199
|
+
if (typeof cited.receipt === "string") {
|
|
200
|
+
const receipt = receiptsById.get(cited.receipt);
|
|
201
|
+
if (!receipt)
|
|
202
|
+
return `receipt ${cited.receipt} is not one of the supplied receipts`;
|
|
203
|
+
const observed = quoted(cited.observed);
|
|
204
|
+
if (!observed)
|
|
205
|
+
return `quote at least ${MIN_QUOTE_CHARS} characters of receipt ${cited.receipt} output in observed`;
|
|
206
|
+
const output = normalText(receipt.output ?? "");
|
|
207
|
+
if (!output.includes(observed))
|
|
208
|
+
return `receipt ${cited.receipt} output does not contain "${observed.slice(0, 80)}"`;
|
|
209
|
+
// A command that reads a delivery document (cat README.md) is not evidence
|
|
210
|
+
// for the document's statements; app output that shows the same text is.
|
|
211
|
+
const readsDocument = (JSON.stringify(receipt.args ?? "").match(/[\w./-]+\.(?:md|markdown|mdx|rst)\b/gi) ?? []).some(file => isDeliveryDocument(file.replace(/^\.\//, "")));
|
|
212
|
+
if (statement && readsDocument && output.includes(normalText(contractQuote)))
|
|
213
|
+
return `receipt ${cited.receipt} prints the document's statement; it does not show the build doing it`;
|
|
214
|
+
return unrelated(observed);
|
|
215
|
+
}
|
|
216
|
+
if (typeof cited.path === "string") {
|
|
217
|
+
if (!reviewPaths.includes(cited.path))
|
|
218
|
+
return `${cited.path} is not a review source`;
|
|
219
|
+
if (inputPaths.has(cited.path))
|
|
220
|
+
return `${cited.path} states the requirements; it is not evidence of the build`;
|
|
221
|
+
if (statement && isDeliveryDocument(cited.path))
|
|
222
|
+
return `${cited.path} is a delivered document; a document cannot prove a document's statement`;
|
|
223
|
+
const texts = await fileText(cited.path);
|
|
224
|
+
if (texts === undefined)
|
|
225
|
+
return `${cited.path} is not available for a quotation check; cite a receipt`;
|
|
226
|
+
// A file shorter than the minimum quotation can be quoted whole.
|
|
227
|
+
const whole = typeof cited.quote === "string" && normalText(cited.quote) !== "" && texts.some(text => text === normalText(cited.quote));
|
|
228
|
+
const quote = whole ? normalText(cited.quote) : quoted(cited.quote);
|
|
229
|
+
if (!quote)
|
|
230
|
+
return `quote at least ${MIN_QUOTE_CHARS} characters of ${cited.path}`;
|
|
231
|
+
if (!texts.some(text => text.includes(quote)))
|
|
232
|
+
return `"${quote.slice(0, 80)}" does not appear in ${cited.path}`;
|
|
233
|
+
return whole ? undefined : unrelated(quote);
|
|
234
|
+
}
|
|
235
|
+
// "Preserve USER_NOTES.md": the controller knows whether the work changed it.
|
|
236
|
+
if (typeof cited.unchanged === "string") {
|
|
237
|
+
const file = cited.unchanged;
|
|
238
|
+
const named = [file, file.split("/").pop()].some(name => name.length >= 3 && `${contractQuote} ${check.expectedBehavior}`.includes(name));
|
|
239
|
+
if (!named)
|
|
240
|
+
return `${file} is not a file this check names`;
|
|
241
|
+
return options.scope.changedPaths.includes(file) || options.scope.otherTaskChangedPaths.includes(file) ? `${file} was changed by this work` : undefined;
|
|
242
|
+
}
|
|
243
|
+
if (answerOnly && typeof cited.summary === "string") {
|
|
244
|
+
const quote = quoted(cited.summary);
|
|
245
|
+
// The proposed answer is the deliverable itself; its words need not echo the request.
|
|
246
|
+
return quote && normalText(options.summary).includes(quote) ? undefined : "the quoted text does not appear in the proposed answer";
|
|
247
|
+
}
|
|
248
|
+
return 'cite {"receipt","observed"}, {"path","quote"} or {"unchanged"}';
|
|
249
|
+
};
|
|
250
|
+
const approve = (selected) => async (verdict) => {
|
|
251
|
+
const evidence = verdict.evidence && typeof verdict.evidence === "object" && !Array.isArray(verdict.evidence) ? verdict.evidence : {};
|
|
252
|
+
const problems = [];
|
|
253
|
+
for (const check of selected) {
|
|
254
|
+
// A non-goal ("add no payroll features") is met by absence: nothing to quote.
|
|
255
|
+
if (quotes[check.quoteId].sourceId.startsWith("nonGoal:"))
|
|
256
|
+
continue;
|
|
257
|
+
const value = evidence[check.id];
|
|
258
|
+
const entries = Array.isArray(value) ? value : value === undefined ? [] : [value];
|
|
259
|
+
const reasons = [];
|
|
260
|
+
for (const entry of entries) {
|
|
261
|
+
const reason = await citationProblem(entry, check);
|
|
262
|
+
if (!reason) {
|
|
263
|
+
reasons.length = 0;
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
reasons.push(reason);
|
|
267
|
+
}
|
|
268
|
+
if (!entries.length)
|
|
269
|
+
reasons.push("no evidence cited");
|
|
270
|
+
if (reasons.length)
|
|
271
|
+
problems.push(`Unproven ${check.id} (${quotes[check.quoteId].sourceId}: ${check.expectedBehavior.slice(0, 200)}): ${reasons.join("; ")}. Show it with a test or journey step whose output demonstrates it, or fix the implementation, then verify again.`);
|
|
272
|
+
}
|
|
273
|
+
return problems;
|
|
274
|
+
};
|
|
99
275
|
for (const [index, batch] of batches.entries()) {
|
|
276
|
+
options.onPortion?.();
|
|
100
277
|
options.signal?.throwIfAborted();
|
|
101
278
|
input.contractChecklist = checklist(batch);
|
|
102
279
|
input.checklistBatch = batches.length > 1 ? { index, count: batches.length, totalChecks: checks.length } : undefined;
|
|
@@ -109,12 +286,13 @@ export async function reviewTaskScope(options) {
|
|
|
109
286
|
for (const file of initialPaths) {
|
|
110
287
|
if (remaining <= 0)
|
|
111
288
|
break;
|
|
112
|
-
const evidence = await options.readSource(file, Math.min(
|
|
289
|
+
const evidence = await options.readSource(file, Math.min(REVIEW_PAGE_CHARS, Math.floor(remaining / 2)));
|
|
113
290
|
const addedChars = JSON.stringify({ [file]: evidence.content }).length + 32;
|
|
114
291
|
if (addedChars > remaining)
|
|
115
292
|
continue;
|
|
116
293
|
input.source[file] = evidence.content;
|
|
117
294
|
remaining -= addedChars;
|
|
295
|
+
show(file, evidence.content);
|
|
118
296
|
if (evidence.truncated)
|
|
119
297
|
input.sourceNextOffsets[file] = evidence.content.length;
|
|
120
298
|
else {
|
|
@@ -124,11 +302,11 @@ export async function reviewTaskScope(options) {
|
|
|
124
302
|
}
|
|
125
303
|
input.sourceTruncatedPaths = [...truncated];
|
|
126
304
|
const result = await runTaskReview({ provider: options.provider, allowedPaths: reviewPaths,
|
|
127
|
-
initialSourceOffsets: input.sourceNextOffsets, readSourcePage
|
|
305
|
+
initialSourceOffsets: input.sourceNextOffsets, readSourcePage,
|
|
128
306
|
maxInputChars: options.maxInputChars, maxOutputTokens: options.maxOutputTokens,
|
|
129
|
-
messages: messages(), signal: options.signal });
|
|
307
|
+
messages: messages(), signal: options.signal, approve: approve(batch) });
|
|
130
308
|
if (!result.passed)
|
|
131
309
|
return result;
|
|
132
310
|
}
|
|
133
|
-
return { passed: true, findings: [] };
|
|
311
|
+
return unreviewed.length ? { passed: true, findings: [], unreviewed } : { passed: true, findings: [] };
|
|
134
312
|
}
|
|
@@ -4,6 +4,11 @@ export declare const readReviewSource: (root: string, relative: string, expected
|
|
|
4
4
|
content: string;
|
|
5
5
|
truncated: boolean;
|
|
6
6
|
}>;
|
|
7
|
+
/** Characters of one source page. At 8,000 a reviewer needed six or seven
|
|
8
|
+
* requests (a model call each) to read one 50k-character file, and ran into
|
|
9
|
+
* its four-round limit before it could decide; the review prompt is still
|
|
10
|
+
* fitted to the model's context after pages are added. */
|
|
11
|
+
export declare const REVIEW_PAGE_CHARS = 24000;
|
|
7
12
|
/** Page offsets refer to redacted text, so repeated reads cannot reconstruct a secret. */
|
|
8
13
|
export declare function readReviewSourcePage(root: string, relative: string, expectedHash: string, offset: number): Promise<ReviewSourcePage>;
|
|
9
14
|
//# sourceMappingURL=ReviewSource.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReviewSource.d.ts","sourceRoot":"","sources":["../../src/runtime/ReviewSource.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,kFAAkF;AAClF,eAAO,MAAM,gBAAgB,GAAU,MAAM,MAAM,EAAE,UAAU,MAAM,EAAE,cAAc,MAAM,EAAE,UAAU,MAAM,KAAG,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAyB9J,CAAC;AAEF,0FAA0F;AAC1F,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAQ1I"}
|
|
1
|
+
{"version":3,"file":"ReviewSource.d.ts","sourceRoot":"","sources":["../../src/runtime/ReviewSource.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,kFAAkF;AAClF,eAAO,MAAM,gBAAgB,GAAU,MAAM,MAAM,EAAE,UAAU,MAAM,EAAE,cAAc,MAAM,EAAE,UAAU,MAAM,KAAG,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAyB9J,CAAC;AAEF;;;0DAG0D;AAC1D,eAAO,MAAM,iBAAiB,QAAS,CAAC;AAExC,0FAA0F;AAC1F,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAQ1I"}
|
|
@@ -39,6 +39,11 @@ export const readReviewSource = async (root, relative, expectedHash, maxChars) =
|
|
|
39
39
|
await handle.close();
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
|
+
/** Characters of one source page. At 8,000 a reviewer needed six or seven
|
|
43
|
+
* requests (a model call each) to read one 50k-character file, and ran into
|
|
44
|
+
* its four-round limit before it could decide; the review prompt is still
|
|
45
|
+
* fitted to the model's context after pages are added. */
|
|
46
|
+
export const REVIEW_PAGE_CHARS = 24000;
|
|
42
47
|
/** Page offsets refer to redacted text, so repeated reads cannot reconstruct a secret. */
|
|
43
48
|
export async function readReviewSourcePage(root, relative, expectedHash, offset) {
|
|
44
49
|
if (!Number.isSafeInteger(offset) || offset < 0)
|
|
@@ -48,7 +53,7 @@ export async function readReviewSourcePage(root, relative, expectedHash, offset)
|
|
|
48
53
|
return { path: relative, offset, content: source.content, truncated: true, unavailable: true };
|
|
49
54
|
if (offset > source.content.length)
|
|
50
55
|
throw new Error(`Review source offset exceeds the file length: ${relative}`);
|
|
51
|
-
const content = source.content.slice(offset, offset +
|
|
56
|
+
const content = source.content.slice(offset, offset + REVIEW_PAGE_CHARS);
|
|
52
57
|
const truncated = offset + content.length < source.content.length;
|
|
53
58
|
return { path: relative, offset, content, truncated, ...(truncated ? { nextOffset: offset + content.length } : {}) };
|
|
54
59
|
}
|