@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.
Files changed (65) hide show
  1. package/AGENT_KERNEL_SYS_PROMPT.md +15 -12
  2. package/CHANGELOG.md +87 -0
  3. package/README.md +6 -54
  4. package/config.example.toml +1 -8
  5. package/docs/README.md +1 -2
  6. package/docs/architecture.md +2 -3
  7. package/docs/configuration.md +11 -10
  8. package/docs/editing-and-verification.md +21 -8
  9. package/docs/podman-linux-checks.md +24 -0
  10. package/docs/release-discipline.md +10 -0
  11. package/docs/retrieval.md +21 -23
  12. package/docs/testing.md +3 -3
  13. package/grammars/tree-sitter-html.wasm +0 -0
  14. package/package.json +5 -3
  15. package/src/config/agent_kernel_command.ts +60 -625
  16. package/src/config/kernel_config.ts +53 -69
  17. package/src/config/toml.ts +6 -1
  18. package/src/editing/auto_heal.ts +1 -1
  19. package/src/editing/patch.ts +75 -37
  20. package/src/editing/post_edit_verification.ts +20 -14
  21. package/src/editing/smart_anchor.ts +9 -6
  22. package/src/editing/syntax-verify.ts +79 -222
  23. package/src/index.ts +36 -453
  24. package/src/retrieval/html_chunker.ts +526 -0
  25. package/src/retrieval/search_bm25.ts +39 -28
  26. package/src/retrieval/search_chunker.ts +69 -7
  27. package/src/retrieval/search_config.ts +21 -40
  28. package/src/retrieval/search_embedder.ts +14 -31
  29. package/src/retrieval/search_index.ts +338 -129
  30. package/src/retrieval/search_modal.ts +1208 -222
  31. package/src/retrieval/{repomap.ts → tag_extractor.ts} +6 -293
  32. package/src/retrieval/tree_sitter_engine.ts +171 -36
  33. package/src/retrieval/workspace_walker.ts +78 -2
  34. package/src/safety/atomic_write.ts +1 -1
  35. package/src/safety/epistemic_guard.ts +105 -31
  36. package/src/safety/host_environment.ts +180 -0
  37. package/src/safety/output_clamper.ts +97 -27
  38. package/src/tools/code_search_output.ts +11 -2
  39. package/src/tools/code_search_tool.ts +25 -13
  40. package/src/tools/context.ts +11 -10
  41. package/src/tools/edit_tool.ts +243 -154
  42. package/src/tools/read_tool.ts +285 -214
  43. package/src/tools/stream_reader.ts +206 -0
  44. package/src/ui/footer.ts +7 -7
  45. package/docs/lsp.md +0 -31
  46. package/src/lsp/adapters/base.ts +0 -42
  47. package/src/lsp/adapters/index.ts +0 -21
  48. package/src/lsp/adapters/python.ts +0 -37
  49. package/src/lsp/adapters/rust.ts +0 -35
  50. package/src/lsp/adapters/typescript.ts +0 -40
  51. package/src/lsp/index.ts +0 -13
  52. package/src/lsp/lsp_client.ts +0 -765
  53. package/src/lsp/lsp_detector.ts +0 -52
  54. package/src/lsp/lsp_formatter.ts +0 -323
  55. package/src/lsp/lsp_installer.ts +0 -320
  56. package/src/lsp/lsp_manager.ts +0 -202
  57. package/src/lsp/lsp_modal.ts +0 -675
  58. package/src/lsp/lsp_registry.ts +0 -600
  59. package/src/lsp/lsp_types.ts +0 -143
  60. package/src/retrieval/ast_search.ts +0 -999
  61. package/src/retrieval/symbol_reader.ts +0 -228
  62. package/src/tools/ast_search_formatter.ts +0 -161
  63. package/src/tools/ast_search_tool.ts +0 -146
  64. package/src/tools/lsp_tool.ts +0 -794
  65. package/src/tools/repo_map_tool.ts +0 -56
@@ -3,7 +3,7 @@ import { Type } from "typebox";
3
3
  import { Text, makeOutputText } from "../ui/tui_utils";
4
4
  import { globalEpistemicGuard } from "../safety/epistemic_guard";
5
5
  import { formatCodeSearchResults, CODE_SEARCH_MODES, type CodeSearchMode } from "./code_search_output";
6
- import { speculativeToolsEnabled, type SearchDeps } from "./context";
6
+ import { markReturnedErrors, type SearchDeps } from "./context";
7
7
 
8
8
  /** Extracted from index.ts — registers the `code_search` tool. */
9
9
  export function registerCodeSearchTool(
@@ -11,11 +11,11 @@ export function registerCodeSearchTool(
11
11
  deps: SearchDeps,
12
12
  ): void {
13
13
  // 5.5 Tool: `code_search` (Local Hybrid BM25 + Semantic AST Code Search)
14
- pi.registerTool({
14
+ pi.registerTool(markReturnedErrors({
15
15
  name: "code_search",
16
16
  label: "Codebase Search",
17
17
  description:
18
- "Fast BM25 & AST semantic search across code chunks. Best for conceptual questions, finding unfamiliar features, and searching when exact symbol names or file paths are unknown (prefer rg for exact text literals).",
18
+ "Fast BM25 & AST semantic search across code chunks. Use when locating features, workflows, UI behaviors, or architecture without known symbol names or file paths (prefer rg for exact text literals and non-code files). Do NOT use for finding exact string literals or call-sites; use rg -n instead.",
19
19
  promptSnippet: "Search codebase conceptually or by keywords via hybrid AST index",
20
20
  renderShell: "default",
21
21
  parameters: Type.Object({
@@ -24,7 +24,7 @@ export function registerCodeSearchTool(
24
24
  }),
25
25
  file_pattern: Type.Optional(
26
26
  Type.String({
27
- description: "Optional relative path substring filter",
27
+ description: "Optional relative path substring filter (e.g., 'src/auth', 'tests'). Omit for whole-workspace search. Do NOT guess paths.",
28
28
  }),
29
29
  ),
30
30
  limit: Type.Optional(
@@ -82,28 +82,40 @@ export function registerCodeSearchTool(
82
82
  limit,
83
83
  filePattern: params.file_pattern,
84
84
  rrfK: params.rrf_k,
85
+ separateTests: true,
85
86
  });
86
87
 
87
88
  const indexStatus = typeof index.getStatus === "function" ? index.getStatus() : undefined;
88
- const wantsVectors =
89
- indexStatus?.effectiveProfile === "hybrid" ||
90
- indexStatus?.effectiveProfile === "full";
89
+ const wantsVectors = indexStatus?.effectiveProfile === "full";
91
90
  const vectorNotice =
92
91
  wantsVectors &&
93
92
  indexStatus &&
94
93
  indexStatus.vectorCount < indexStatus.chunkCount
95
94
  ? `[Notice: Vector embeddings are incomplete (${indexStatus.vectorCount}/${indexStatus.chunkCount} chunks); searched via BM25]\n\n`
96
95
  : "";
96
+ const grammarIssues = indexStatus?.grammarIssues ?? [];
97
+ const grammarNotice = grammarIssues.length > 0
98
+ ? `[Notice: tree-sitter grammar unavailable for ${grammarIssues.map((issue) => `${issue.extensions.join(", ")} (${issue.reason})`).join("; ")}; code structure for those files is approximate]\n\n`
99
+ : "";
100
+ const notIndexed = indexStatus?.notIndexed;
101
+ const missingFiles = notIndexed ? notIndexed.source + notIndexed.test + notIndexed.vendored : 0;
102
+ const count = (n: number) => n.toLocaleString("en-US");
103
+ const coverageNotice = indexStatus && notIndexed && missingFiles > 0
104
+ ? `[Notice: index covers ${count(indexStatus.indexableFiles - missingFiles)} of ${indexStatus.walkTruncated ? "≥ " : ""}${count(indexStatus.indexableFiles)} indexable files (index limits); not indexed: ${(["source", "test", "vendored"] as const).filter((tier) => notIndexed[tier] > 0).map((tier) => `${count(notIndexed[tier])} ${tier}`).join(", ")} (${indexStatus.notIndexedDirs.join(", ")}); use rg for those paths]\n\n`
105
+ : "";
97
106
 
98
107
  if (hits.length === 0) {
108
+ // Blame the filter, not the query, when it excludes every indexed file (e.g. "README": docs are not indexed).
109
+ const filterExcludesIndex = params.file_pattern && indexStatus && indexStatus.chunkCount > 0 &&
110
+ typeof index.hasIndexedFile === "function" && !index.hasIndexedFile(params.file_pattern);
111
+ const message = filterExcludesIndex
112
+ ? `No indexed file path contains "${params.file_pattern}". code_search indexes source code only (not Markdown, JSON, YAML, TOML or other text files); use rg to search other files.`
113
+ : `No code chunks found matching "${query}". (Tips: Try broader or different terms, or 'rg' for exact text literals.)`;
99
114
  return {
100
115
  content: [
101
116
  {
102
117
  type: "text",
103
- text: `${vectorNotice}No code chunks found matching "${query}". (` +
104
- (speculativeToolsEnabled(deps.getConfig, ctx.cwd)
105
- ? `Tips: Try 'ast_search' for exact symbol names or 'rg' for exact text literals.`
106
- : `Tips: Try broader or different terms, or 'rg' for exact text literals.`),
118
+ text: `${coverageNotice}${grammarNotice}${vectorNotice}${message}`,
107
119
  },
108
120
  ],
109
121
  details: { count: 0 },
@@ -151,7 +163,7 @@ export function registerCodeSearchTool(
151
163
  content: [
152
164
  {
153
165
  type: "text",
154
- text: `${vectorNotice}${formatted.text}`,
166
+ text: `${coverageNotice}${grammarNotice}${vectorNotice}${formatted.text}`,
155
167
  },
156
168
  ],
157
169
  details: {
@@ -187,5 +199,5 @@ export function registerCodeSearchTool(
187
199
  result.content?.find((c: any) => c.type === "text")?.text || "";
188
200
  return makeOutputText(`\n${theme.fg("toolOutput", output)}`);
189
201
  },
190
- });
202
+ }));
191
203
  }
@@ -13,17 +13,18 @@ export interface SessionDeps {
13
13
  }
14
14
 
15
15
  /**
16
- * Whether the opt-in tools (`get_repo_map`, `ast_search`, `lsp`) are registered for this
17
- * workspace. Single source of truth: `src/index.ts` gates registration on this, and user-facing
18
- * tool hints consult it so they never recommend a tool the model cannot actually call.
16
+ * pi flags a tool result as an error only when `execute` throws; a returned `isError` is dropped. Kernel tools return
17
+ * their failures, so copy the flag into `details.isError`, where the kernel's tool_result hook restores it.
19
18
  */
20
- export function speculativeToolsEnabled(
21
- getConfig: ((cwd: string) => import("../config").KernelConfig) | undefined,
22
- cwd: string,
23
- ): boolean {
24
- const flag = process.env.PI_ENABLE_ALL_RETRIEVAL_TOOLS;
25
- if (flag === "1" || flag === "true") return true;
26
- return getConfig?.(cwd)?.retrieval?.enable_tools === true;
19
+ export function markReturnedErrors<T extends { execute: (...args: any[]) => Promise<any> }>(tool: T): T {
20
+ const execute = tool.execute;
21
+ return {
22
+ ...tool,
23
+ async execute(...args: any[]) {
24
+ const result = await execute.apply(tool, args);
25
+ return result?.isError === true ? { ...result, details: { ...(result.details ?? {}), isError: true } } : result;
26
+ },
27
+ };
27
28
  }
28
29
 
29
30
  export interface SearchDeps extends SessionDeps {