-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.ts
More file actions
144 lines (129 loc) · 5.45 KB
/
index.ts
File metadata and controls
144 lines (129 loc) · 5.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env node
// =============================================================================
// Preflight-Dev MCP Server — v3.0
// =============================================================================
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { isToolEnabled, getProfile } from "./profiles.js";
import { getConfig, hasPreflightConfig } from "./lib/config.js";
import { existsSync } from "fs";
// Main entry point
import { registerPreflightCheck } from "./tools/preflight-check.js";
// Category 1: Plans
import { registerScopeWork } from "./tools/scope-work.js";
// Category 2: Clarification
import { registerClarifyIntent } from "./tools/clarify-intent.js";
// Category 3: Delegation
import { registerEnrichAgentTask } from "./tools/enrich-agent-task.js";
// Category 4: Follow-up Specificity
import { registerSharpenFollowup } from "./tools/sharpen-followup.js";
// Category 5: Token Efficiency
import { registerTokenAudit } from "./tools/token-audit.js";
// Category 6: Sequencing
import { registerSequenceTasks } from "./tools/sequence-tasks.js";
// Category 7: Compaction Management
import { registerCheckpoint } from "./tools/checkpoint.js";
// Category 8: Session Lifecycle
import { registerSessionHealth } from "./tools/session-health.js";
// Category 9: Error Recovery
import { registerLogCorrection } from "./tools/log-correction.js";
// Category 9b: Pattern Learning
import { registerCheckPatterns } from "./tools/check-patterns.js";
// Category 10: Workspace Hygiene
import { registerAuditWorkspace } from "./tools/audit-workspace.js";
// Category 11: Cross-Session Continuity
import { registerSessionHandoff } from "./tools/session-handoff.js";
import { registerWhatChanged } from "./tools/what-changed.js";
// Category 12: Verification
import { registerVerifyCompletion } from "./tools/verify-completion.js";
// New lightweight tools
import { registerSessionStats } from "./tools/session-stats.js";
import { registerPromptScore } from "./tools/prompt-score.js";
// Timeline: Project Intelligence
import { registerOnboardProject } from "./tools/onboard-project.js";
import { registerSearchHistory } from "./tools/search-history.js";
import { registerTimeline } from "./tools/timeline-view.js";
import { registerScanSessions } from "./tools/scan-sessions.js";
import { registerGenerateScorecard } from "./tools/generate-scorecard.js";
import { registerSearchContracts } from "./tools/search-contracts.js";
import { registerEstimateCost } from "./tools/estimate-cost.js";
import { registerExportTimeline } from "./tools/export-timeline.js";
// Validate related projects from config
function validateRelatedProjects(): void {
const config = getConfig();
const projects = config.related_projects;
if (projects.length === 0) return;
const invalid: string[] = [];
for (const project of projects) {
if (!existsSync(project.path)) {
invalid.push(`${project.alias} (${project.path})`);
}
}
if (invalid.length > 0) {
process.stderr.write(`preflight-dev: warning - related projects contain invalid paths: ${invalid.join(", ")}\n`);
} else {
process.stderr.write(`preflight-dev: related projects: ${projects.length} configured\n`);
}
}
// Load config and validate related projects on startup
const config = getConfig();
validateRelatedProjects();
const profile = getProfile();
const server = new McpServer({
name: "preflight",
version: "3.0.0",
});
// Register tools based on profile
type RegisterFn = (server: McpServer) => void;
const toolRegistry: Array<[string, RegisterFn]> = [
["preflight_check", registerPreflightCheck],
["scope_work", registerScopeWork],
["clarify_intent", registerClarifyIntent],
["enrich_agent_task", registerEnrichAgentTask],
["sharpen_followup", registerSharpenFollowup],
["token_audit", registerTokenAudit],
["sequence_tasks", registerSequenceTasks],
["checkpoint", registerCheckpoint],
["check_session_health", registerSessionHealth],
["log_correction", registerLogCorrection],
["check_patterns", registerCheckPatterns],
["audit_workspace", registerAuditWorkspace],
["session_handoff", registerSessionHandoff],
["what_changed", registerWhatChanged],
["verify_completion", registerVerifyCompletion],
["session_stats", registerSessionStats],
["prompt_score", registerPromptScore],
["onboard_project", registerOnboardProject],
["search_history", registerSearchHistory],
["timeline_view", registerTimeline],
["scan_sessions", registerScanSessions],
["generate_scorecard", registerGenerateScorecard],
["estimate_cost", registerEstimateCost],
["search_contracts", registerSearchContracts],
["export_timeline", registerExportTimeline],
];
let registered = 0;
for (const [name, register] of toolRegistry) {
if (isToolEnabled(name)) {
register(server);
registered++;
}
}
const configSource = hasPreflightConfig() ? ".preflight/" : "env vars";
process.stderr.write(`preflight: profile=${profile}, tools=${registered}, config=${configSource}\n`);
// Graceful shutdown
function shutdown() {
process.stderr.write("preflight: shutting down\n");
process.exit(0);
}
process.on("SIGINT", shutdown);
process.on("SIGTERM", shutdown);
// Connect transport
try {
const transport = new StdioServerTransport();
await server.connect(transport);
process.stderr.write("preflight: server started\n");
} catch (err) {
process.stderr.write(`preflight: failed to start — ${err}\n`);
process.exit(1);
}