import { openMemory, printMcpConfig, resolveConfiguredMemoryRoot, startMemoryMcpServer } from "@poe-code/memory";
import { mcpWritesAllowed } from "@poe-code/poe-code-config";
export function registerMemoryMcpCommand(program, container) {
    program
        .command("memory-mcp")
        .description("Run the memory MCP server on stdin/stdout.")
        .option("--allow-writes", "Enable append_to_page writes.")
        .option("--print-mcp-config", "Print MCP client configuration as JSON.")
        .action(async (options) => {
        if (options.printMcpConfig === true) {
            process.stdout.write(`${printMcpConfig()}\n`);
            return;
        }
        const root = await resolveConfiguredMemoryRoot({
            cwd: container.env.cwd,
            env: container.env.variables,
            fs: container.fs,
            configPath: container.env.configPath,
            projectConfigPath: container.env.projectConfigPath
        });
        const handle = openMemory({ root });
        const allowWrites = options.allowWrites === true ||
            (await mcpWritesAllowed({
                fs: container.fs,
                filePath: container.env.configPath,
                projectFilePath: container.env.projectConfigPath
            }));
        const { server } = await startMemoryMcpServer(handle, { allowWrites });
        await server.listen();
    });
}
//# sourceMappingURL=memory-mcp.js.map