export type { LspServerStatus } from "../lsp/client.js";
export {
	createLspTool,
	type LspToolDetails,
	lspSchema,
	lspTool,
} from "../lsp/index.js";
export {
	type BashOperations,
	type BashSpawnContext,
	type BashSpawnHook,
	type BashToolDetails,
	type BashToolInput,
	type BashToolOptions,
	bashTool,
	createBashTool,
	rewriteBackgroundCommand,
} from "./bash.js";
export {
	type BashInterceptorRule,
	type CompiledInterceptor,
	checkBashInterception,
	compileInterceptor,
	DEFAULT_BASH_INTERCEPTOR_RULES,
	type InterceptionResult,
} from "./bash-interceptor.js";
export {
	createEditTool,
	type EditOperations,
	type EditToolDetails,
	type EditToolInput,
	type EditToolOptions,
	editTool,
} from "./edit.js";
export {
	createFindTool,
	type FindOperations,
	type FindToolDetails,
	type FindToolInput,
	type FindToolOptions,
	findTool,
} from "./find.js";
export {
	createGrepTool,
	type GrepOperations,
	type GrepToolDetails,
	type GrepToolInput,
	type GrepToolOptions,
	grepTool,
} from "./grep.js";
export { createAstGrepTool } from "./ast-grep.js";
export { createInsertAroundSymbolTool } from "./insert-around-symbol.js";
export { createReplaceSymbolTool } from "./replace-symbol.js";
export {
	type Anchor,
	applyHashlineEdits,
	computeLineHash,
	formatHashLines,
	formatLineTag,
	type HashlineEdit,
	HashlineMismatchError,
	type HashMismatch,
	parseHashlineText,
	parseTag,
	stripNewLinePrefixes,
	validateLineRef,
} from "./hashline.js";
export {
	createLsTool,
	type LsOperations,
	type LsToolDetails,
	type LsToolInput,
	type LsToolOptions,
	lsTool,
} from "./ls.js";
export {
	createReadTool,
	type ReadOperations,
	type ReadToolDetails,
	type ReadToolInput,
	type ReadToolOptions,
	readTool,
} from "./read.js";
export {
	getAllToolCompatibility,
	getToolCompatibility,
	registerMcpToolCompatibility,
	registerToolCompatibility,
	resetToolCompatibilityRegistry,
} from "./tool-compatibility-registry.js";
export {
	DEFAULT_MAX_BYTES,
	DEFAULT_MAX_LINES,
	formatSize,
	type TruncationOptions,
	type TruncationResult,
	truncateHead,
	truncateLine,
	truncateTail,
} from "./truncate.js";
export {
	createWriteTool,
	type WriteOperations,
	type WriteToolInput,
	type WriteToolOptions,
	writeTool,
} from "./write.js";

import type { AgentTool } from "@singularity-forge/agent-core";
import { createLspTool, lspTool } from "../lsp/index.js";
import { createAstGrepTool } from "./ast-grep.js";
import { type BashToolOptions, bashTool, createBashTool } from "./bash.js";
import { createEditTool, editTool } from "./edit.js";
import { createFindTool, findTool } from "./find.js";
import { createGrepTool, grepTool } from "./grep.js";
import { createInsertAroundSymbolTool } from "./insert-around-symbol.js";
import { createLsTool, lsTool } from "./ls.js";
import { createReadTool, type ReadToolOptions, readTool } from "./read.js";
import { createReplaceSymbolTool } from "./replace-symbol.js";
import { createWriteTool, writeTool } from "./write.js";

/** Tool type (AgentTool from pi-ai) */
export type Tool = AgentTool<any>;

// Default tools for full access mode (using process.cwd())
export const codingTools: Tool[] = [
	readTool,
	grepTool,
	findTool,
	lsTool,
	bashTool,
	editTool,
	writeTool,
	lspTool,
];

// Read-only tools for exploration without modification (using process.cwd())
export const readOnlyTools: Tool[] = [readTool, grepTool, findTool, lsTool];

// All available tools (using process.cwd())
export const allTools = {
	Read: readTool,
	Bash: bashTool,
	Edit: editTool,
	Write: writeTool,
	Grep: grepTool,
	Glob: findTool,
	LS: lsTool,
	lsp: lspTool,
	// Serena-style AST tools: tree-sitter-anchored, language-aware editing.
	// More durable than substring Edit / line-anchor hashline for code in
	// languages with a tree-sitter grammar.
	ReplaceSymbol: createReplaceSymbolTool(process.cwd()),
	InsertAroundSymbol: createInsertAroundSymbolTool(process.cwd()),
	AstGrep: createAstGrepTool(process.cwd()),
};

export type ToolName = keyof typeof allTools;

export interface ToolsOptions {
	/** Options for the read tool */
	read?: ReadToolOptions;
	/** Options for the bash tool */
	bash?: BashToolOptions;
}

/**
 * Create coding tools configured for a specific working directory.
 */
export function createCodingTools(cwd: string, options?: ToolsOptions): Tool[] {
	return [
		createReadTool(cwd, options?.read),
		createGrepTool(cwd),
		createFindTool(cwd),
		createLsTool(cwd),
		createBashTool(cwd, options?.bash),
		createEditTool(cwd),
		createWriteTool(cwd),
		createLspTool(cwd),
	];
}

/**
 * Create read-only tools configured for a specific working directory.
 */
export function createReadOnlyTools(
	cwd: string,
	options?: ToolsOptions,
): Tool[] {
	return [
		createReadTool(cwd, options?.read),
		createGrepTool(cwd),
		createFindTool(cwd),
		createLsTool(cwd),
	];
}

/**
 * Create all tools configured for a specific working directory.
 */
export function createAllTools(
	cwd: string,
	options?: ToolsOptions,
): Record<ToolName, Tool> {
	return {
		Read: createReadTool(cwd, options?.read),
		Bash: createBashTool(cwd, options?.bash),
		Edit: createEditTool(cwd),
		Write: createWriteTool(cwd),
		Grep: createGrepTool(cwd),
		Glob: createFindTool(cwd),
		LS: createLsTool(cwd),
		lsp: createLspTool(cwd),
		ReplaceSymbol: createReplaceSymbolTool(cwd),
		InsertAroundSymbol: createInsertAroundSymbolTool(cwd),
		AstGrep: createAstGrepTool(cwd),
	};
}
