Forked from brdcastro/maestro
"use strict";
/**
* @file Workflow coordinator — lightweight phase tracking for tool usage.
*
* Inspired by Claude Code's coordinator pattern. Tracks what phase of work
* the model is in (understand → plan → implement → verify) and provides
* contextual guidance to encourage good practices like:
* - Reading before writing
* - Planning before implementing
* - Testing/verifying after implementing
*
* Phase transitions are inferred from tool usage patterns, not forced.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.inferPhase = inferPhase;
exports.classifyTool = classifyTool;
exports.getPhaseGuidance = getPhaseGuidance;
exports.getPhaseIndicator = getPhaseIndicator;
/** Tool names grouped by workflow phase. */
const UNDERSTAND_TOOLS = new Set([
"read_file", "list_directory", "find_files", "grep_files",
"get_project_context", "get_project_overview",
"spotlight_search", "get_active_app", "take_screenshot",
"git_status", "git_log", "git_diff",
"web_search", "fetch_web_content", "wikipedia_search",
"recall",
]);
const IMPLEMENT_TOOLS = new Set([
"save_file", "replace_text_in_file", "delete_path", "move_file", "copy_file",
"git_add", "git_commit",
"run_applescript", "run_jxa", "build_keynote",
]);
const VERIFY_TOOLS = new Set([
"run_test_command", "lint_file", "diff_files",
]);
const EXECUTE_TOOLS = new Set([
"run_javascript", "run_python", "execute_command",
"run_in_terminal", "run_background",
]);
/**
* Given the current phase and tool counts, determine the next phase.
*/
function inferPhase(counts) {
// If tests have been run, we're in verify
if (counts.tests > 0)
return "verify";
// If files have been written, we're implementing
if (counts.writes > 0)
return "implement";
// If code has been executed but no files written, still implementing (exploratory)
if (counts.executions > 0 && counts.reads >= 2)
return "implement";
// If we've read multiple files, we've understood enough to plan
if (counts.reads >= 3)
return "plan";
// Otherwise, still understanding
return "understand";
}
/**
* Classify which category a tool belongs to.
*/
function classifyTool(toolName) {
if (UNDERSTAND_TOOLS.has(toolName))
return "reads";
if (IMPLEMENT_TOOLS.has(toolName))
return "writes";
if (VERIFY_TOOLS.has(toolName))
return "tests";
if (EXECUTE_TOOLS.has(toolName))
return "executions";
return null;
}
/**
* Get phase-appropriate guidance for the model.
* Returns null if no guidance is needed for this phase transition.
*/
function getPhaseGuidance(prevPhase, currentPhase, counts) {
// Only provide guidance on phase transitions or important milestones
if (prevPhase === currentPhase) {
// Within-phase guidance for long phases
if (currentPhase === "implement" && counts.writes >= 5 && counts.tests === 0) {
return "📋 You've made several file changes. Consider running tests or verifying your changes before continuing.";
}
return null;
}
// Phase transition guidance
switch (currentPhase) {
case "plan":
return "📐 You've explored the codebase. Before making changes, briefly plan your approach — what files need to change and in what order.";
case "implement":
if (counts.reads < 2) {
return "⚠️ You're making changes without reading much of the codebase first. Consider reading the relevant files before editing to avoid mistakes.";
}
return null; // Normal transition, no guidance needed
case "verify":
return null; // Good practice, no guidance needed
default:
return null;
}
}
/**
* Get a compact phase indicator string for the system prompt.
*/
function getPhaseIndicator(phase, counts) {
const phases = {
understand: "🔍 Phase: Understand",
plan: "📐 Phase: Plan",
implement: "🔨 Phase: Implement",
verify: "✅ Phase: Verify",
};
return `${phases[phase]} | reads: ${counts.reads}, writes: ${counts.writes}, tests: ${counts.tests}`;
}
//# sourceMappingURL=workflowCoordinator.js.map