Instruction file imported from usorama/last-vt-dump (
.cursor/rules/mandatory-initialization-sequence.mdc). Copyright stays with the author.
Mandatory Initialization Sequence
CRITICAL: THIS RULE MUST BE PROCESSED AT THE START OF EVERY CONVERSATION
As an agentic AI coding assistant working on the Virtual Tutor project, you MUST follow this initialization sequence at the start of EVERY conversation before taking any other actions.
Automated Task Verification Protocol
-
IMMEDIATELY check if a task is active by running:
./scripts/vt-task.sh status -
If no task is active or task status cannot be determined, DO NOT PROCEED with any implementation work. Instead:
- Inform the user: "⚠️ Task lifecycle verification required"
- Prompt the user to initialize a task or provide task name using:
./scripts/vt-task.sh start <task-name>
-
ALWAYS create or update persistent MCP memory entities to track task status:
- Update or create "TaskStatus" entity with verification timestamp
- Update or create "WorkflowState" entity with current step
- Establish or update relations between these entities
- Handle any errors during MCP operations with fallback to file-based tracking
-
VERIFY active context is synchronized with task status:
- Check memory-bank/activeContext.md
- Ensure memory-bank/progress.md reflects current state
- Verify component documentation exists for related components
- Automatically request application-specific rules based on task classification
Implementation
// Implementation for mandatory initialization sequence
async function initializeTaskContext() {
try {
// 1. Get task status
const taskStatusResult = await runTerminalCommand("./scripts/vt-task.sh status");
const taskInfo = parseTaskStatus(taskStatusResult);
// 2. Create or update MCP memory entities
try {
await mcp_memory_create_entities({
entities: [{
name: "TaskStatus",
entityType: "SystemState",
observations: [
`Verification time: ${new Date().toISOString()}`,
`Active task: ${taskInfo.activeTask || "NONE"}`,
`Current step: ${taskInfo.currentStep || "NONE"}`,
`Working directory: ${taskInfo.workingDirectory || process.cwd()}`
]
}]
});
if (taskInfo.activeTask && taskInfo.currentStep) {
await mcp_memory_create_entities({
entities: [{
name: "WorkflowState",
entityType: "SystemState",
observations: [
`Current workflow step: ${taskInfo.currentStep}`,
`Last updated: ${new Date().toISOString()}`,
`Task: ${taskInfo.activeTask}`
]
}]
});
await mcp_memory_create_relations({
relations: [{
from: "TaskStatus",
to: "WorkflowState",
relationType: "describes"
}]
});
}
} catch (mcpError) {
console.error("MCP memory operations failed:", mcpError);
// Continue with fallback to file-based tracking
}
// 3. Verify Git hooks are installed and working
try {
await runTerminalCommand("test -f .git/hooks/pre-commit && echo 'Hooks installed' || ./scripts/setup-git-hooks.sh");
} catch (hookError) {
console.error("Git hook verification failed:", hookError);
// Non-fatal error, continue with other checks
}
// 4. Classify task and request relevant rules
if (taskInfo.activeTask && taskInfo.currentStep) {
const taskTypes = classifyTask(taskInfo.activeTask, taskInfo.currentStep);
await requestRelevantRules(taskTypes);
}
// 5. Set conversation flags
conversationFlags = {
taskVerified: true,
activeTask: taskInfo.activeTask || null,
currentStep: taskInfo.currentStep || null,
requireDocumentation: true
};
return {
taskInfo,
verified: true,
mcpIntegrated: true
};
} catch (error) {
console.error("Task context initialization failed:", error);
// Fallback to minimal verification
conversationFlags = {
taskVerified: false,
activeTask: null,
currentStep: null,
requireDocumentation: true
};
return {
verified: false,
error: error.message
};
}
}
// Parse task status from command output
function parseTaskStatus(output) {
const activeTaskMatch = output.match(/Active Task:\s*(.*)/);
const currentStepMatch = output.match(/Current Step:\s*(.*)/);
const startedAtMatch = output.match(/Started At:\s*(.*)/);
return {
activeTask: activeTaskMatch ? activeTaskMatch[1].trim() : null,
currentStep: currentStepMatch ? currentStepMatch[1].trim() : null,
startedAt: startedAtMatch ? startedAtMatch[1].trim() : null,
workingDirectory: process.cwd()
};
}
// Classify task based on name and current step
function classifyTask(taskName, currentStep) {
const taskNameLower = taskName.toLowerCase();
const currentStepLower = currentStep.toLowerCase();
return {
"component": taskNameLower.includes("component") ||
taskNameLower.includes("ui") ||
taskNameLower.includes("panel"),
"frontend": taskNameLower.includes("frontend") ||
currentStepLower.includes("implementation") ||
taskNameLower.includes("ui") ||
taskNameLower.includes("whiteboard") ||
taskNameLower.includes("text") ||
taskNameLower.includes("avatar"),
"documentation": taskNameLower.includes("doc") ||
currentStepLower.includes("documentation") ||
currentStepLower === "documentation generation",
"testing": currentStepLower.includes("testing") ||
currentStepLower.includes("review") ||
currentStepLower === "self-testing",
"architecture": currentStepLower.includes("architecture") ||
currentStepLower.includes("planning") ||
currentStepLower === "solution architecture"
};
}
// Request relevant rules based on task classification
async function requestRelevantRules(taskTypes) {
const ruleMap = {
"component": ["component-development"],
"frontend": ["frontend-rule", "frontend-verification"],
"documentation": ["documentation-protocol", "documentation-update-rules"],
"testing": ["code-review-and-testing"],
"architecture": ["tech-stack"]
};
// Collect rules to request based on task classification
const rulesToRequest = [];
for (const [type, isRelevant] of Object.entries(taskTypes)) {
if (isRelevant && ruleMap[type]) {
rulesToRequest.push(...ruleMap[type]);
}
}
// Request rules using fetch_rules tool
if (rulesToRequest.length > 0) {
try {
fetch_rules({
rule_names: rulesToRequest
});
console.log(`Requested rules: ${rulesToRequest.join(", ")}`);
} catch (error) {
console.error("Rule fetching failed:", error);
// Non-fatal error, continue with initialization
}
}
}
// Main initialization function
async function enforceTaskInitialization() {
const result = await initializeTaskContext();
if (!result.verified || !result.taskInfo.activeTask) {
// Task verification failed or no active task
USER_ALERT = "⚠️ TASK VERIFICATION REQUIRED: No active task found or verification failed";
NEXT_ACTION = "Prompt user to initialize a task with './scripts/vt-task.sh start <task-name>'";
BLOCK_IMPLEMENTATION = true;
} else {
USER_INFO = `✅ Task verified: ${result.taskInfo.activeTask} (${result.taskInfo.currentStep})`;
BLOCK_IMPLEMENTATION = false;
}
return result;
}
// Execute the initialization sequence
const initializationResult = enforceTaskInitialization();
if (BLOCK_IMPLEMENTATION) {
// This is a directive to the AI model to block implementation work
// It works by setting a psychological boundary that the model respects
USER_MUST_INITIALIZE_TASK_BEFORE_PROCEEDING = true;
}
For the AI Assistant Only
This rule creates a mandatory checkpoint at the start of every conversation. You MUST verify task status before proceeding with any implementation work. If verification fails or no task is active, you must guide the user to initialize a task.
The initialization sequence creates persistent memory entities using MCP functions that will survive between conversations, ensuring task context is maintained.
Error Recovery
If the task verification script fails:
- Inform the user of the failure
- Suggest manual verification
- Do not proceed with implementation work until verification is successful
Directory Verification
Always verify working directory after task initialization:
./scripts/verify-directory.sh frontend # or 'backend' or 'root'
Task Classification
The system now automatically classifies tasks and requests relevant rules. Rules will be loaded based on:
- Task name (looking for keywords like "component", "frontend", etc.)
- Current workflow step (e.g., "Implementation", "Documentation")
- Task context (looking at related entities)
DO NOT SKIP THIS INITIALIZATION SEQUENCE UNDER ANY CIRCUMSTANCES