@mrclrchtr/supi-lsp 0.1.0 → 1.1.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.
- package/README.md +112 -0
- package/node_modules/@mrclrchtr/supi-core/README.md +90 -0
- package/node_modules/@mrclrchtr/supi-core/package.json +26 -0
- package/node_modules/@mrclrchtr/supi-core/src/config-settings.ts +76 -0
- package/node_modules/@mrclrchtr/supi-core/src/config.ts +186 -0
- package/node_modules/@mrclrchtr/supi-core/src/context-messages.ts +119 -0
- package/node_modules/@mrclrchtr/supi-core/src/context-provider-registry.ts +36 -0
- package/node_modules/@mrclrchtr/supi-core/src/context-tag.ts +31 -0
- package/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +255 -0
- package/node_modules/@mrclrchtr/supi-core/src/index.ts +83 -0
- package/node_modules/@mrclrchtr/supi-core/src/project-roots.ts +170 -0
- package/node_modules/@mrclrchtr/supi-core/src/registry-utils.ts +54 -0
- package/node_modules/@mrclrchtr/supi-core/src/session-utils.ts +29 -0
- package/node_modules/@mrclrchtr/supi-core/src/settings-command.ts +15 -0
- package/node_modules/@mrclrchtr/supi-core/src/settings-registry.ts +41 -0
- package/node_modules/@mrclrchtr/supi-core/src/settings-ui.ts +226 -0
- package/node_modules/@mrclrchtr/supi-core/src/terminal.ts +60 -0
- package/package.json +16 -11
- package/{capabilities.ts → src/capabilities.ts} +8 -0
- package/src/client/client-refresh.ts +229 -0
- package/{client.ts → src/client/client.ts} +178 -30
- package/{transport.ts → src/client/transport.ts} +10 -6
- package/src/config.ts +143 -0
- package/src/defaults.json +82 -0
- package/src/diagnostics/diagnostic-augmentation.ts +82 -0
- package/src/diagnostics/diagnostic-display.ts +68 -0
- package/{diagnostic-summary.ts → src/diagnostics/diagnostic-summary.ts} +11 -7
- package/{diagnostics.ts → src/diagnostics/diagnostics.ts} +9 -4
- package/src/diagnostics/stale-diagnostics.ts +47 -0
- package/src/diagnostics/suppression-diagnostics.ts +58 -0
- package/src/format.ts +359 -0
- package/src/guidance.ts +163 -0
- package/src/index.ts +17 -0
- package/src/lsp-state.ts +82 -0
- package/src/lsp.ts +481 -0
- package/src/manager/manager-client-state.ts +34 -0
- package/src/manager/manager-diagnostics.ts +139 -0
- package/src/manager/manager-helpers.ts +39 -0
- package/src/manager/manager-project-info.ts +46 -0
- package/src/manager/manager-stale-resync.ts +47 -0
- package/src/manager/manager-types.ts +39 -0
- package/src/manager/manager-workspace-recovery.ts +83 -0
- package/src/manager/manager-workspace-symbol.ts +18 -0
- package/src/manager/manager.ts +550 -0
- package/src/overrides.ts +173 -0
- package/src/pattern-matcher.ts +197 -0
- package/src/renderer.ts +120 -0
- package/src/scanner.ts +153 -0
- package/src/search-fallback.ts +98 -0
- package/src/service-registry.ts +153 -0
- package/src/settings-registration.ts +292 -0
- package/{summary.ts → src/summary.ts} +44 -9
- package/src/tool-actions.ts +430 -0
- package/src/tree-persist.ts +48 -0
- package/src/tsconfig-scope.ts +156 -0
- package/{types.ts → src/types.ts} +123 -0
- package/src/ui.ts +358 -0
- package/{utils.ts → src/utils.ts} +8 -25
- package/src/workspace-sentinels.ts +114 -0
- package/bash-guard.ts +0 -58
- package/config.ts +0 -99
- package/defaults.json +0 -40
- package/format.ts +0 -190
- package/guidance.ts +0 -140
- package/lsp.ts +0 -375
- package/manager.ts +0 -396
- package/overrides.ts +0 -95
- package/recent-paths.ts +0 -126
- package/runtime-state.ts +0 -113
- package/tool-actions.ts +0 -211
- package/tsconfig.json +0 -5
- package/ui.ts +0 -303
package/src/guidance.ts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import { splitSuppressionDiagnostics } from "./diagnostics/suppression-diagnostics.ts";
|
|
3
|
+
import type { OutstandingDiagnosticSummaryEntry } from "./manager/manager-types.ts";
|
|
4
|
+
import type { Diagnostic, ProjectServerInfo } from "./types.ts";
|
|
5
|
+
|
|
6
|
+
export const lspPromptSnippet =
|
|
7
|
+
"Use semantic code intelligence for hover, definitions, references, symbols, rename planning, code actions, and diagnostics in supported languages.";
|
|
8
|
+
|
|
9
|
+
export const lspPromptGuidelines = [
|
|
10
|
+
"Prefer the lsp tool over bash text search for supported source files when the task is semantic code navigation or diagnostics.",
|
|
11
|
+
"Use lsp for hover, definitions, references, document symbols, rename planning, code actions, and diagnostics before falling back to grep-style shell search.",
|
|
12
|
+
"Fall back to bash/read when LSP is unavailable, the file type is unsupported, or the task is plain-text search across docs, config files, or string literals.",
|
|
13
|
+
"Diagnostics are automatically delivered: inline after every write/edit tool result, and as context before each agent turn. You do not need to call the lsp tool to check them — they are already in your context.",
|
|
14
|
+
"When delivered diagnostics show errors, decide: (a) expected temporary state from a planned multi-step change — continue your sequence, then verify at the end; (b) unexpected 'Cannot find module', unresolved imports, or type mismatches — stop and fix the root cause before editing more files.",
|
|
15
|
+
"When the SAME error pattern appears across MULTIPLE files after you changed imports, dependencies, or shared types, it is a systemic root-cause issue (missing install, broken import path, wrong dependency version). Do not patch each file individually — find and fix the root cause first.",
|
|
16
|
+
"When diagnostics look stale after package.json, lockfile, tsconfig, or generated-type changes, use lsp recover before editing more files.",
|
|
17
|
+
"After changing package.json dependencies, imports, or peer dependencies, run the package manager install command (e.g., pnpm install) before concluding that module resolution errors are real code bugs.",
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Build per-project `promptGuidelines` for the `lsp` tool registration.
|
|
22
|
+
* These guidelines are part of pi's stable system prompt after session-start
|
|
23
|
+
* tool registration, avoiding per-turn `before_agent_start` prompt overrides.
|
|
24
|
+
*/
|
|
25
|
+
export function buildProjectGuidelines(servers: ProjectServerInfo[], cwd: string): string[] {
|
|
26
|
+
const dynamic = servers.map((server) => {
|
|
27
|
+
const root = displayRoot(server.root, cwd);
|
|
28
|
+
const fileTypes = server.fileTypes.map((entry) => `.${entry}`).join(", ");
|
|
29
|
+
const actions = server.supportedActions.join(", ");
|
|
30
|
+
const status = server.status === "running" ? "active" : "unavailable";
|
|
31
|
+
const actionText = actions.length > 0 ? ` | actions: ${actions}` : "";
|
|
32
|
+
return `LSP ${status}: ${server.name} | root: ${root} | files: ${fileTypes}${actionText}`;
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return [
|
|
36
|
+
...lspPromptGuidelines.slice(0, 2),
|
|
37
|
+
"Use lsp before grep/rg/find for understanding code, finding usages, diagnostics, symbol lookup, and refactors in supported languages.",
|
|
38
|
+
...dynamic,
|
|
39
|
+
"Use lsp actions by task: hover/definition/references/symbols for understanding code, references/workspace_symbol/search for usages, diagnostics/hover/code_actions for issues, and rename/code_actions for refactors.",
|
|
40
|
+
...lspPromptGuidelines.slice(2),
|
|
41
|
+
].filter(Boolean);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const MAX_DETAILED_DIAGNOSTICS = 5;
|
|
45
|
+
const MAX_DETAIL_LINES_PER_FILE = 3;
|
|
46
|
+
|
|
47
|
+
interface DetailedDiagnostics {
|
|
48
|
+
file: string;
|
|
49
|
+
diagnostics: Diagnostic[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function formatDiagnosticsContext(
|
|
53
|
+
diagnostics: OutstandingDiagnosticSummaryEntry[],
|
|
54
|
+
maxFiles: number = 3,
|
|
55
|
+
detailed?: DetailedDiagnostics[],
|
|
56
|
+
staleWarning?: string | null,
|
|
57
|
+
): string | null {
|
|
58
|
+
if (diagnostics.length === 0) return null;
|
|
59
|
+
|
|
60
|
+
const totalDiags = diagnostics.reduce((sum, d) => sum + d.total, 0);
|
|
61
|
+
const detailMap = buildDetailMap(diagnostics, totalDiags, detailed);
|
|
62
|
+
|
|
63
|
+
const lines: string[] = [];
|
|
64
|
+
if (staleWarning) lines.push(staleWarning);
|
|
65
|
+
const visible = diagnostics.slice(0, maxFiles);
|
|
66
|
+
|
|
67
|
+
for (const entry of visible) {
|
|
68
|
+
lines.push(`- ${entry.file}: ${formatCounts(entry)}`);
|
|
69
|
+
appendDetailLines(lines, detailMap?.get(entry.file));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const remaining = diagnostics.length - visible.length;
|
|
73
|
+
if (remaining > 0) {
|
|
74
|
+
lines.push(`- +${remaining} more file${remaining === 1 ? "" : "s"}`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
appendSuppressionCleanup(
|
|
78
|
+
lines,
|
|
79
|
+
visible.map((entry) => entry.file),
|
|
80
|
+
detailMap,
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
return [
|
|
84
|
+
'<extension-context source="supi-lsp">',
|
|
85
|
+
"Outstanding diagnostics — fix these before proceeding:",
|
|
86
|
+
...lines,
|
|
87
|
+
"</extension-context>",
|
|
88
|
+
].join("\n");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function buildDetailMap(
|
|
92
|
+
_diagnostics: OutstandingDiagnosticSummaryEntry[],
|
|
93
|
+
totalDiags: number,
|
|
94
|
+
detailed?: DetailedDiagnostics[],
|
|
95
|
+
): Map<string, Diagnostic[]> | null {
|
|
96
|
+
if (totalDiags > MAX_DETAILED_DIAGNOSTICS || !detailed || detailed.length === 0) return null;
|
|
97
|
+
return new Map(detailed.map((d) => [d.file, d.diagnostics]));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function appendDetailLines(lines: string[], details?: Diagnostic[]): void {
|
|
101
|
+
if (!details) return;
|
|
102
|
+
for (const d of details.slice(0, MAX_DETAIL_LINES_PER_FILE)) {
|
|
103
|
+
const line = d.range.start.line + 1;
|
|
104
|
+
const char = d.range.start.character + 1;
|
|
105
|
+
const source = d.source ? ` ${d.source}` : "";
|
|
106
|
+
lines.push(` L${line} C${char}${source}: ${d.message}`);
|
|
107
|
+
}
|
|
108
|
+
if (details.length > MAX_DETAIL_LINES_PER_FILE) {
|
|
109
|
+
const extra = details.length - MAX_DETAIL_LINES_PER_FILE;
|
|
110
|
+
lines.push(` +${extra} more`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function appendSuppressionCleanup(
|
|
115
|
+
lines: string[],
|
|
116
|
+
visibleFiles: string[],
|
|
117
|
+
detailMap: Map<string, Diagnostic[]> | null,
|
|
118
|
+
): void {
|
|
119
|
+
if (!detailMap) return;
|
|
120
|
+
|
|
121
|
+
const suppressionLines: string[] = [];
|
|
122
|
+
for (const file of visibleFiles) {
|
|
123
|
+
const diagnostics = detailMap.get(file);
|
|
124
|
+
if (!diagnostics) continue;
|
|
125
|
+
|
|
126
|
+
const { suppressions } = splitSuppressionDiagnostics(diagnostics, 1);
|
|
127
|
+
if (suppressions.length === 0) continue;
|
|
128
|
+
|
|
129
|
+
suppressionLines.push(`- ${file}`);
|
|
130
|
+
appendDetailLines(suppressionLines, suppressions);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (suppressionLines.length === 0) return;
|
|
134
|
+
lines.push("", "Stale suppression comments — clean these up:", ...suppressionLines);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function diagnosticsContextFingerprint(content: string | null): string | null {
|
|
138
|
+
return content;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// reorderDiagnosticContextMessages, getContextToken, and findLastUserMessageIndex
|
|
142
|
+
// have been extracted to supi-core/context-messages.ts.
|
|
143
|
+
// Use pruneAndReorderContextMessages(messages, "lsp-context", activeToken) instead.
|
|
144
|
+
|
|
145
|
+
function formatCounts(entry: OutstandingDiagnosticSummaryEntry): string {
|
|
146
|
+
const counts: string[] = [];
|
|
147
|
+
if (entry.errors > 0) counts.push(pluralize(entry.errors, "error"));
|
|
148
|
+
if (entry.warnings > 0) counts.push(pluralize(entry.warnings, "warning"));
|
|
149
|
+
if (entry.information > 0) counts.push(pluralize(entry.information, "info"));
|
|
150
|
+
if (entry.hints > 0) counts.push(pluralize(entry.hints, "hint"));
|
|
151
|
+
return counts.join(", ");
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function displayRoot(root: string, cwd: string): string {
|
|
155
|
+
const relative = path.relative(cwd, root);
|
|
156
|
+
if (relative === "") return ".";
|
|
157
|
+
if (relative.startsWith(`..${path.sep}`) || relative === "..") return root;
|
|
158
|
+
return relative.replaceAll(path.sep, "/");
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function pluralize(count: number, word: string): string {
|
|
162
|
+
return `${count} ${word}${count === 1 ? "" : "s"}`;
|
|
163
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Public library entrypoint for @mrclrchtr/supi-lsp.
|
|
2
|
+
// Import from the package root to reuse session-scoped LSP services
|
|
3
|
+
// without reaching into private implementation files.
|
|
4
|
+
|
|
5
|
+
export type { SessionLspServiceState } from "./service-registry.ts";
|
|
6
|
+
export { getSessionLspService, SessionLspService } from "./service-registry.ts";
|
|
7
|
+
export type {
|
|
8
|
+
Diagnostic,
|
|
9
|
+
DocumentSymbol,
|
|
10
|
+
Hover,
|
|
11
|
+
Location,
|
|
12
|
+
LocationLink,
|
|
13
|
+
Position,
|
|
14
|
+
ProjectServerInfo,
|
|
15
|
+
SymbolInformation,
|
|
16
|
+
WorkspaceSymbol,
|
|
17
|
+
} from "./types.ts";
|
package/src/lsp-state.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// LSP extension runtime state and tool management helpers.
|
|
2
|
+
// Extracted from lsp.ts to keep file sizes within Biome limits.
|
|
3
|
+
|
|
4
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
5
|
+
import type { LspManager } from "./manager/manager.ts";
|
|
6
|
+
import { introspectCapabilities } from "./scanner.ts";
|
|
7
|
+
import { clearSessionLspService } from "./service-registry.ts";
|
|
8
|
+
import type { DetectedProjectServer, ProjectServerInfo } from "./types.ts";
|
|
9
|
+
import type { LspInspectorState } from "./ui.ts";
|
|
10
|
+
|
|
11
|
+
export interface LspRuntimeState {
|
|
12
|
+
manager: LspManager | null;
|
|
13
|
+
inlineSeverity: number;
|
|
14
|
+
inspector: LspInspectorState;
|
|
15
|
+
detectedServers: DetectedProjectServer[];
|
|
16
|
+
projectServers: ProjectServerInfo[];
|
|
17
|
+
lastDiagnosticsFingerprint: string | null;
|
|
18
|
+
currentContextToken: string | null;
|
|
19
|
+
contextCounter: number;
|
|
20
|
+
lspActive: boolean;
|
|
21
|
+
sentinelSnapshot: Map<string, number>;
|
|
22
|
+
staleSuspected: boolean;
|
|
23
|
+
lastWorkspaceChangeAt: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function createRuntimeState(): LspRuntimeState {
|
|
27
|
+
return {
|
|
28
|
+
manager: null,
|
|
29
|
+
inlineSeverity: 1,
|
|
30
|
+
inspector: { handle: null, close: null },
|
|
31
|
+
detectedServers: [],
|
|
32
|
+
projectServers: [],
|
|
33
|
+
lastDiagnosticsFingerprint: null,
|
|
34
|
+
currentContextToken: null,
|
|
35
|
+
contextCounter: 0,
|
|
36
|
+
lspActive: false,
|
|
37
|
+
sentinelSnapshot: new Map(),
|
|
38
|
+
staleSuspected: false,
|
|
39
|
+
lastWorkspaceChangeAt: 0,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function refreshProjectServers(state: LspRuntimeState): void {
|
|
44
|
+
if (!state.manager) {
|
|
45
|
+
state.projectServers = [];
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
state.projectServers = introspectCapabilities(state.manager, state.detectedServers);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function isLspAwareTool(toolName: string): boolean {
|
|
52
|
+
return toolName === "lsp" || toolName === "read" || toolName === "write" || toolName === "edit";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function disableLspState(pi: ExtensionAPI, state: LspRuntimeState): void {
|
|
56
|
+
if (state.manager) {
|
|
57
|
+
clearSessionLspService(state.manager.getCwd());
|
|
58
|
+
}
|
|
59
|
+
state.inspector.close?.();
|
|
60
|
+
state.manager = null;
|
|
61
|
+
state.detectedServers = [];
|
|
62
|
+
state.projectServers = [];
|
|
63
|
+
state.lastDiagnosticsFingerprint = null;
|
|
64
|
+
state.currentContextToken = null;
|
|
65
|
+
state.staleSuspected = false;
|
|
66
|
+
state.lastWorkspaceChangeAt = 0;
|
|
67
|
+
state.sentinelSnapshot = new Map();
|
|
68
|
+
state.lspActive = false;
|
|
69
|
+
removeLspTool(pi);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function removeLspTool(pi: ExtensionAPI): void {
|
|
73
|
+
const activeTools = pi.getActiveTools();
|
|
74
|
+
if (activeTools.includes("lsp"))
|
|
75
|
+
pi.setActiveTools(activeTools.filter((t: string) => t !== "lsp"));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function ensureLspToolActive(pi: ExtensionAPI): void {
|
|
79
|
+
const activeTools = pi.getActiveTools();
|
|
80
|
+
if (activeTools.includes("lsp")) return;
|
|
81
|
+
pi.setActiveTools([...activeTools, "lsp"]);
|
|
82
|
+
}
|