@sema-agent/core
Version:
Stateless, task-oriented AI agent core
29 lines (28 loc) • 1.83 kB
JavaScript
import { createLspTool, gitCheckIgnoreFilter, lspBaseOf, lspListedWithheld, lspReadGateOf, resolveLspPath } from "../lsp.js";
import { pathToUri } from "../lsp-protocol.js";
import { RosterBuilder } from "../tool-roster.js";
export function prepareLsp(input) {
const { spec, deps, executionEnv, readFloor, taskRootFinal, readFace, sessionId, roster } = input;
const lspManager = spec.lspManager ?? deps.lspManager;
roster.mounts.know({ "lsp.readFace": readFace !== undefined });
if (roster.mounts.judge("lsp") && lspManager && readFace) {
roster.mount(createLspTool(lspManager, { isPathIgnored: gitCheckIgnoreFilter(executionEnv, taskRootFinal, () => readFloor(undefined)), env: executionEnv, readFace }), { source: "builtin", mountedBy: "hands" });
}
const lspDiagnostics = spec.lspDiagnostics !== false && lspManager?.diagnostics !== undefined && readFace !== undefined && spec.handsReadOnly !== true
? lspManager.diagnostics
: undefined;
const lspRunIdent = sessionId;
const nudgeLspOnEdit = lspDiagnostics && readFace
? (rawPath) => {
const filePath = resolveLspPath(rawPath, lspBaseOf(readFace));
lspDiagnostics.fileEdited(lspRunIdent, pathToUri(filePath));
const gate = lspReadGateOf(executionEnv, readFace);
void lspManager
.sessionFor(filePath, undefined, executionEnv)
.then((session) => session?.notifyFileChanged?.(filePath, undefined, gate))
.catch(() => undefined);
}
: undefined;
const withheldDiagnosticsOf = lspDiagnostics && readFace ? (uris) => lspListedWithheld(executionEnv, readFace, uris) : undefined;
return { lspDiagnostics, nudgeLspOnEdit, withheldDiagnosticsOf, lspRunIdent, managerWired: lspManager !== undefined };
}