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:
@@ -63,7 +63,7 @@ import {
|
||||
CHAT_IMAGE_UPLOAD_MAX_INPUT_BYTES,
|
||||
} from '../utils/imageUpload';
|
||||
import { buildAbsoluteAssetDownloadUrl } from '../utils/mindspaceCards';
|
||||
import { resolveAgentRunOptions } from '../utils/agentRunMode';
|
||||
import { resolveAgentRunOptions, resolvePageDataDevTaskType } from '../utils/agentRunMode';
|
||||
import {
|
||||
buildUserMessage,
|
||||
normalizeConversationMessages,
|
||||
@@ -1472,8 +1472,9 @@ export function useTKMindChat(
|
||||
}
|
||||
|
||||
try {
|
||||
const pageDataDevTaskType = resolvePageDataDevTaskType(trimmed);
|
||||
const runOptions = resolveAgentRunOptions(trimmed, {
|
||||
taskType: 'h5_chat_code_task',
|
||||
taskType: pageDataDevTaskType ?? 'h5_chat_code_task',
|
||||
userId: userRef.current?.id ?? null,
|
||||
requestId,
|
||||
mindspaceContext: options?.mindspaceContext ?? null,
|
||||
|
||||
@@ -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}`,
|
||||
|
||||
Reference in New Issue
Block a user