@floydous/pi-agent-kernel 0.4.3 → 0.6.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/AGENT_KERNEL_SYS_PROMPT.md +15 -12
- package/CHANGELOG.md +87 -0
- package/README.md +6 -54
- package/config.example.toml +1 -8
- package/docs/README.md +1 -2
- package/docs/architecture.md +2 -3
- package/docs/configuration.md +11 -10
- package/docs/editing-and-verification.md +21 -8
- package/docs/podman-linux-checks.md +24 -0
- package/docs/release-discipline.md +10 -0
- package/docs/retrieval.md +21 -23
- package/docs/testing.md +3 -3
- package/grammars/tree-sitter-html.wasm +0 -0
- package/package.json +5 -3
- package/src/config/agent_kernel_command.ts +60 -625
- package/src/config/kernel_config.ts +53 -69
- package/src/config/toml.ts +6 -1
- package/src/editing/auto_heal.ts +1 -1
- package/src/editing/patch.ts +75 -37
- package/src/editing/post_edit_verification.ts +20 -14
- package/src/editing/smart_anchor.ts +9 -6
- package/src/editing/syntax-verify.ts +79 -222
- package/src/index.ts +36 -453
- package/src/retrieval/html_chunker.ts +526 -0
- package/src/retrieval/search_bm25.ts +39 -28
- package/src/retrieval/search_chunker.ts +69 -7
- package/src/retrieval/search_config.ts +21 -40
- package/src/retrieval/search_embedder.ts +14 -31
- package/src/retrieval/search_index.ts +338 -129
- package/src/retrieval/search_modal.ts +1208 -222
- package/src/retrieval/{repomap.ts → tag_extractor.ts} +6 -293
- package/src/retrieval/tree_sitter_engine.ts +171 -36
- package/src/retrieval/workspace_walker.ts +78 -2
- package/src/safety/atomic_write.ts +1 -1
- package/src/safety/epistemic_guard.ts +105 -31
- package/src/safety/host_environment.ts +180 -0
- package/src/safety/output_clamper.ts +97 -27
- package/src/tools/code_search_output.ts +11 -2
- package/src/tools/code_search_tool.ts +25 -13
- package/src/tools/context.ts +11 -10
- package/src/tools/edit_tool.ts +243 -154
- package/src/tools/read_tool.ts +285 -214
- package/src/tools/stream_reader.ts +206 -0
- package/src/ui/footer.ts +7 -7
- package/docs/lsp.md +0 -31
- package/src/lsp/adapters/base.ts +0 -42
- package/src/lsp/adapters/index.ts +0 -21
- package/src/lsp/adapters/python.ts +0 -37
- package/src/lsp/adapters/rust.ts +0 -35
- package/src/lsp/adapters/typescript.ts +0 -40
- package/src/lsp/index.ts +0 -13
- package/src/lsp/lsp_client.ts +0 -765
- package/src/lsp/lsp_detector.ts +0 -52
- package/src/lsp/lsp_formatter.ts +0 -323
- package/src/lsp/lsp_installer.ts +0 -320
- package/src/lsp/lsp_manager.ts +0 -202
- package/src/lsp/lsp_modal.ts +0 -675
- package/src/lsp/lsp_registry.ts +0 -600
- package/src/lsp/lsp_types.ts +0 -143
- package/src/retrieval/ast_search.ts +0 -999
- package/src/retrieval/symbol_reader.ts +0 -228
- package/src/tools/ast_search_formatter.ts +0 -161
- package/src/tools/ast_search_tool.ts +0 -146
- package/src/tools/lsp_tool.ts +0 -794
- package/src/tools/repo_map_tool.ts +0 -56
package/src/lsp/lsp_manager.ts
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
import * as path from "node:path";
|
|
2
|
-
import { StdioLspClient } from "./lsp_client";
|
|
3
|
-
import { resolveLspServer } from "./lsp_registry";
|
|
4
|
-
import { detectLanguageFromPath, findWorkspaceRoot } from "./lsp_detector";
|
|
5
|
-
import { loadKernelConfig } from "../config";
|
|
6
|
-
|
|
7
|
-
const DEFAULT_IDLE_TIMEOUT_MS = 5 * 60 * 1000; // 5 minutes
|
|
8
|
-
|
|
9
|
-
export class LspManager {
|
|
10
|
-
private static instance: LspManager | null = null;
|
|
11
|
-
private clients = new Map<string, StdioLspClient>();
|
|
12
|
-
private inFlightStarts = new Map<string, Promise<StdioLspClient | null>>();
|
|
13
|
-
private reaperTimer: NodeJS.Timeout | null = null;
|
|
14
|
-
|
|
15
|
-
public static getInstance(): LspManager {
|
|
16
|
-
if (!LspManager.instance) {
|
|
17
|
-
LspManager.instance = new LspManager();
|
|
18
|
-
}
|
|
19
|
-
return LspManager.instance;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
constructor() {
|
|
23
|
-
this.startReaper();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Start periodic reaper to clean up idle LSP servers (every 60s)
|
|
28
|
-
*/
|
|
29
|
-
private startReaper(): void {
|
|
30
|
-
if (this.reaperTimer) return;
|
|
31
|
-
this.reaperTimer = setInterval(() => {
|
|
32
|
-
this.reapIdleClients(loadKernelConfig().lsp.idle_timeout_ms);
|
|
33
|
-
}, 60 * 1000);
|
|
34
|
-
if (this.reaperTimer.unref) {
|
|
35
|
-
this.reaperTimer.unref();
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Stop reaper timer
|
|
41
|
-
*/
|
|
42
|
-
public stopReaper(): void {
|
|
43
|
-
if (this.reaperTimer) {
|
|
44
|
-
clearInterval(this.reaperTimer);
|
|
45
|
-
this.reaperTimer = null;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Reap clients that have been idle past DEFAULT_IDLE_TIMEOUT_MS
|
|
51
|
-
*/
|
|
52
|
-
public async reapIdleClients(
|
|
53
|
-
idleTimeoutMs = DEFAULT_IDLE_TIMEOUT_MS,
|
|
54
|
-
): Promise<void> {
|
|
55
|
-
const now = Date.now();
|
|
56
|
-
for (const [id, client] of this.clients.entries()) {
|
|
57
|
-
if (now - client.getLastActivity() > idleTimeoutMs) {
|
|
58
|
-
await client.stop();
|
|
59
|
-
this.clients.delete(id);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Return a ready client without spawning a language server.
|
|
66
|
-
* Used by bounded verification paths where startup latency is undesirable.
|
|
67
|
-
*/
|
|
68
|
-
public getReadyClientForFile(
|
|
69
|
-
filePath: string,
|
|
70
|
-
cwd: string,
|
|
71
|
-
): StdioLspClient | null {
|
|
72
|
-
const absPath = path.isAbsolute(filePath)
|
|
73
|
-
? filePath
|
|
74
|
-
: path.resolve(cwd, filePath);
|
|
75
|
-
const langKey = detectLanguageFromPath(absPath);
|
|
76
|
-
if (!langKey) return null;
|
|
77
|
-
|
|
78
|
-
const rootDir = findWorkspaceRoot(path.dirname(absPath), langKey);
|
|
79
|
-
const client = this.clients.get(`${langKey}:${rootDir}`);
|
|
80
|
-
if (!client || client.getState() !== "ready") return null;
|
|
81
|
-
client.touch();
|
|
82
|
-
return client;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Get or spawn an active LSP client for a target file
|
|
87
|
-
*/
|
|
88
|
-
public async getClientForFile(
|
|
89
|
-
filePath: string,
|
|
90
|
-
cwd: string,
|
|
91
|
-
): Promise<StdioLspClient | null> {
|
|
92
|
-
const absPath = path.isAbsolute(filePath)
|
|
93
|
-
? filePath
|
|
94
|
-
: path.resolve(cwd, filePath);
|
|
95
|
-
const langKey = detectLanguageFromPath(absPath);
|
|
96
|
-
if (!langKey) return null;
|
|
97
|
-
|
|
98
|
-
const rootDir = findWorkspaceRoot(path.dirname(absPath), langKey);
|
|
99
|
-
const clientId = `${langKey}:${rootDir}`;
|
|
100
|
-
|
|
101
|
-
const existing = this.clients.get(clientId);
|
|
102
|
-
if (existing) {
|
|
103
|
-
if (existing.getState() === "ready") {
|
|
104
|
-
existing.touch();
|
|
105
|
-
return existing;
|
|
106
|
-
}
|
|
107
|
-
if (existing.getState() === "starting") {
|
|
108
|
-
const inFlight = this.inFlightStarts.get(clientId);
|
|
109
|
-
if (inFlight) return inFlight;
|
|
110
|
-
}
|
|
111
|
-
// If client is in error or stopped state, clean it up before recreating
|
|
112
|
-
await existing.stop().catch(() => {});
|
|
113
|
-
this.clients.delete(clientId);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const inFlight = this.inFlightStarts.get(clientId);
|
|
117
|
-
if (inFlight) return inFlight;
|
|
118
|
-
|
|
119
|
-
// Resolve installed executable
|
|
120
|
-
const resolved = resolveLspServer(langKey, [], [rootDir]);
|
|
121
|
-
if (!resolved) return null;
|
|
122
|
-
|
|
123
|
-
const client = new StdioLspClient(clientId, {
|
|
124
|
-
command: resolved.binPath,
|
|
125
|
-
args: resolved.args,
|
|
126
|
-
cwd: rootDir,
|
|
127
|
-
languageId: resolved.languageId,
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
const startPromise = (async () => {
|
|
131
|
-
try {
|
|
132
|
-
const started = await client.start();
|
|
133
|
-
if (started) {
|
|
134
|
-
this.clients.set(clientId, client);
|
|
135
|
-
return client;
|
|
136
|
-
}
|
|
137
|
-
return null;
|
|
138
|
-
} finally {
|
|
139
|
-
this.inFlightStarts.delete(clientId);
|
|
140
|
-
}
|
|
141
|
-
})();
|
|
142
|
-
|
|
143
|
-
this.inFlightStarts.set(clientId, startPromise);
|
|
144
|
-
return startPromise;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Get all active clients status
|
|
149
|
-
*/
|
|
150
|
-
public getStatus(): Array<{
|
|
151
|
-
id: string;
|
|
152
|
-
languageId: string;
|
|
153
|
-
rootDir: string;
|
|
154
|
-
state: string;
|
|
155
|
-
idleSeconds: number;
|
|
156
|
-
}> {
|
|
157
|
-
const now = Date.now();
|
|
158
|
-
const list: Array<{
|
|
159
|
-
id: string;
|
|
160
|
-
languageId: string;
|
|
161
|
-
rootDir: string;
|
|
162
|
-
state: string;
|
|
163
|
-
idleSeconds: number;
|
|
164
|
-
}> = [];
|
|
165
|
-
for (const [id, client] of this.clients.entries()) {
|
|
166
|
-
list.push({
|
|
167
|
-
id,
|
|
168
|
-
languageId: client.languageId,
|
|
169
|
-
rootDir: client.rootDir,
|
|
170
|
-
state: client.getState(),
|
|
171
|
-
idleSeconds: Math.floor((now - client.getLastActivity()) / 1000),
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
return list;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Stop all active servers for a specific language
|
|
179
|
-
*/
|
|
180
|
-
public async stopLanguage(languageOrKey: string): Promise<void> {
|
|
181
|
-
const norm = languageOrKey.toLowerCase();
|
|
182
|
-
for (const [id, client] of this.clients.entries()) {
|
|
183
|
-
if (
|
|
184
|
-
client.languageId.toLowerCase() === norm ||
|
|
185
|
-
id.startsWith(norm + ":")
|
|
186
|
-
) {
|
|
187
|
-
await client.stop();
|
|
188
|
-
this.clients.delete(id);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Stop all active servers
|
|
195
|
-
*/
|
|
196
|
-
public async stopAll(): Promise<void> {
|
|
197
|
-
for (const client of this.clients.values()) {
|
|
198
|
-
await client.stop();
|
|
199
|
-
}
|
|
200
|
-
this.clients.clear();
|
|
201
|
-
}
|
|
202
|
-
}
|