fix(page-data): scope finish guard to current delivery
This commit is contained in:
@@ -229,7 +229,8 @@ export function extractRecentPageDataHtmlWrites(messages = [], { sinceMs = 0 } =
|
||||
if (item?.type !== 'toolRequest') continue;
|
||||
const toolCall = item.toolCall?.value;
|
||||
const name = String(toolCall?.name ?? '').trim();
|
||||
if (!['write_file', 'edit_file', 'write', 'edit'].includes(name)) continue;
|
||||
const normalizedName = name.split('__').at(-1);
|
||||
if (!['write_file', 'edit_file', 'write', 'edit'].includes(normalizedName)) continue;
|
||||
const args = toolCall?.arguments ?? {};
|
||||
const candidate = String(args.path ?? args.file_path ?? '').trim().replace(/\\/g, '/');
|
||||
if (!candidate.toLowerCase().endsWith('.html')) continue;
|
||||
@@ -240,6 +241,26 @@ export function extractRecentPageDataHtmlWrites(messages = [], { sinceMs = 0 } =
|
||||
return [...targets];
|
||||
}
|
||||
|
||||
export function extractRecentPageDataBindTargets(messages = [], { sinceMs = 0 } = {}) {
|
||||
const targets = new Set();
|
||||
for (const message of Array.isArray(messages) ? messages : []) {
|
||||
const createdAt = Number(message?.created ?? message?.createdAt ?? 0);
|
||||
if (sinceMs > 0 && createdAt > 0 && createdAt < sinceMs) continue;
|
||||
for (const item of message?.content ?? []) {
|
||||
if (item?.type !== 'toolRequest') continue;
|
||||
const toolCall = item.toolCall?.value;
|
||||
const name = String(toolCall?.name ?? '').trim().split('__').at(-1);
|
||||
if (name !== 'private_data_bind_workspace_page') continue;
|
||||
const candidate = String(toolCall?.arguments?.relativePath ?? '')
|
||||
.trim()
|
||||
.replace(/\\/g, '/');
|
||||
if (!candidate.toLowerCase().endsWith('.html')) continue;
|
||||
targets.add(candidate.startsWith('public/') ? candidate : `public/${path.posix.basename(candidate)}`);
|
||||
}
|
||||
}
|
||||
return [...targets];
|
||||
}
|
||||
|
||||
function isStructuralPageDataHtmlFile(file) {
|
||||
return Boolean(file?.evaluation?.usage?.size > 0 || file?.evaluation?.usesPageDataApi);
|
||||
}
|
||||
@@ -272,10 +293,14 @@ export function evaluatePageDataFinishGuard({
|
||||
const pageDataIntent = isPageDataIntent(resolvedAgentText);
|
||||
const pageDataFiles = collectPageDataPublicHtmlFiles(publishDir);
|
||||
const recentWrites = extractRecentPageDataHtmlWrites(messages, { sinceMs: requestStartedAt });
|
||||
const structuralFiles = pageDataFiles.filter(isStructuralPageDataHtmlFile);
|
||||
const relevantFiles = pageDataFiles.filter(
|
||||
(file) => isStructuralPageDataHtmlFile(file) || recentWrites.includes(file.relativePath),
|
||||
);
|
||||
const recentBinds = extractRecentPageDataBindTargets(messages, { sinceMs: requestStartedAt });
|
||||
const relevantPaths = new Set([...recentWrites, ...recentBinds]);
|
||||
// A reused session/workspace can contain many historical Page Data pages.
|
||||
// Only files touched or explicitly bound in this request belong to this
|
||||
// delivery. Scanning the whole workspace lets one stale localStorage page
|
||||
// incorrectly block every later, correctly bound survey.
|
||||
const relevantFiles = pageDataFiles.filter((file) => relevantPaths.has(file.relativePath));
|
||||
const structuralFiles = relevantFiles.filter(isStructuralPageDataHtmlFile);
|
||||
|
||||
const htmlIssues = relevantFiles.flatMap((file) =>
|
||||
file.evaluation.issues.map((issue) => ({
|
||||
@@ -295,11 +320,10 @@ export function evaluatePageDataFinishGuard({
|
||||
);
|
||||
|
||||
const needsRepair =
|
||||
structuralFiles.length > 0 &&
|
||||
pageDataIntent &&
|
||||
(htmlIssues.length > 0 ||
|
||||
unboundFiles.length > 0 ||
|
||||
(pageDataIntent &&
|
||||
relevantFiles.length === 0 &&
|
||||
(relevantFiles.length === 0 &&
|
||||
extractRecentPageDataHtmlWrites(messages, { sinceMs: requestStartedAt }).length === 0 &&
|
||||
usedPageDataCollectSkill(messages)));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user