@floydous/pi-agent-kernel 0.1.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 (57) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +108 -0
  3. package/config.toml +24 -0
  4. package/docs/README.md +22 -0
  5. package/docs/architecture.md +40 -0
  6. package/docs/configuration.md +43 -0
  7. package/docs/editing-and-verification.md +41 -0
  8. package/docs/lsp.md +31 -0
  9. package/docs/retrieval.md +42 -0
  10. package/docs/testing.md +32 -0
  11. package/package.json +48 -0
  12. package/src/config/index.ts +2 -0
  13. package/src/config/kernel_config.ts +218 -0
  14. package/src/config/toml.ts +237 -0
  15. package/src/context/session_repair.ts +99 -0
  16. package/src/dedup/content_store.ts +365 -0
  17. package/src/dedup/recall_tool.ts +157 -0
  18. package/src/editing/patch.ts +482 -0
  19. package/src/editing/post_edit_verification.ts +200 -0
  20. package/src/editing/syntax-verify.ts +353 -0
  21. package/src/index.ts +852 -0
  22. package/src/lsp/adapters/base.ts +42 -0
  23. package/src/lsp/adapters/index.ts +21 -0
  24. package/src/lsp/adapters/python.ts +37 -0
  25. package/src/lsp/adapters/rust.ts +35 -0
  26. package/src/lsp/adapters/typescript.ts +40 -0
  27. package/src/lsp/index.ts +13 -0
  28. package/src/lsp/lsp_client.ts +650 -0
  29. package/src/lsp/lsp_detector.ts +52 -0
  30. package/src/lsp/lsp_formatter.ts +284 -0
  31. package/src/lsp/lsp_installer.ts +604 -0
  32. package/src/lsp/lsp_manager.ts +202 -0
  33. package/src/lsp/lsp_modal.ts +675 -0
  34. package/src/lsp/lsp_registry.ts +539 -0
  35. package/src/lsp/lsp_types.ts +143 -0
  36. package/src/retrieval/ast_search.ts +926 -0
  37. package/src/retrieval/repomap.ts +779 -0
  38. package/src/retrieval/search_bm25.ts +190 -0
  39. package/src/retrieval/search_chunker.ts +251 -0
  40. package/src/retrieval/search_config.ts +162 -0
  41. package/src/retrieval/search_embedder.ts +362 -0
  42. package/src/retrieval/search_index.ts +753 -0
  43. package/src/retrieval/search_modal.ts +358 -0
  44. package/src/retrieval/symbol_reader.ts +200 -0
  45. package/src/safety/atomic_write.ts +26 -0
  46. package/src/safety/epistemic_guard.ts +733 -0
  47. package/src/safety/kernel_debug.ts +15 -0
  48. package/src/safety/output_clamper.ts +213 -0
  49. package/src/tools/ast_search_tool.ts +131 -0
  50. package/src/tools/code_search_tool.ts +147 -0
  51. package/src/tools/context.ts +20 -0
  52. package/src/tools/edit_tool.ts +288 -0
  53. package/src/tools/lsp_tool.ts +813 -0
  54. package/src/tools/read_tool.ts +348 -0
  55. package/src/tools/repo_map_tool.ts +57 -0
  56. package/src/ui/footer.ts +287 -0
  57. package/src/ui/tui_utils.ts +278 -0
@@ -0,0 +1,42 @@
1
+ import type { LspDiagnostic } from "../lsp_types";
2
+
3
+ export interface LspAdapter {
4
+ readonly languageKey: string;
5
+ getInitializationOptions?(rootDir: string): Record<string, any>;
6
+ getClientCapabilities?(): Record<string, any>;
7
+ handleServerRequest?(method: string, params: any, rootDir: string): any;
8
+ transformDiagnostics?(uri: string, diagnostics: LspDiagnostic[]): LspDiagnostic[];
9
+ }
10
+
11
+ export class BaseLspAdapter implements LspAdapter {
12
+ public readonly languageKey: string;
13
+
14
+ constructor(languageKey = "generic") {
15
+ this.languageKey = languageKey;
16
+ }
17
+
18
+ public getInitializationOptions(_rootDir: string): Record<string, any> {
19
+ return {};
20
+ }
21
+
22
+ public getClientCapabilities(): Record<string, any> {
23
+ return {};
24
+ }
25
+
26
+ public handleServerRequest(method: string, params: any, rootDir: string): any {
27
+ switch (method) {
28
+ case "workspace/configuration":
29
+ return Array.isArray(params?.items) ? params.items.map(() => null) : [];
30
+ case "workspace/workspaceFolders":
31
+ return [{ uri: rootDir, name: "workspace" }];
32
+ case "workspace/applyEdit":
33
+ return { applied: false };
34
+ default:
35
+ return null;
36
+ }
37
+ }
38
+
39
+ public transformDiagnostics(_uri: string, diagnostics: LspDiagnostic[]): LspDiagnostic[] {
40
+ return diagnostics;
41
+ }
42
+ }
@@ -0,0 +1,21 @@
1
+ import type { LspAdapter } from "./base";
2
+ import { BaseLspAdapter } from "./base";
3
+ import { TypeScriptLspAdapter } from "./typescript";
4
+ import { PythonLspAdapter } from "./python";
5
+ import { RustLspAdapter } from "./rust";
6
+
7
+ export * from "./base";
8
+ export * from "./typescript";
9
+ export * from "./python";
10
+ export * from "./rust";
11
+
12
+ const adapters = new Map<string, LspAdapter>([
13
+ ["typescript", new TypeScriptLspAdapter()],
14
+ ["python", new PythonLspAdapter()],
15
+ ["rust", new RustLspAdapter()],
16
+ ]);
17
+
18
+ export function getLspAdapter(languageKey: string): LspAdapter {
19
+ const norm = languageKey.toLowerCase();
20
+ return adapters.get(norm) || new BaseLspAdapter(norm);
21
+ }
@@ -0,0 +1,37 @@
1
+ import { BaseLspAdapter } from "./base";
2
+
3
+ export class PythonLspAdapter extends BaseLspAdapter {
4
+ constructor() {
5
+ super("python");
6
+ }
7
+
8
+ public override getInitializationOptions(_rootDir: string): Record<string, any> {
9
+ return {
10
+ analysis: {
11
+ autoSearchPaths: true,
12
+ useLibraryCodeForTypes: true,
13
+ diagnosticMode: "openFilesOnly",
14
+ typeCheckingMode: "basic",
15
+ },
16
+ };
17
+ }
18
+
19
+ public override handleServerRequest(method: string, params: any, rootDir: string): any {
20
+ if (method === "workspace/configuration") {
21
+ const items = params?.items || [];
22
+ return items.map((item: any) => {
23
+ const section = item?.section || "";
24
+ if (section.startsWith("python") || section.startsWith("pyright") || section.startsWith("basedpyright")) {
25
+ return {
26
+ analysis: {
27
+ diagnosticMode: "openFilesOnly",
28
+ typeCheckingMode: "basic",
29
+ },
30
+ };
31
+ }
32
+ return null;
33
+ });
34
+ }
35
+ return super.handleServerRequest(method, params, rootDir);
36
+ }
37
+ }
@@ -0,0 +1,35 @@
1
+ import { BaseLspAdapter } from "./base";
2
+
3
+ export class RustLspAdapter extends BaseLspAdapter {
4
+ constructor() {
5
+ super("rust");
6
+ }
7
+
8
+ public override getInitializationOptions(_rootDir: string): Record<string, any> {
9
+ return {
10
+ checkOnSave: true,
11
+ diagnostics: {
12
+ enable: true,
13
+ },
14
+ };
15
+ }
16
+
17
+ public override handleServerRequest(method: string, params: any, rootDir: string): any {
18
+ if (method === "workspace/configuration") {
19
+ const items = params?.items || [];
20
+ return items.map((item: any) => {
21
+ const section = item?.section || "";
22
+ if (section.startsWith("rust-analyzer") || section === "") {
23
+ return {
24
+ check: { command: "check" },
25
+ checkOnSave: true,
26
+ cargo: { buildScripts: { enable: true } },
27
+ diagnostics: { enable: true, experimental: { enable: true } },
28
+ };
29
+ }
30
+ return {};
31
+ });
32
+ }
33
+ return super.handleServerRequest(method, params, rootDir);
34
+ }
35
+ }
@@ -0,0 +1,40 @@
1
+ import { BaseLspAdapter } from "./base";
2
+ import type { LspDiagnostic } from "../lsp_types";
3
+
4
+ export class TypeScriptLspAdapter extends BaseLspAdapter {
5
+ constructor() {
6
+ super("typescript");
7
+ }
8
+
9
+ public override getInitializationOptions(_rootDir: string): Record<string, any> {
10
+ return {
11
+ preferences: {
12
+ includeInlayParameterNameHints: "none",
13
+ includeInlayVariableTypeHints: false,
14
+ includeInlayFunctionParameterTypeHints: false,
15
+ },
16
+ tsserver: {
17
+ log: "off",
18
+ maxTsServerMemory: 4096,
19
+ },
20
+ };
21
+ }
22
+
23
+ public override handleServerRequest(method: string, params: any, rootDir: string): any {
24
+ if (method === "workspace/configuration") {
25
+ const items = params?.items || [];
26
+ return items.map((item: any) => {
27
+ const section = item?.section || "";
28
+ if (section.startsWith("typescript") || section.startsWith("javascript") || section.startsWith("vtsls")) {
29
+ return {};
30
+ }
31
+ return null;
32
+ });
33
+ }
34
+ return super.handleServerRequest(method, params, rootDir);
35
+ }
36
+
37
+ public override transformDiagnostics(_uri: string, diagnostics: LspDiagnostic[]): LspDiagnostic[] {
38
+ return diagnostics;
39
+ }
40
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Public LSP Module Exports
3
+ */
4
+
5
+ export * from "./lsp_types";
6
+ export * from "./adapters";
7
+ export * from "./lsp_registry";
8
+ export * from "./lsp_detector";
9
+ export * from "./lsp_formatter";
10
+ export * from "./lsp_client";
11
+ export * from "./lsp_manager";
12
+ export * from "./lsp_installer";
13
+ export * from "./lsp_modal";