@stackmemoryai/stackmemory
Version:
Lossless, project-scoped memory for AI coding tools. Durable context across sessions with 56 MCP tools, FTS5 search, conductor orchestrator, loop/watch monitoring, snapshot capture, pre-flight overlap checks, Claude/Codex/OpenCode wrappers, Linear sync, a
277 lines (276 loc) • 9.57 kB
JavaScript
import { fileURLToPath as __fileURLToPath } from 'url';
import { dirname as __pathDirname } from 'path';
const __filename = __fileURLToPath(import.meta.url);
const __dirname = __pathDirname(__filename);
import {
ContextHandlers
} from "./context-handlers.js";
import { TaskHandlers } from "./task-handlers.js";
import {
LinearHandlers
} from "./linear-handlers.js";
import {
TraceHandlers
} from "./trace-handlers.js";
import {
DiscoveryHandlers
} from "./discovery-handlers.js";
import {
ProviderHandlers
} from "./provider-handlers.js";
import { TeamHandlers } from "./team-handlers.js";
import { CordHandlers } from "./cord-handlers.js";
import {
ProvenantHandlers
} from "./provenant-handlers.js";
import {
ContextHandlers as ContextHandlers2
} from "./context-handlers.js";
import { TaskHandlers as TaskHandlers2 } from "./task-handlers.js";
import {
LinearHandlers as LinearHandlers2
} from "./linear-handlers.js";
import { TraceHandlers as TraceHandlers2 } from "./trace-handlers.js";
import { ProviderHandlers as ProviderHandlers2 } from "./provider-handlers.js";
import { TeamHandlers as TeamHandlers2 } from "./team-handlers.js";
import { CordHandlers as CordHandlers2 } from "./cord-handlers.js";
import { ProvenantHandlers as ProvenantHandlers2 } from "./provenant-handlers.js";
class MCPHandlerFactory {
contextHandlers;
taskHandlers;
linearHandlers;
traceHandlers;
providerHandlers;
teamHandlers;
cordHandlers;
provenantHandlers;
constructor(deps) {
this.contextHandlers = new ContextHandlers2({
frameManager: deps.frameManager
});
this.taskHandlers = new TaskHandlers2({
taskStore: deps.taskStore,
projectId: deps.projectId
});
this.linearHandlers = new LinearHandlers2({
linearAuthManager: deps.linearAuthManager,
linearSync: deps.linearSync,
taskStore: deps.taskStore
});
this.traceHandlers = new TraceHandlers2({
traceDetector: deps.traceDetector,
browserMCP: deps.browserMCP
});
this.providerHandlers = new ProviderHandlers2();
if (deps.dbAdapter) {
this.teamHandlers = new TeamHandlers2({
frameManager: deps.frameManager,
dbAdapter: deps.dbAdapter
});
this.cordHandlers = new CordHandlers2({
frameManager: deps.frameManager,
dbAdapter: deps.dbAdapter
});
}
if (deps.projectDir) {
this.provenantHandlers = new ProvenantHandlers2({
projectDir: deps.projectDir
});
}
}
/**
* Get handler for a specific tool
*/
getHandler(toolName) {
switch (toolName) {
// Context handlers
case "get_context":
return this.contextHandlers.handleGetContext.bind(this.contextHandlers);
case "add_decision":
return this.contextHandlers.handleAddDecision.bind(
this.contextHandlers
);
case "start_frame":
return this.contextHandlers.handleStartFrame.bind(this.contextHandlers);
case "close_frame":
return this.contextHandlers.handleCloseFrame.bind(this.contextHandlers);
case "add_anchor":
return this.contextHandlers.handleAddAnchor.bind(this.contextHandlers);
case "get_hot_stack":
return this.contextHandlers.handleGetHotStack.bind(
this.contextHandlers
);
// Task handlers
case "create_task":
return this.taskHandlers.handleCreateTask.bind(this.taskHandlers);
case "update_task_status":
return this.taskHandlers.handleUpdateTaskStatus.bind(this.taskHandlers);
case "get_active_tasks":
return this.taskHandlers.handleGetActiveTasks.bind(this.taskHandlers);
case "get_task_metrics":
return this.taskHandlers.handleGetTaskMetrics.bind(this.taskHandlers);
// Linear handlers
case "linear_sync":
return this.linearHandlers.handleLinearSync.bind(this.linearHandlers);
case "linear_update_task":
return this.linearHandlers.handleLinearUpdateTask.bind(
this.linearHandlers
);
case "linear_get_tasks":
return this.linearHandlers.handleLinearGetTasks.bind(
this.linearHandlers
);
case "linear_status":
return this.linearHandlers.handleLinearStatus.bind(this.linearHandlers);
// Trace handlers
case "get_traces":
return this.traceHandlers.handleGetTraces.bind(this.traceHandlers);
case "start_browser_debug":
return this.traceHandlers.handleStartBrowserDebug.bind(
this.traceHandlers
);
case "take_screenshot":
return this.traceHandlers.handleTakeScreenshot.bind(this.traceHandlers);
case "execute_script":
return this.traceHandlers.handleExecuteScript.bind(this.traceHandlers);
case "stop_browser_debug":
return this.traceHandlers.handleStopBrowserDebug.bind(
this.traceHandlers
);
// Provider handlers
case "delegate_to_model":
return this.providerHandlers.handleDelegateToModel.bind(
this.providerHandlers
);
case "batch_submit":
return this.providerHandlers.handleBatchSubmit.bind(
this.providerHandlers
);
case "batch_check":
return this.providerHandlers.handleBatchCheck.bind(
this.providerHandlers
);
// Team handlers
case "team_context_get":
if (!this.teamHandlers) throw new Error("Team tools require dbAdapter");
return this.teamHandlers.handleTeamContextGet.bind(this.teamHandlers);
case "team_context_share":
if (!this.teamHandlers) throw new Error("Team tools require dbAdapter");
return this.teamHandlers.handleTeamContextShare.bind(this.teamHandlers);
case "team_search":
if (!this.teamHandlers) throw new Error("Team tools require dbAdapter");
return this.teamHandlers.handleTeamSearch.bind(this.teamHandlers);
// Cord orchestration handlers
case "cord_spawn":
if (!this.cordHandlers) throw new Error("Cord tools require dbAdapter");
return this.cordHandlers.handleCordSpawn.bind(this.cordHandlers);
case "cord_fork":
if (!this.cordHandlers) throw new Error("Cord tools require dbAdapter");
return this.cordHandlers.handleCordFork.bind(this.cordHandlers);
case "cord_complete":
if (!this.cordHandlers) throw new Error("Cord tools require dbAdapter");
return this.cordHandlers.handleCordComplete.bind(this.cordHandlers);
case "cord_ask":
if (!this.cordHandlers) throw new Error("Cord tools require dbAdapter");
return this.cordHandlers.handleCordAsk.bind(this.cordHandlers);
case "cord_tree":
if (!this.cordHandlers) throw new Error("Cord tools require dbAdapter");
return this.cordHandlers.handleCordTree.bind(this.cordHandlers);
// Provenant decision graph handlers
case "provenant_search":
if (!this.provenantHandlers)
throw new Error("Provenant tools require projectDir");
return this.provenantHandlers.handleSearch.bind(this.provenantHandlers);
case "provenant_log":
if (!this.provenantHandlers)
throw new Error("Provenant tools require projectDir");
return this.provenantHandlers.handleLog.bind(this.provenantHandlers);
case "provenant_status":
if (!this.provenantHandlers)
throw new Error("Provenant tools require projectDir");
return this.provenantHandlers.handleStatus.bind(this.provenantHandlers);
case "provenant_contradictions":
if (!this.provenantHandlers)
throw new Error("Provenant tools require projectDir");
return this.provenantHandlers.handleContradictions.bind(
this.provenantHandlers
);
case "provenant_resolve":
if (!this.provenantHandlers)
throw new Error("Provenant tools require projectDir");
return this.provenantHandlers.handleResolve.bind(
this.provenantHandlers
);
default:
throw new Error(`Unknown tool: ${toolName}`);
}
}
/**
* Get all available tool names
*/
getAvailableTools() {
return [
// Context tools
"get_context",
"add_decision",
"start_frame",
"close_frame",
"add_anchor",
"get_hot_stack",
// Task tools
"create_task",
"update_task_status",
"get_active_tasks",
"get_task_metrics",
// Linear tools
"linear_sync",
"linear_update_task",
"linear_get_tasks",
"linear_status",
// Trace tools
"get_traces",
"start_browser_debug",
"take_screenshot",
"execute_script",
"stop_browser_debug",
// Provider tools (conditionally active)
"delegate_to_model",
"batch_submit",
"batch_check",
// Team tools
"team_context_get",
"team_context_share",
"team_search",
// Cord orchestration tools
"cord_spawn",
"cord_fork",
"cord_complete",
"cord_ask",
"cord_tree",
// Provenant decision graph tools
"provenant_search",
"provenant_log",
"provenant_status",
"provenant_contradictions",
"provenant_resolve"
];
}
/**
* Check if a tool exists
*/
hasHandler(toolName) {
return this.getAvailableTools().includes(toolName);
}
}
export {
ContextHandlers,
CordHandlers,
DiscoveryHandlers,
LinearHandlers,
MCPHandlerFactory,
ProvenantHandlers,
ProviderHandlers,
TaskHandlers,
TeamHandlers,
TraceHandlers
};