@amaranthic/hernex 0.6.1 → 0.7.0
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/CHANGELOG.md +46 -0
- package/dist/engine/runTurn.d.ts.map +1 -1
- package/dist/engine/runTurn.js +2 -1
- package/dist/engine/runTurn.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/tools/LspTool.d.ts +174 -0
- package/dist/tools/LspTool.d.ts.map +1 -0
- package/dist/tools/LspTool.js +195 -0
- package/dist/tools/LspTool.js.map +1 -0
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +2 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/internal/lsp.d.ts +175 -0
- package/dist/tools/internal/lsp.d.ts.map +1 -0
- package/dist/tools/internal/lsp.js +1202 -0
- package/dist/tools/internal/lsp.js.map +1 -0
- package/dist/tools/prompts.d.ts +4 -0
- package/dist/tools/prompts.d.ts.map +1 -1
- package/dist/tools/prompts.js +23 -0
- package/dist/tools/prompts.js.map +1 -1
- package/package.json +1 -1
package/dist/tools/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAML,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAML,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,0BAA0B,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,OAAO,EAML,gBAAgB,EAChB,sBAAsB,EACtB,aAAa,GACd,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview On-demand Language Server Protocol engine for Hernex.
|
|
3
|
+
*
|
|
4
|
+
* Implements the LSP JSON-RPC wire protocol from scratch over stdio — no
|
|
5
|
+
* external vscode or jsonrpc packages. Each call to {@link runLspRequest}
|
|
6
|
+
* spawns the configured language server binary, executes exactly one
|
|
7
|
+
* operation (initialize → didOpen → request → shutdown → exit), then exits
|
|
8
|
+
* cleanly. Zero lingering processes.
|
|
9
|
+
*
|
|
10
|
+
* Wire format (per LSP spec §3.1):
|
|
11
|
+
* `Content-Length: <byteLen>\r\n\r\n<utf-8 json body>`
|
|
12
|
+
*
|
|
13
|
+
* @packageDocumentation
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Default per-request timeout in milliseconds.
|
|
17
|
+
*/
|
|
18
|
+
export declare const DEFAULT_LSP_TIMEOUT_MS = 5000;
|
|
19
|
+
/**
|
|
20
|
+
* Configuration for a single LSP server binary.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const tsConfig: LspServerConfig = {
|
|
25
|
+
* command: "typescript-language-server",
|
|
26
|
+
* args: ["--stdio"],
|
|
27
|
+
* extensions: [".ts", ".tsx", ".js", ".jsx"],
|
|
28
|
+
* };
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export interface LspServerConfig {
|
|
32
|
+
/**
|
|
33
|
+
* The executable name or absolute path of the LSP server binary.
|
|
34
|
+
* Must be resolvable on the system `PATH` or be an absolute path.
|
|
35
|
+
*/
|
|
36
|
+
readonly command: string;
|
|
37
|
+
/**
|
|
38
|
+
* Optional command-line arguments to pass to the binary.
|
|
39
|
+
* Most servers require `["--stdio"]` to enable stdio transport.
|
|
40
|
+
*/
|
|
41
|
+
readonly args?: readonly string[] | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* File extensions this server handles (e.g. `[".ts", ".tsx"]`).
|
|
44
|
+
* Each extension must start with a dot. Mandatory — no default.
|
|
45
|
+
*/
|
|
46
|
+
readonly extensions: readonly string[];
|
|
47
|
+
/**
|
|
48
|
+
* Optional extra environment variables to merge into the server's process
|
|
49
|
+
* environment. Merged on top of the sanitized safe environment.
|
|
50
|
+
*/
|
|
51
|
+
readonly env?: Readonly<Record<string, string>> | undefined;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A flat map of server name → server configuration.
|
|
55
|
+
* When multiple entries claim the same extension, the first one wins
|
|
56
|
+
* (iteration order of the object).
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const config: LspConfig = {
|
|
61
|
+
* typescript: { command: "typescript-language-server", args: ["--stdio"], extensions: [".ts"] },
|
|
62
|
+
* python: { command: "pyright-langserver", args: ["--stdio"], extensions: [".py"] },
|
|
63
|
+
* };
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export type LspConfig = Readonly<Record<string, LspServerConfig>>;
|
|
67
|
+
/**
|
|
68
|
+
* The seven LSP operations the model can invoke via {@link LspTool}.
|
|
69
|
+
*/
|
|
70
|
+
export type LspOperation = "hover" | "goToDefinition" | "goToImplementation" | "findReferences" | "documentSymbol" | "workspaceSymbol" | "diagnostics";
|
|
71
|
+
/**
|
|
72
|
+
* Options for a single on-demand LSP request.
|
|
73
|
+
*/
|
|
74
|
+
export interface LspRequestOptions {
|
|
75
|
+
/**
|
|
76
|
+
* Absolute or workspace-relative path of the file to query.
|
|
77
|
+
* Resolved and security-checked before the server is spawned.
|
|
78
|
+
*/
|
|
79
|
+
readonly filePath: string;
|
|
80
|
+
/** The LSP operation to perform. */
|
|
81
|
+
readonly operation: LspOperation;
|
|
82
|
+
/**
|
|
83
|
+
* 1-based line number. Converted to 0-based before writing LSP frames.
|
|
84
|
+
* Ignored for `documentSymbol`, `workspaceSymbol`, and `diagnostics`.
|
|
85
|
+
*/
|
|
86
|
+
readonly line: number;
|
|
87
|
+
/**
|
|
88
|
+
* 1-based character offset. Converted to 0-based before writing LSP frames.
|
|
89
|
+
* Ignored for `documentSymbol`, `workspaceSymbol`, and `diagnostics`.
|
|
90
|
+
*/
|
|
91
|
+
readonly character: number;
|
|
92
|
+
/**
|
|
93
|
+
* Search query string; required only for `workspaceSymbol`.
|
|
94
|
+
* Silently treated as `""` for other operations.
|
|
95
|
+
*/
|
|
96
|
+
readonly query?: string | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Absolute path of the workspace root used for path containment checks
|
|
99
|
+
* and for constructing the `rootUri` passed to the LSP server.
|
|
100
|
+
*/
|
|
101
|
+
readonly workingDirectory: string;
|
|
102
|
+
/**
|
|
103
|
+
* Optional config override. When omitted, {@link defaultLspConfig} is used.
|
|
104
|
+
*/
|
|
105
|
+
readonly config?: LspConfig | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* Per-request timeout in milliseconds. Defaults to {@link DEFAULT_LSP_TIMEOUT_MS}.
|
|
108
|
+
*/
|
|
109
|
+
readonly timeoutMs?: number | undefined;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Discriminated result returned by {@link runLspRequest}.
|
|
113
|
+
*/
|
|
114
|
+
export type LspResult = {
|
|
115
|
+
readonly ok: true;
|
|
116
|
+
readonly markdown: string;
|
|
117
|
+
} | {
|
|
118
|
+
readonly ok: false;
|
|
119
|
+
readonly error: string;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Built-in LSP server configurations covering the ten most common languages.
|
|
123
|
+
*
|
|
124
|
+
* Used when {@link LspRequestOptions.config} is not provided.
|
|
125
|
+
* All binaries must be installed separately on the host system.
|
|
126
|
+
*
|
|
127
|
+
* | Key | Binary | Extensions |
|
|
128
|
+
* |---------------|-----------------------------------|-------------------------------------------|
|
|
129
|
+
* | typescript | typescript-language-server | .ts .tsx .js .jsx .mjs .cjs |
|
|
130
|
+
* | python | pyright-langserver | .py .pyi |
|
|
131
|
+
* | rust | rust-analyzer | .rs |
|
|
132
|
+
* | go | gopls | .go |
|
|
133
|
+
* | clangd | clangd | .c .cpp .cc .cxx .h .hpp |
|
|
134
|
+
* | json | vscode-json-language-server | .json .jsonc |
|
|
135
|
+
* | html | vscode-html-language-server | .html .htm |
|
|
136
|
+
* | css | vscode-css-language-server | .css .scss .less |
|
|
137
|
+
* | yaml | yaml-language-server | .yaml .yml |
|
|
138
|
+
* | shell | bash-language-server | .sh .bash |
|
|
139
|
+
*/
|
|
140
|
+
export declare const defaultLspConfig: LspConfig;
|
|
141
|
+
/**
|
|
142
|
+
* Executes a single on-demand LSP operation against the appropriate language
|
|
143
|
+
* server for the given file.
|
|
144
|
+
*
|
|
145
|
+
* **Lifecycle per call:**
|
|
146
|
+
* 1. Validate inputs (path guard, file size, binary presence).
|
|
147
|
+
* 2. Spawn the LSP server with sanitized stdio.
|
|
148
|
+
* 3. Await the `'spawn'` event before writing any frames.
|
|
149
|
+
* 4. Perform the LSP handshake: `initialize` → `initialized`.
|
|
150
|
+
* 5. Send `textDocument/didOpen`.
|
|
151
|
+
* 6. Dispatch the requested operation (with retry on `-32801`).
|
|
152
|
+
* 7. Teardown: `shutdown` → `exit` → drain → SIGKILL if needed.
|
|
153
|
+
* 8. Return a `{ ok: true, markdown }` or `{ ok: false, error }` result.
|
|
154
|
+
*
|
|
155
|
+
* @param options - Request parameters; see {@link LspRequestOptions}.
|
|
156
|
+
* @returns A promise resolving to an {@link LspResult}.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const result = await runLspRequest({
|
|
161
|
+
* filePath: "src/index.ts",
|
|
162
|
+
* operation: "hover",
|
|
163
|
+
* line: 12,
|
|
164
|
+
* character: 8,
|
|
165
|
+
* workingDirectory: "/home/user/myproject",
|
|
166
|
+
* });
|
|
167
|
+
* if (result.ok) {
|
|
168
|
+
* console.log(result.markdown);
|
|
169
|
+
* } else {
|
|
170
|
+
* console.error(result.error);
|
|
171
|
+
* }
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
export declare function runLspRequest(options: LspRequestOptions): Promise<LspResult>;
|
|
175
|
+
//# sourceMappingURL=lsp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lsp.d.ts","sourceRoot":"","sources":["../../../src/tools/internal/lsp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAkBH;;GAEG;AACH,eAAO,MAAM,sBAAsB,OAAQ,CAAC;AAoH5C;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IAE9C;;;OAGG;I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