@floydous/pi-agent-kernel 0.4.3 → 0.5.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.
Files changed (59) hide show
  1. package/AGENT_KERNEL_SYS_PROMPT.md +1 -7
  2. package/CHANGELOG.md +36 -0
  3. package/README.md +6 -53
  4. package/config.example.toml +0 -8
  5. package/docs/README.md +1 -2
  6. package/docs/architecture.md +2 -3
  7. package/docs/configuration.md +10 -9
  8. package/docs/editing-and-verification.md +1 -3
  9. package/docs/retrieval.md +6 -11
  10. package/docs/testing.md +3 -3
  11. package/package.json +4 -2
  12. package/src/config/agent_kernel_command.ts +8 -39
  13. package/src/config/kernel_config.ts +30 -68
  14. package/src/config/toml.ts +6 -1
  15. package/src/editing/auto_heal.ts +1 -1
  16. package/src/editing/patch.ts +27 -16
  17. package/src/editing/post_edit_verification.ts +12 -10
  18. package/src/editing/smart_anchor.ts +7 -5
  19. package/src/editing/syntax-verify.ts +9 -5
  20. package/src/index.ts +15 -257
  21. package/src/retrieval/search_bm25.ts +4 -2
  22. package/src/retrieval/search_chunker.ts +1 -1
  23. package/src/retrieval/search_config.ts +4 -6
  24. package/src/retrieval/search_embedder.ts +3 -2
  25. package/src/retrieval/search_index.ts +82 -35
  26. package/src/retrieval/search_modal.ts +7 -8
  27. package/src/retrieval/{repomap.ts → tag_extractor.ts} +5 -292
  28. package/src/retrieval/tree_sitter_engine.ts +70 -34
  29. package/src/retrieval/workspace_walker.ts +6 -2
  30. package/src/safety/atomic_write.ts +1 -1
  31. package/src/safety/epistemic_guard.ts +105 -31
  32. package/src/safety/output_clamper.ts +14 -8
  33. package/src/tools/code_search_output.ts +2 -1
  34. package/src/tools/code_search_tool.ts +2 -5
  35. package/src/tools/context.ts +0 -14
  36. package/src/tools/edit_tool.ts +82 -115
  37. package/src/tools/read_tool.ts +42 -178
  38. package/src/ui/footer.ts +7 -7
  39. package/docs/lsp.md +0 -31
  40. package/src/lsp/adapters/base.ts +0 -42
  41. package/src/lsp/adapters/index.ts +0 -21
  42. package/src/lsp/adapters/python.ts +0 -37
  43. package/src/lsp/adapters/rust.ts +0 -35
  44. package/src/lsp/adapters/typescript.ts +0 -40
  45. package/src/lsp/index.ts +0 -13
  46. package/src/lsp/lsp_client.ts +0 -765
  47. package/src/lsp/lsp_detector.ts +0 -52
  48. package/src/lsp/lsp_formatter.ts +0 -323
  49. package/src/lsp/lsp_installer.ts +0 -320
  50. package/src/lsp/lsp_manager.ts +0 -202
  51. package/src/lsp/lsp_modal.ts +0 -675
  52. package/src/lsp/lsp_registry.ts +0 -600
  53. package/src/lsp/lsp_types.ts +0 -143
  54. package/src/retrieval/ast_search.ts +0 -999
  55. package/src/retrieval/symbol_reader.ts +0 -228
  56. package/src/tools/ast_search_formatter.ts +0 -161
  57. package/src/tools/ast_search_tool.ts +0 -146
  58. package/src/tools/lsp_tool.ts +0 -794
  59. package/src/tools/repo_map_tool.ts +0 -56
@@ -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
- }