@cortexkit/aft 0.17.0 → 0.17.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,53 @@
1
+ import type { sendAftRequest } from "../lib/aft-bridge.js";
2
+ import { sendAftRequests } from "../lib/aft-bridge.js";
3
+ import { findAftBinary } from "../lib/binary-probe.js";
4
+ import { resolveAdaptersForCommand } from "../lib/harness-select.js";
5
+ export interface LspDoctorOptions {
6
+ argv: string[];
7
+ sendRequest?: typeof sendAftRequest;
8
+ sendRequests?: typeof sendAftRequests;
9
+ findBinary?: typeof findAftBinary;
10
+ resolveAdapters?: typeof resolveAdaptersForCommand;
11
+ }
12
+ export interface LspInspectResponse {
13
+ success: boolean;
14
+ code?: string;
15
+ message?: string;
16
+ file?: string;
17
+ extension?: string;
18
+ project_root?: string | null;
19
+ experimental_lsp_ty?: boolean;
20
+ disabled_lsp?: string[];
21
+ lsp_paths_extra?: string[];
22
+ matching_servers?: LspServerInspection[];
23
+ diagnostics_count?: number;
24
+ diagnostics?: LspDiagnostic[];
25
+ }
26
+ export interface LspServerInspection {
27
+ id: string;
28
+ name: string;
29
+ kind: string;
30
+ extensions: string[];
31
+ root_markers: string[];
32
+ binary_name: string;
33
+ binary_path: string | null;
34
+ binary_source: "path" | "lsp_paths_extra" | "project_node_modules" | "not_found" | string;
35
+ workspace_root: string | null;
36
+ spawn_status: string;
37
+ args: string[];
38
+ }
39
+ export interface LspDiagnostic {
40
+ file: string;
41
+ line: number;
42
+ column: number;
43
+ end_line?: number;
44
+ end_column?: number;
45
+ severity: string;
46
+ message: string;
47
+ code?: string | null;
48
+ source?: string | null;
49
+ }
50
+ export declare function printLspDoctorHelp(): void;
51
+ export declare function runLspDoctor(options: LspDoctorOptions): Promise<number>;
52
+ export declare function renderLspInspection(inputFile: string, response: LspInspectResponse): string;
53
+ //# sourceMappingURL=lsp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lsp.d.ts","sourceRoot":"","sources":["../../src/commands/lsp.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAc,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAMrE,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,WAAW,CAAC,EAAE,OAAO,cAAc,CAAC;IACpC,YAAY,CAAC,EAAE,OAAO,eAAe,CAAC;IACtC,UAAU,CAAC,EAAE,OAAO,aAAa,CAAC;IAClC,eAAe,CAAC,EAAE,OAAO,yBAAyB,CAAC;CACpD;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,gBAAgB,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACzC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,WAAW,CAAC,EAAE,aAAa,EAAE,CAAC;CAC/B;AAED,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,aAAa,EAAE,MAAM,GAAG,iBAAiB,GAAG,sBAAsB,GAAG,WAAW,GAAG,MAAM,CAAC;IAC1F,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED,wBAAgB,kBAAkB,IAAI,IAAI,CAIzC;AAED,wBAAsB,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CA0D7E;AAED,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,kBAAkB,GAAG,MAAM,CAmD3F"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;GAMG;AAEH,QAAA,MAAM,OAAO,QAAkB,CAAC;AAChC,QAAA,MAAM,IAAI,UAAwB,CAAC;AAEnC,iBAAS,SAAS,IAAI,IAAI,CAsBzB;AAED,iBAAe,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAcrC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;GAMG;AAEH,QAAA,MAAM,OAAO,QAAkB,CAAC;AAChC,QAAA,MAAM,IAAI,UAAwB,CAAC;AAEnC,iBAAS,SAAS,IAAI,IAAI,CAwBzB;AAED,iBAAe,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAkBrC"}
package/dist/index.js CHANGED
@@ -9781,44 +9781,79 @@ var init_setup = __esm(() => {
9781
9781
  init_prompts();
9782
9782
  });
9783
9783
 
9784
- // src/lib/binary-cache.ts
9785
- import { existsSync as existsSync5, readdirSync as readdirSync2, statSync as statSync2 } from "node:fs";
9786
- import { join as join5 } from "node:path";
9787
- function getBinaryCacheInfo(activeVersion) {
9788
- const path = getAftBinaryCacheDir();
9789
- if (!existsSync5(path)) {
9790
- return {
9791
- versions: [],
9792
- activeVersion: null,
9793
- totalSize: 0,
9794
- path
9784
+ // src/lib/aft-bridge.ts
9785
+ import { spawn } from "node:child_process";
9786
+ async function sendAftRequests(binaryPath, requests) {
9787
+ return new Promise((resolve2, reject) => {
9788
+ const child = spawn(binaryPath, [], {
9789
+ stdio: ["pipe", "pipe", "pipe"]
9790
+ });
9791
+ const responses = [];
9792
+ let stdout = "";
9793
+ let stderr = "";
9794
+ let settled = false;
9795
+ const finish = (fn) => {
9796
+ if (settled)
9797
+ return;
9798
+ settled = true;
9799
+ child.kill();
9800
+ fn();
9795
9801
  };
9796
- }
9797
- const versions = readdirSync2(path).filter((entry) => {
9798
- try {
9799
- return statSync2(join5(path, entry)).isDirectory();
9800
- } catch {
9801
- return false;
9802
+ const handleLine = (line) => {
9803
+ if (!line)
9804
+ return;
9805
+ try {
9806
+ responses.push(JSON.parse(line));
9807
+ } catch (error) {
9808
+ finish(() => reject(error));
9809
+ return;
9810
+ }
9811
+ if (responses.length === requests.length) {
9812
+ finish(() => resolve2(responses));
9813
+ }
9814
+ };
9815
+ child.stdout.setEncoding("utf-8");
9816
+ child.stdout.on("data", (chunk) => {
9817
+ stdout += chunk;
9818
+ while (true) {
9819
+ const newline = stdout.indexOf(`
9820
+ `);
9821
+ if (newline === -1)
9822
+ break;
9823
+ const line = stdout.slice(0, newline).trim();
9824
+ stdout = stdout.slice(newline + 1);
9825
+ handleLine(line);
9826
+ if (settled)
9827
+ break;
9828
+ }
9829
+ });
9830
+ child.stderr.setEncoding("utf-8");
9831
+ child.stderr.on("data", (chunk) => {
9832
+ stderr += chunk;
9833
+ });
9834
+ child.on("error", (error) => {
9835
+ finish(() => reject(error));
9836
+ });
9837
+ child.on("exit", (code) => {
9838
+ if (settled)
9839
+ return;
9840
+ finish(() => reject(new Error(`aft exited before responding (code ${code}): ${stderr.trim()}`)));
9841
+ });
9842
+ for (const request of requests) {
9843
+ child.stdin.write(`${JSON.stringify(request)}
9844
+ `);
9802
9845
  }
9803
- }).sort(compareVersionLabels);
9804
- const tag = activeVersion ? activeVersion.startsWith("v") ? activeVersion : `v${activeVersion}` : null;
9805
- const resolvedActive = tag && versions.includes(tag) ? tag : null;
9806
- return {
9807
- versions,
9808
- activeVersion: resolvedActive,
9809
- totalSize: dirSize(path),
9810
- path
9811
- };
9846
+ child.stdin.end();
9847
+ });
9812
9848
  }
9813
- var init_binary_cache = __esm(() => {
9814
- init_fs_util();
9815
- init_paths();
9816
- });
9849
+ var init_aft_bridge = () => {};
9817
9850
 
9818
9851
  // src/lib/binary-probe.ts
9819
9852
  import { execSync as execSync3 } from "node:child_process";
9820
- import { existsSync as existsSync6 } from "node:fs";
9821
- import { join as join6 } from "node:path";
9853
+ import { existsSync as existsSync5 } from "node:fs";
9854
+ import { createRequire as createRequire2 } from "node:module";
9855
+ import { homedir as homedir4 } from "node:os";
9856
+ import { join as join5 } from "node:path";
9822
9857
  function normalizeVersion(output) {
9823
9858
  const trimmed = output.trim();
9824
9859
  if (!trimmed)
@@ -9829,7 +9864,7 @@ function probeBinaryVersion(preferredVersion) {
9829
9864
  const candidates = [];
9830
9865
  if (preferredVersion) {
9831
9866
  const tag = preferredVersion.startsWith("v") ? preferredVersion : `v${preferredVersion}`;
9832
- candidates.push(join6(getAftBinaryCacheDir(), tag, getAftBinaryName()));
9867
+ candidates.push(join5(getAftBinaryCacheDir(), tag, getAftBinaryName()));
9833
9868
  }
9834
9869
  try {
9835
9870
  const lookup = process.platform === "win32" ? "where aft" : "which aft";
@@ -9840,7 +9875,7 @@ function probeBinaryVersion(preferredVersion) {
9840
9875
  } catch {}
9841
9876
  for (const candidate of candidates) {
9842
9877
  try {
9843
- if (!existsSync6(candidate))
9878
+ if (!existsSync5(candidate))
9844
9879
  continue;
9845
9880
  const output = execSync3(`"${candidate}" --version`, {
9846
9881
  stdio: "pipe",
@@ -9853,29 +9888,369 @@ function probeBinaryVersion(preferredVersion) {
9853
9888
  }
9854
9889
  return null;
9855
9890
  }
9891
+ function platformKey(platform = process.platform, arch = process.arch) {
9892
+ const table = {
9893
+ darwin: { arm64: "darwin-arm64", x64: "darwin-x64" },
9894
+ linux: { arm64: "linux-arm64", x64: "linux-x64" },
9895
+ win32: { x64: "win32-x64" }
9896
+ };
9897
+ return table[platform]?.[arch] ?? null;
9898
+ }
9899
+ function findAftBinary(preferredVersion) {
9900
+ const candidates = [];
9901
+ if (preferredVersion) {
9902
+ const tag = preferredVersion.startsWith("v") ? preferredVersion : `v${preferredVersion}`;
9903
+ candidates.push(join5(getAftBinaryCacheDir(), tag, getAftBinaryName()));
9904
+ }
9905
+ const key = platformKey();
9906
+ if (key) {
9907
+ try {
9908
+ const require2 = createRequire2(import.meta.url);
9909
+ candidates.push(require2.resolve(`@cortexkit/aft-${key}/bin/${getAftBinaryName()}`));
9910
+ } catch {}
9911
+ }
9912
+ try {
9913
+ const lookup = process.platform === "win32" ? "where aft" : "which aft";
9914
+ const resolved = execSync3(lookup, { stdio: "pipe", encoding: "utf-8" }).trim();
9915
+ if (resolved) {
9916
+ candidates.push(resolved.split(/\r?\n/)[0]);
9917
+ }
9918
+ } catch {}
9919
+ candidates.push(join5(homedir4(), ".cargo", "bin", getAftBinaryName()));
9920
+ for (const candidate of candidates) {
9921
+ if (existsSync5(candidate))
9922
+ return candidate;
9923
+ }
9924
+ return null;
9925
+ }
9856
9926
  var init_binary_probe = __esm(() => {
9857
9927
  init_paths();
9858
9928
  });
9859
9929
 
9860
- // src/lib/lsp-cache.ts
9861
- import { existsSync as existsSync7, readdirSync as readdirSync3, rmSync as rmSync2, statSync as statSync3 } from "node:fs";
9930
+ // src/commands/lsp.ts
9931
+ var exports_lsp = {};
9932
+ __export(exports_lsp, {
9933
+ runLspDoctor: () => runLspDoctor,
9934
+ renderLspInspection: () => renderLspInspection,
9935
+ printLspDoctorHelp: () => printLspDoctorHelp
9936
+ });
9937
+ import { existsSync as existsSync6, readdirSync as readdirSync2, statSync as statSync2 } from "node:fs";
9938
+ import { join as join6, resolve as resolve2 } from "node:path";
9939
+ function printLspDoctorHelp() {
9940
+ console.log("Usage: aft doctor lsp <file> [--harness opencode|pi]");
9941
+ console.log("");
9942
+ console.log("Inspect what AFT's LSP layer would do for a file.");
9943
+ }
9944
+ async function runLspDoctor(options) {
9945
+ const file = parseFileArg(options.argv);
9946
+ if (!file) {
9947
+ printLspDoctorHelp();
9948
+ return 1;
9949
+ }
9950
+ const resolveAdapters = options.resolveAdapters ?? resolveAdaptersForCommand;
9951
+ const adapters = await resolveAdapters(options.argv, {
9952
+ allowMulti: false,
9953
+ verb: "inspect LSP for"
9954
+ });
9955
+ const adapter = adapters[0];
9956
+ if (!adapter) {
9957
+ O2.error("No harness selected.");
9958
+ return 1;
9959
+ }
9960
+ const findBinary = options.findBinary ?? findAftBinary;
9961
+ const binary = findBinary(getSelfVersion());
9962
+ if (!binary) {
9963
+ O2.error("Could not find the aft binary in the cache, platform package, PATH, or ~/.cargo/bin.");
9964
+ return 1;
9965
+ }
9966
+ const projectRoot = resolve2(process.cwd());
9967
+ const config = buildConfigureParams(adapter, projectRoot);
9968
+ const inspectRequest = {
9969
+ id: "doctor-lsp-inspect",
9970
+ command: "lsp_inspect",
9971
+ file: resolve2(file)
9972
+ };
9973
+ const responses = options.sendRequests ? await options.sendRequests(binary, [config, inspectRequest]) : options.sendRequest ? [await options.sendRequest(binary, inspectRequest)] : await sendAftRequests(binary, [config, inspectRequest]);
9974
+ const configure = responses.length > 1 ? responses[0] : undefined;
9975
+ if (configure && !configure.success) {
9976
+ O2.error(configure.message ?? configure.code ?? "configure failed");
9977
+ return 1;
9978
+ }
9979
+ const inspect = responses[responses.length - 1];
9980
+ if (!inspect) {
9981
+ O2.error("aft exited before returning lsp_inspect response");
9982
+ return 1;
9983
+ }
9984
+ if (!inspect.success) {
9985
+ O2.error(inspect.message ?? inspect.code ?? "lsp_inspect failed");
9986
+ return 1;
9987
+ }
9988
+ console.log(renderLspInspection(file, inspect));
9989
+ return 0;
9990
+ }
9991
+ function renderLspInspection(inputFile, response) {
9992
+ const lines = [];
9993
+ lines.push(`LSP inspection — ${inputFile}`);
9994
+ lines.push("");
9995
+ lines.push(`Resolved file: ${response.file ?? "(unknown)"}`);
9996
+ lines.push(`File extension: ${response.extension ? `.${response.extension}` : "(none)"}`);
9997
+ lines.push(`Project root: ${response.project_root ?? "(not configured)"}`);
9998
+ lines.push("");
9999
+ lines.push(`Active config: experimental_lsp_ty=${response.experimental_lsp_ty === true ? "true" : "false"}, disabled_lsp=${formatList(response.disabled_lsp ?? [])}`);
10000
+ lines.push(`lsp_paths_extra: ${formatList(response.lsp_paths_extra ?? [])}`);
10001
+ lines.push("");
10002
+ lines.push("Server attempts:");
10003
+ const active = new Set(response.matching_servers?.map((server) => server.id) ?? []);
10004
+ for (const id of response.disabled_lsp ?? []) {
10005
+ if (!active.has(id)) {
10006
+ lines.push(` • ${id}: disabled by config`);
10007
+ }
10008
+ }
10009
+ const servers = response.matching_servers ?? [];
10010
+ if (servers.length === 0) {
10011
+ lines.push(" (no registered LSP servers match this file extension)");
10012
+ }
10013
+ for (const server of servers) {
10014
+ const ok = server.spawn_status === "ok";
10015
+ lines.push(` ${ok ? "✓" : "✗"} ${server.id}`);
10016
+ lines.push(` Binary: ${formatBinary(server)}`);
10017
+ lines.push(` Workspace root: ${formatWorkspaceRoot(server)}`);
10018
+ lines.push(` Args: ${JSON.stringify(server.args)}`);
10019
+ lines.push(` Status: ${formatSpawnStatus(server)}`);
10020
+ if (server.binary_source === "not_found") {
10021
+ lines.push(` Action: ${installHint(server.binary_name)}`);
10022
+ }
10023
+ }
10024
+ const diagnostics = response.diagnostics ?? [];
10025
+ lines.push("");
10026
+ lines.push(`Diagnostics (${response.diagnostics_count ?? diagnostics.length} found):`);
10027
+ if (diagnostics.length === 0) {
10028
+ lines.push(" (none)");
10029
+ }
10030
+ for (const diagnostic of diagnostics) {
10031
+ lines.push(` ${diagnostic.file}:${diagnostic.line}:${diagnostic.column} [${diagnostic.severity}] ${diagnostic.message}`);
10032
+ }
10033
+ return lines.join(`
10034
+ `);
10035
+ }
10036
+ function parseFileArg(argv) {
10037
+ for (let i = 0;i < argv.length; i += 1) {
10038
+ const arg = argv[i];
10039
+ if (arg === "--harness") {
10040
+ i += 1;
10041
+ continue;
10042
+ }
10043
+ if (arg.startsWith("--"))
10044
+ continue;
10045
+ return arg;
10046
+ }
10047
+ return null;
10048
+ }
10049
+ function buildConfigureParams(adapter, projectRoot) {
10050
+ const paths = adapter.detectConfigPaths();
10051
+ const userConfig = readJsoncFile(paths.aftConfig).value ?? {};
10052
+ const projectConfig = readProjectConfig(adapter.kind, projectRoot);
10053
+ const merged = mergeConfig(userConfig, projectConfig);
10054
+ const lsp = isRecord(merged.lsp) ? merged.lsp : {};
10055
+ const lspConfig = resolveLspConfig(merged);
10056
+ return {
10057
+ id: "doctor-lsp-configure",
10058
+ command: "configure",
10059
+ project_root: projectRoot,
10060
+ ...lspConfig,
10061
+ lsp_paths_extra: inferLspPathsExtra(lsp)
10062
+ };
10063
+ }
10064
+ function readProjectConfig(kind, projectRoot) {
10065
+ const dir = kind === "pi" ? ".pi" : ".opencode";
10066
+ const jsonc = join6(projectRoot, dir, "aft.jsonc");
10067
+ const json = join6(projectRoot, dir, "aft.json");
10068
+ if (existsSync6(jsonc))
10069
+ return readJsoncFile(jsonc).value ?? {};
10070
+ if (existsSync6(json))
10071
+ return readJsoncFile(json).value ?? {};
10072
+ return {};
10073
+ }
10074
+ function mergeConfig(userConfig, projectConfig) {
10075
+ const userLsp = isRecord(userConfig.lsp) ? userConfig.lsp : {};
10076
+ const projectLsp = isRecord(projectConfig.lsp) ? projectConfig.lsp : {};
10077
+ return {
10078
+ ...userConfig,
10079
+ ...projectConfig,
10080
+ lsp: {
10081
+ ...userLsp,
10082
+ ...projectLsp,
10083
+ ...isRecord(userLsp.servers) ? { servers: userLsp.servers } : {},
10084
+ ...Array.isArray(userLsp.disabled) ? { disabled: userLsp.disabled } : {}
10085
+ }
10086
+ };
10087
+ }
10088
+ function resolveLspConfig(config) {
10089
+ const lsp = isRecord(config.lsp) ? config.lsp : {};
10090
+ const disabled = new Set;
10091
+ for (const entry of Array.isArray(lsp.disabled) ? lsp.disabled : []) {
10092
+ if (typeof entry === "string")
10093
+ disabled.add(entry.toLowerCase());
10094
+ }
10095
+ let experimentalTy = typeof config.experimental_lsp_ty === "boolean" ? config.experimental_lsp_ty : undefined;
10096
+ if (lsp.python === "ty") {
10097
+ experimentalTy = true;
10098
+ disabled.add("python");
10099
+ } else if (lsp.python === "pyright") {
10100
+ experimentalTy = false;
10101
+ disabled.add("ty");
10102
+ }
10103
+ const result = {};
10104
+ if (experimentalTy !== undefined)
10105
+ result.experimental_lsp_ty = experimentalTy;
10106
+ if (disabled.size > 0)
10107
+ result.disabled_lsp = [...disabled];
10108
+ const servers = resolveCustomServers(lsp.servers);
10109
+ if (servers.length > 0)
10110
+ result.lsp_servers = servers;
10111
+ return result;
10112
+ }
10113
+ function resolveCustomServers(servers) {
10114
+ if (!isRecord(servers))
10115
+ return [];
10116
+ return Object.entries(servers).filter(([, server]) => isRecord(server)).map(([id, server]) => {
10117
+ const entry = server;
10118
+ return {
10119
+ id,
10120
+ extensions: Array.isArray(entry.extensions) ? entry.extensions : [],
10121
+ binary: typeof entry.binary === "string" ? entry.binary : "",
10122
+ args: Array.isArray(entry.args) ? entry.args : [],
10123
+ root_markers: Array.isArray(entry.root_markers) ? entry.root_markers : [".git"],
10124
+ disabled: entry.disabled === true,
10125
+ ...isRecord(entry.env) ? { env: entry.env } : {},
10126
+ ...entry.initialization_options !== undefined ? { initialization_options: entry.initialization_options } : {}
10127
+ };
10128
+ }).filter((server) => typeof server.binary === "string" && server.binary.length > 0);
10129
+ }
10130
+ function inferLspPathsExtra(lsp) {
10131
+ if (lsp.auto_install === false)
10132
+ return [];
10133
+ const paths = new Set;
10134
+ for (const entry of childDirs(getAftLspPackagesDir())) {
10135
+ paths.add(join6(entry, "node_modules", ".bin"));
10136
+ }
10137
+ for (const entry of childDirs(getAftLspBinariesDir())) {
10138
+ paths.add(join6(entry, "bin"));
10139
+ }
10140
+ return [...paths];
10141
+ }
10142
+ function childDirs(path) {
10143
+ if (!existsSync6(path))
10144
+ return [];
10145
+ try {
10146
+ return readdirSync2(path).map((entry) => join6(path, entry)).filter((entry) => {
10147
+ try {
10148
+ return statSync2(entry).isDirectory();
10149
+ } catch {
10150
+ return false;
10151
+ }
10152
+ });
10153
+ } catch {
10154
+ return [];
10155
+ }
10156
+ }
10157
+ function formatBinary(server) {
10158
+ if (!server.binary_path) {
10159
+ return `${server.binary_name} (NOT FOUND on PATH or in lsp_paths_extra)`;
10160
+ }
10161
+ return `${server.binary_path} (found via ${server.binary_source})`;
10162
+ }
10163
+ function formatWorkspaceRoot(server) {
10164
+ if (!server.workspace_root) {
10165
+ return `(not found; markers: ${server.root_markers.join(", ") || "none"})`;
10166
+ }
10167
+ return `${server.workspace_root} (markers: ${server.root_markers.join(", ") || "none"})`;
10168
+ }
10169
+ function formatSpawnStatus(server) {
10170
+ if (server.spawn_status === "ok")
10171
+ return "spawned successfully";
10172
+ if (server.spawn_status === "binary_not_installed")
10173
+ return "binary not installed";
10174
+ if (server.spawn_status === "no_root_marker")
10175
+ return "no workspace root marker found";
10176
+ return server.spawn_status;
10177
+ }
10178
+ function formatList(values) {
10179
+ return values.length === 0 ? "(none)" : values.join(", ");
10180
+ }
10181
+ function installHint(binaryName) {
10182
+ if (binaryName === "ty")
10183
+ return "Install with `uv tool install ty` or `pip install ty`.";
10184
+ if (binaryName === "pyright-langserver")
10185
+ return "Install with `npm install -g pyright`.";
10186
+ return `Install ${binaryName} and ensure it is on PATH or in lsp_paths_extra.`;
10187
+ }
10188
+ function isRecord(value) {
10189
+ return typeof value === "object" && value !== null && !Array.isArray(value);
10190
+ }
10191
+ var init_lsp = __esm(() => {
10192
+ init_aft_bridge();
10193
+ init_binary_probe();
10194
+ init_harness_select();
10195
+ init_jsonc();
10196
+ init_paths();
10197
+ init_prompts();
10198
+ init_self_version();
10199
+ });
10200
+
10201
+ // src/lib/binary-cache.ts
10202
+ import { existsSync as existsSync7, readdirSync as readdirSync3, statSync as statSync3 } from "node:fs";
9862
10203
  import { join as join7 } from "node:path";
9863
- function inspectDir(path) {
10204
+ function getBinaryCacheInfo(activeVersion) {
10205
+ const path = getAftBinaryCacheDir();
9864
10206
  if (!existsSync7(path)) {
10207
+ return {
10208
+ versions: [],
10209
+ activeVersion: null,
10210
+ totalSize: 0,
10211
+ path
10212
+ };
10213
+ }
10214
+ const versions = readdirSync3(path).filter((entry) => {
10215
+ try {
10216
+ return statSync3(join7(path, entry)).isDirectory();
10217
+ } catch {
10218
+ return false;
10219
+ }
10220
+ }).sort(compareVersionLabels);
10221
+ const tag = activeVersion ? activeVersion.startsWith("v") ? activeVersion : `v${activeVersion}` : null;
10222
+ const resolvedActive = tag && versions.includes(tag) ? tag : null;
10223
+ return {
10224
+ versions,
10225
+ activeVersion: resolvedActive,
10226
+ totalSize: dirSize(path),
10227
+ path
10228
+ };
10229
+ }
10230
+ var init_binary_cache = __esm(() => {
10231
+ init_fs_util();
10232
+ init_paths();
10233
+ });
10234
+
10235
+ // src/lib/lsp-cache.ts
10236
+ import { existsSync as existsSync8, readdirSync as readdirSync4, rmSync as rmSync2, statSync as statSync4 } from "node:fs";
10237
+ import { join as join8 } from "node:path";
10238
+ function inspectDir(path) {
10239
+ if (!existsSync8(path)) {
9865
10240
  return { entries: [], totalSize: 0 };
9866
10241
  }
9867
10242
  const entries = [];
9868
10243
  let totalSize = 0;
9869
10244
  let names;
9870
10245
  try {
9871
- names = readdirSync3(path);
10246
+ names = readdirSync4(path);
9872
10247
  } catch {
9873
10248
  return { entries: [], totalSize: 0 };
9874
10249
  }
9875
10250
  for (const name of names) {
9876
- const full = join7(path, name);
10251
+ const full = join8(path, name);
9877
10252
  try {
9878
- if (!statSync3(full).isDirectory())
10253
+ if (!statSync4(full).isDirectory())
9879
10254
  continue;
9880
10255
  const size = dirSize(full);
9881
10256
  entries.push({
@@ -9931,8 +10306,8 @@ var init_lsp_cache = __esm(() => {
9931
10306
  });
9932
10307
 
9933
10308
  // src/lib/onnx.ts
9934
- import { existsSync as existsSync8, readdirSync as readdirSync4, readlinkSync, realpathSync, statSync as statSync4 } from "node:fs";
9935
- import { join as join8 } from "node:path";
10309
+ import { existsSync as existsSync9, readdirSync as readdirSync5, readlinkSync, realpathSync, statSync as statSync5 } from "node:fs";
10310
+ import { join as join9 } from "node:path";
9936
10311
  function getOnnxLibraryName() {
9937
10312
  if (process.platform === "darwin")
9938
10313
  return "libonnxruntime.dylib";
@@ -9965,21 +10340,21 @@ function findSystemOnnxRuntime() {
9965
10340
  const libName = getOnnxLibraryName();
9966
10341
  const searchPaths = process.platform === "darwin" ? ["/opt/homebrew/lib", "/usr/local/lib"] : process.platform === "linux" ? ["/usr/lib", "/usr/lib/x86_64-linux-gnu", "/usr/lib/aarch64-linux-gnu", "/usr/local/lib"] : [];
9967
10342
  for (const path of searchPaths) {
9968
- if (existsSync8(join8(path, libName)))
10343
+ if (existsSync9(join9(path, libName)))
9969
10344
  return path;
9970
10345
  }
9971
10346
  return null;
9972
10347
  }
9973
10348
  function findCachedOnnxRuntime(storageDir) {
9974
- const ortDir = join8(storageDir, "onnxruntime", ONNX_RUNTIME_VERSION);
9975
- return existsSync8(join8(ortDir, getOnnxLibraryName())) ? ortDir : null;
10349
+ const ortDir = join9(storageDir, "onnxruntime", ONNX_RUNTIME_VERSION);
10350
+ return existsSync9(join9(ortDir, getOnnxLibraryName())) ? ortDir : null;
9976
10351
  }
9977
10352
  function detectOrtVersion(libDir) {
9978
- if (!existsSync8(libDir))
10353
+ if (!existsSync9(libDir))
9979
10354
  return null;
9980
10355
  const libName = getOnnxLibraryName();
9981
10356
  try {
9982
- const entries = readdirSync4(libDir);
10357
+ const entries = readdirSync5(libDir);
9983
10358
  for (const entry of entries) {
9984
10359
  if (!entry.startsWith(libName))
9985
10360
  continue;
@@ -9987,8 +10362,8 @@ function detectOrtVersion(libDir) {
9987
10362
  if (match)
9988
10363
  return match[1];
9989
10364
  }
9990
- const base = join8(libDir, libName);
9991
- if (existsSync8(base)) {
10365
+ const base = join9(libDir, libName);
10366
+ if (existsSync9(base)) {
9992
10367
  try {
9993
10368
  const real = realpathSync(base);
9994
10369
  const suffix = real.match(/\.(\d+\.\d+\.\d+)$/);
@@ -10018,13 +10393,13 @@ var ONNX_RUNTIME_VERSION = "1.24.4", REQUIRED_ORT_MAJOR = 1, REQUIRED_ORT_MIN_MI
10018
10393
  var init_onnx = () => {};
10019
10394
 
10020
10395
  // src/lib/sanitize.ts
10021
- import { homedir as homedir4, userInfo } from "node:os";
10396
+ import { homedir as homedir5, userInfo } from "node:os";
10022
10397
  function escapeRegex(value) {
10023
10398
  return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
10024
10399
  }
10025
10400
  function sanitizeContent(content) {
10026
10401
  const username = userInfo().username;
10027
- const home = homedir4();
10402
+ const home = homedir5();
10028
10403
  let sanitized = content;
10029
10404
  if (home) {
10030
10405
  sanitized = sanitized.replace(new RegExp(escapeRegex(home), "g"), "~");
@@ -10053,7 +10428,7 @@ function sanitizeValue(value) {
10053
10428
  var init_sanitize = () => {};
10054
10429
 
10055
10430
  // src/lib/diagnostics.ts
10056
- import { existsSync as existsSync9, readFileSync as readFileSync4, statSync as statSync5 } from "node:fs";
10431
+ import { existsSync as existsSync10, readFileSync as readFileSync4, statSync as statSync6 } from "node:fs";
10057
10432
  async function collectDiagnostics(adapters) {
10058
10433
  const cliVersion = getSelfVersion();
10059
10434
  const binaryVersion = probeBinaryVersion(cliVersion);
@@ -10093,14 +10468,14 @@ async function diagnoseHarness(adapter) {
10093
10468
  pluginRegistered: adapter.hasPluginEntry(),
10094
10469
  configPaths,
10095
10470
  aftConfig: {
10096
- exists: existsSync9(configPaths.aftConfig),
10471
+ exists: existsSync10(configPaths.aftConfig),
10097
10472
  ...aftConfigRead.error ? { parseError: aftConfigRead.error } : {},
10098
10473
  flags: aftFlags
10099
10474
  },
10100
10475
  pluginCache: adapter.getPluginCacheInfo(),
10101
10476
  storageDir: {
10102
10477
  path: storage,
10103
- exists: existsSync9(storage),
10478
+ exists: existsSync10(storage),
10104
10479
  sizesByKey: describeStorage
10105
10480
  },
10106
10481
  onnxRuntime: {
@@ -10117,8 +10492,8 @@ async function diagnoseHarness(adapter) {
10117
10492
  },
10118
10493
  logFile: {
10119
10494
  path: logPath,
10120
- exists: existsSync9(logPath),
10121
- sizeKb: existsSync9(logPath) ? Math.round(statSync5(logPath).size / 1024) : 0
10495
+ exists: existsSync10(logPath),
10496
+ sizeKb: existsSync10(logPath) ? Math.round(statSync6(logPath).size / 1024) : 0
10122
10497
  }
10123
10498
  };
10124
10499
  }
@@ -10178,7 +10553,7 @@ function renderDiagnosticsMarkdown(report) {
10178
10553
  `);
10179
10554
  }
10180
10555
  function tailLogFile(path, lines) {
10181
- if (!existsSync9(path))
10556
+ if (!existsSync10(path))
10182
10557
  return "";
10183
10558
  try {
10184
10559
  const raw = readFileSync4(path, "utf-8");
@@ -10244,7 +10619,7 @@ __export(exports_doctor, {
10244
10619
  DOCTOR_CLEAR_TARGET_OPTIONS: () => DOCTOR_CLEAR_TARGET_OPTIONS
10245
10620
  });
10246
10621
  import { writeFileSync as writeFileSync2 } from "node:fs";
10247
- import { join as join9 } from "node:path";
10622
+ import { join as join10 } from "node:path";
10248
10623
  async function runDoctor(options) {
10249
10624
  if (options.issue) {
10250
10625
  return runIssueFlow(options.argv);
@@ -10458,7 +10833,7 @@ ${tail || "<no log output>"}
10458
10833
  `);
10459
10834
  const body = sanitizeContent(rawBody);
10460
10835
  const title = `AFT issue: ${description.slice(0, 72)}`;
10461
- const outPath = join9(process.cwd(), `aft-issue-${Date.now()}.md`);
10836
+ const outPath = join10(process.cwd(), `aft-issue-${Date.now()}.md`);
10462
10837
  writeFileSync2(outPath, `${body}
10463
10838
  `);
10464
10839
  O2.success(`Wrote sanitized issue body to ${outPath}`);
@@ -10513,6 +10888,7 @@ function printHelp() {
10513
10888
  console.log(" Commands:");
10514
10889
  console.log(" setup Interactive setup wizard");
10515
10890
  console.log(" doctor Check and fix configuration issues");
10891
+ console.log(" doctor lsp <file> Inspect LSP setup for one file");
10516
10892
  console.log(" doctor --clear Select caches to clear with an interactive prompt");
10517
10893
  console.log(" doctor --issue Collect diagnostics and open a GitHub issue");
10518
10894
  console.log("");
@@ -10524,6 +10900,7 @@ function printHelp() {
10524
10900
  console.log(" Usage:");
10525
10901
  console.log(" bunx --bun @cortexkit/aft setup");
10526
10902
  console.log(" bunx --bun @cortexkit/aft doctor");
10903
+ console.log(" bunx --bun @cortexkit/aft doctor lsp ./src/main.py");
10527
10904
  console.log(" bunx --bun @cortexkit/aft doctor --clear");
10528
10905
  console.log(" bunx --bun @cortexkit/aft doctor --issue");
10529
10906
  console.log("");
@@ -10534,6 +10911,10 @@ async function main() {
10534
10911
  return runSetup2(args);
10535
10912
  }
10536
10913
  if (command === "doctor") {
10914
+ if (args[0] === "lsp") {
10915
+ const { runLspDoctor: runLspDoctor2 } = await Promise.resolve().then(() => (init_lsp(), exports_lsp));
10916
+ return runLspDoctor2({ argv: args.slice(1) });
10917
+ }
10537
10918
  const { runDoctor: runDoctor2 } = await Promise.resolve().then(() => (init_doctor(), exports_doctor));
10538
10919
  const force = args.includes("--force");
10539
10920
  const clear = args.includes("--clear");
@@ -0,0 +1,15 @@
1
+ export interface AftRequest {
2
+ id: string;
3
+ command: string;
4
+ [key: string]: unknown;
5
+ }
6
+ export interface AftResponse {
7
+ id: string;
8
+ success: boolean;
9
+ code?: string;
10
+ message?: string;
11
+ [key: string]: unknown;
12
+ }
13
+ export declare function sendAftRequest(binaryPath: string, request: AftRequest): Promise<AftResponse>;
14
+ export declare function sendAftRequests(binaryPath: string, requests: AftRequest[]): Promise<AftResponse[]>;
15
+ //# sourceMappingURL=aft-bridge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aft-bridge.d.ts","sourceRoot":"","sources":["../../src/lib/aft-bridge.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,wBAAsB,cAAc,CAClC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,UAAU,GAClB,OAAO,CAAC,WAAW,CAAC,CAKtB;AAED,wBAAsB,eAAe,CACnC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,UAAU,EAAE,GACrB,OAAO,CAAC,WAAW,EAAE,CAAC,CAgExB"}
@@ -8,4 +8,6 @@
8
8
  * not an exception.
9
9
  */
10
10
  export declare function probeBinaryVersion(preferredVersion?: string): string | null;
11
+ export declare function platformKey(platform?: string, arch?: string): string | null;
12
+ export declare function findAftBinary(preferredVersion?: string): string | null;
11
13
  //# sourceMappingURL=binary-probe.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"binary-probe.d.ts","sourceRoot":"","sources":["../../src/lib/binary-probe.ts"],"names":[],"mappings":"AAWA;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAgC3E"}
1
+ {"version":3,"file":"binary-probe.d.ts","sourceRoot":"","sources":["../../src/lib/binary-probe.ts"],"names":[],"mappings":"AAaA;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAgC3E;AAED,wBAAgB,WAAW,CACzB,QAAQ,GAAE,MAAyB,EACnC,IAAI,GAAE,MAAqB,GAC1B,MAAM,GAAG,IAAI,CAOf;AAED,wBAAgB,aAAa,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAkCtE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/aft",
3
- "version": "0.17.0",
3
+ "version": "0.17.2",
4
4
  "type": "module",
5
5
  "description": "Unified CLI for Agent File Tools (AFT) — setup, doctor, and diagnostics across supported agent harnesses (OpenCode, Pi)",
6
6
  "license": "MIT",