feat: add page_data_dev code-run path and adm policy design docs

Introduce Page Data dev repair intent routing, page_data_dev taskType
autodetect, and help-code02 memindadm runtime policy specification.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
john
2026-07-23 21:31:09 +08:00
parent 898f6fff44
commit 13f5c740a1
9 changed files with 514 additions and 14 deletions
+58 -6
View File
@@ -28,6 +28,11 @@ export const agentCodeRunsEnabled = envFlag(import.meta.env.VITE_AGENT_CODE_RUNS
export const agentCodeRunsAutodetectEnabled = envFlag(
import.meta.env.VITE_AGENT_CODE_RUNS_AUTODETECT,
);
export const agentPageDataDevAutodetectEnabled = envFlag(
import.meta.env.VITE_AGENT_PAGE_DATA_DEV_AUTODETECT,
);
export const PAGE_DATA_DEV_TASK_TYPE = 'page_data_dev';
function parseUserIdSet(value: unknown): Set<string> {
return new Set(
@@ -46,6 +51,27 @@ export function agentCodeRunsEnabledForUser(userId?: string | null): boolean {
return Boolean(userId && agentCodeRunUserIds.has(userId));
}
const PAGE_DATA_DEV_TASK_PATTERNS = [
/columns_not_allowed/i,
/\bpage[\s-]?data[\s-]?dev\b/i,
/(?:insert||).{0,16}(?:|403||error)/iu,
/(?:|||debug|fix).{0,24}(?:|page[\s-]?data|||admin||policy||bind)/iu,
/(?:|page[\s-]?data||).{0,24}(?:bug||||)/iu,
/(?:|verify).{0,16}(?:||)/iu,
/(?:repair|).{0,16}(?:bind||policy|)/iu,
];
export function isPageDataDevTaskText(text: string): boolean {
const normalized = String(text ?? '').trim();
if (!normalized) return false;
return PAGE_DATA_DEV_TASK_PATTERNS.some((pattern) => pattern.test(normalized));
}
export function resolvePageDataDevTaskType(text: string): string | null {
if (!agentPageDataDevAutodetectEnabled) return null;
return isPageDataDevTaskText(text) ? PAGE_DATA_DEV_TASK_TYPE : null;
}
const CODE_TASK_PATTERNS = [
/\b(repo|repository|branch|commit|pull request|pr|diff|patch)\b/i,
/\b(aider|openhands|codex|codebase|workspace)\b/i,
@@ -185,6 +211,22 @@ export function buildAgentRunTaskValidation({
);
}
if (taskType === PAGE_DATA_DEV_TASK_TYPE) {
const taskReceiptPath = `.memind/agent-runs/${safeRequestId}-page-data-dev.json`;
expectedFiles.push({ path: taskReceiptPath, contains: PAGE_DATA_DEV_TASK_TYPE });
instructions.push(
'',
'[Memind page-data-dev validation]',
`Before finishing this Page Data dev repair task, create or update ${taskReceiptPath}.`,
'The file must be valid JSON and include:',
`- requestId: ${requestId}`,
`- taskType: ${PAGE_DATA_DEV_TASK_TYPE}`,
'- a brief summary of HTML/policy fixes or why no file change was needed.',
'Only modify public/*.html and .mindspace/page-data-policies/*.json unless explicitly told otherwise.',
'Do not recreate datasets or call private_data_execute unless the user pasted schema errors.',
);
}
return {
validation: expectedFiles.length ? { expectedFiles } : null,
instruction: instructions.join('\n'),
@@ -222,6 +264,7 @@ export function resolveAgentRunOptions(
taskType = 'code_task',
forceCode = false,
allowAutodetect = agentCodeRunsAutodetectEnabled,
allowPageDataDevAutodetect = agentPageDataDevAutodetectEnabled,
userId = null,
requestId = null,
mindspaceContext = null,
@@ -230,6 +273,7 @@ export function resolveAgentRunOptions(
taskType?: string;
forceCode?: boolean;
allowAutodetect?: boolean;
allowPageDataDevAutodetect?: boolean;
userId?: string | null;
requestId?: string | null;
mindspaceContext?: MindSpaceChatContext | null;
@@ -237,29 +281,37 @@ export function resolveAgentRunOptions(
} = {},
): AgentRunCreateOptions {
const normalizedText = String(text ?? '').trim();
const pageDataDevTaskType =
allowPageDataDevAutodetect && resolvePageDataDevTaskType(normalizedText);
const effectiveTaskType = pageDataDevTaskType ?? taskType;
const shouldUseDeepReasoning =
forceCode || DEEP_REASONING_TASK_PATTERNS.some((pattern) => pattern.test(normalizedText));
forceCode ||
Boolean(pageDataDevTaskType) ||
DEEP_REASONING_TASK_PATTERNS.some((pattern) => pattern.test(normalizedText));
if (!agentCodeRunsEnabledForUser(userId)) {
return shouldUseDeepReasoning ? { forceDeepReasoning: true, taskType } : {};
return shouldUseDeepReasoning ? { forceDeepReasoning: true, taskType: effectiveTaskType } : {};
}
const shouldUseCode = forceCode || (allowAutodetect && CODE_TASK_PATTERNS.some((pattern) => pattern.test(normalizedText)));
const shouldUseCode =
forceCode ||
Boolean(pageDataDevTaskType) ||
(allowAutodetect && CODE_TASK_PATTERNS.some((pattern) => pattern.test(normalizedText)));
if (!shouldUseCode) {
return shouldUseDeepReasoning ? { forceDeepReasoning: true, taskType } : {};
return shouldUseDeepReasoning ? { forceDeepReasoning: true, taskType: effectiveTaskType } : {};
}
const normalizedRequestId = requestId ?? crypto.randomUUID();
const receipt = buildAgentRunValidationReceipt(normalizedRequestId);
const taskValidation = buildAgentRunTaskValidation({
requestId: normalizedRequestId,
taskType,
taskType: effectiveTaskType,
text: normalizedText,
mindspaceContext,
pageEdit,
});
return {
toolMode: 'code',
taskType,
taskType: effectiveTaskType,
forceDeepReasoning: true,
validation: mergeAgentRunValidationFiles(receipt.validation, taskValidation.validation),
validationInstruction: `${receipt.instruction}${taskValidation.instruction}`,