@theokit/sdk-tools 0.3.0 → 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.
package/dist/index.d.cts CHANGED
@@ -361,6 +361,14 @@ declare function injectGuidance(handlerOutput: string, guidance: ToolGuidanceMap
361
361
  declare function withToolResultGuidance(tool: CustomTool, guidance: ToolGuidanceMap): CustomTool;
362
362
  /** `withToolResultGuidance` pre-bound to {@link DEFAULT_TOOL_GUIDANCE}. */
363
363
  declare function withDefaultGuidance(tool: CustomTool): CustomTool;
364
+ /**
365
+ * Wrap `shell_exec` so a SOFT failure — `{ ok: true, exit_code != 0 }` (the TOOL ran, the COMMAND
366
+ * failed) — gains a `guidance` hint. This is the one case {@link injectGuidance} does not cover (it
367
+ * is `ok:false`-only by design). ADDITIVE, IDEMPOTENT, NEVER-THROW; a no-op for any other tool, for
368
+ * `exit_code 0`, and for non-JSON output. Compose AFTER {@link withDefaultGuidance} (the two domains —
369
+ * `ok:false` vs `ok:true` soft-fail — are disjoint, so there is no double-injection).
370
+ */
371
+ declare function withShellExitGuidance(tool: CustomTool): CustomTool;
364
372
 
365
373
  /**
366
374
  * `list_dir` — built-in tool for coding agents.
@@ -785,4 +793,4 @@ interface CreateWriteFileToolOptions {
785
793
  }
786
794
  declare function createWriteFileTool(opts: CreateWriteFileToolOptions): CustomTool;
787
795
 
788
- export { CatastrophicCommandError, type CommandPolicy, type CreateApplyPatchToolOptions, type CreateBraveWebSearchAdapterOptions, type CreateEditFileToolOptions, type CreateGitDiffToolOptions, type CreateGlobToolOptions, type CreateListDirToolOptions, type CreateReadFileToolOptions, type CreateRunVitestToolOptions, type CreateSearchTextToolOptions, type CreateShellToolOptions, type CreateWebFetchToolOptions, type CreateWebSearchToolOptions, type CreateWriteFileToolOptions, DEFAULT_TOOL_GUIDANCE, type PlanModeTool, type PlanModeToolOptions, type PlanModeToolWithStore, type PlanNode, type QuestionTool, type QuestionToolOptions, type RepoMapOptions, type ResolveAndScreenOptions, type ScreenedFetchOptions, type SessionArtifactStore, type SessionArtifactStoreOptions, SsrfBlockedError, type TodoItem, type TodolistTool, type ToolGuidanceMap, type TruncationOptions, type TruncationResult, type VitestSummary, type WebSearchCallback, type WebSearchResult, buildEnvContext, buildRepoMap, catastrophicShellReason, commandDenialReason, createApplyPatchTool, createBraveWebSearchAdapter, createEditFileTool, createGitDiffTool, createGlobTool, createListDirTool, createPlanModeTool, createQuestionTool, createReadFileTool, createRunVitestTool, createSearchTextTool, createSessionArtifactStore, createShellTool, createTodolistTool, createWebFetchTool, createWebSearchTool, createWriteFileTool, denyCatastrophicCommands, formatCode, formatDiff, formatError, formatFileList, injectGuidance, isBlockedIp, isCommandAllowed, renderToolList, resolveAndScreen, screenedFetch, todoItemsToPlanNodes, truncateOutput, withDefaultGuidance, withDescription, withToolResultGuidance };
796
+ export { CatastrophicCommandError, type CommandPolicy, type CreateApplyPatchToolOptions, type CreateBraveWebSearchAdapterOptions, type CreateEditFileToolOptions, type CreateGitDiffToolOptions, type CreateGlobToolOptions, type CreateListDirToolOptions, type CreateReadFileToolOptions, type CreateRunVitestToolOptions, type CreateSearchTextToolOptions, type CreateShellToolOptions, type CreateWebFetchToolOptions, type CreateWebSearchToolOptions, type CreateWriteFileToolOptions, DEFAULT_TOOL_GUIDANCE, type PlanModeTool, type PlanModeToolOptions, type PlanModeToolWithStore, type PlanNode, type QuestionTool, type QuestionToolOptions, type RepoMapOptions, type ResolveAndScreenOptions, type ScreenedFetchOptions, type SessionArtifactStore, type SessionArtifactStoreOptions, SsrfBlockedError, type TodoItem, type TodolistTool, type ToolGuidanceMap, type TruncationOptions, type TruncationResult, type VitestSummary, type WebSearchCallback, type WebSearchResult, buildEnvContext, buildRepoMap, catastrophicShellReason, commandDenialReason, createApplyPatchTool, createBraveWebSearchAdapter, createEditFileTool, createGitDiffTool, createGlobTool, createListDirTool, createPlanModeTool, createQuestionTool, createReadFileTool, createRunVitestTool, createSearchTextTool, createSessionArtifactStore, createShellTool, createTodolistTool, createWebFetchTool, createWebSearchTool, createWriteFileTool, denyCatastrophicCommands, formatCode, formatDiff, formatError, formatFileList, injectGuidance, isBlockedIp, isCommandAllowed, renderToolList, resolveAndScreen, screenedFetch, todoItemsToPlanNodes, truncateOutput, withDefaultGuidance, withDescription, withShellExitGuidance, withToolResultGuidance };
package/dist/index.d.ts CHANGED
@@ -361,6 +361,14 @@ declare function injectGuidance(handlerOutput: string, guidance: ToolGuidanceMap
361
361
  declare function withToolResultGuidance(tool: CustomTool, guidance: ToolGuidanceMap): CustomTool;
362
362
  /** `withToolResultGuidance` pre-bound to {@link DEFAULT_TOOL_GUIDANCE}. */
363
363
  declare function withDefaultGuidance(tool: CustomTool): CustomTool;
364
+ /**
365
+ * Wrap `shell_exec` so a SOFT failure — `{ ok: true, exit_code != 0 }` (the TOOL ran, the COMMAND
366
+ * failed) — gains a `guidance` hint. This is the one case {@link injectGuidance} does not cover (it
367
+ * is `ok:false`-only by design). ADDITIVE, IDEMPOTENT, NEVER-THROW; a no-op for any other tool, for
368
+ * `exit_code 0`, and for non-JSON output. Compose AFTER {@link withDefaultGuidance} (the two domains —
369
+ * `ok:false` vs `ok:true` soft-fail — are disjoint, so there is no double-injection).
370
+ */
371
+ declare function withShellExitGuidance(tool: CustomTool): CustomTool;
364
372
 
365
373
  /**
366
374
  * `list_dir` — built-in tool for coding agents.
@@ -785,4 +793,4 @@ interface CreateWriteFileToolOptions {
785
793
  }
786
794
  declare function createWriteFileTool(opts: CreateWriteFileToolOptions): CustomTool;
787
795
 
788
- export { CatastrophicCommandError, type CommandPolicy, type CreateApplyPatchToolOptions, type CreateBraveWebSearchAdapterOptions, type CreateEditFileToolOptions, type CreateGitDiffToolOptions, type CreateGlobToolOptions, type CreateListDirToolOptions, type CreateReadFileToolOptions, type CreateRunVitestToolOptions, type CreateSearchTextToolOptions, type CreateShellToolOptions, type CreateWebFetchToolOptions, type CreateWebSearchToolOptions, type CreateWriteFileToolOptions, DEFAULT_TOOL_GUIDANCE, type PlanModeTool, type PlanModeToolOptions, type PlanModeToolWithStore, type PlanNode, type QuestionTool, type QuestionToolOptions, type RepoMapOptions, type ResolveAndScreenOptions, type ScreenedFetchOptions, type SessionArtifactStore, type SessionArtifactStoreOptions, SsrfBlockedError, type TodoItem, type TodolistTool, type ToolGuidanceMap, type TruncationOptions, type TruncationResult, type VitestSummary, type WebSearchCallback, type WebSearchResult, buildEnvContext, buildRepoMap, catastrophicShellReason, commandDenialReason, createApplyPatchTool, createBraveWebSearchAdapter, createEditFileTool, createGitDiffTool, createGlobTool, createListDirTool, createPlanModeTool, createQuestionTool, createReadFileTool, createRunVitestTool, createSearchTextTool, createSessionArtifactStore, createShellTool, createTodolistTool, createWebFetchTool, createWebSearchTool, createWriteFileTool, denyCatastrophicCommands, formatCode, formatDiff, formatError, formatFileList, injectGuidance, isBlockedIp, isCommandAllowed, renderToolList, resolveAndScreen, screenedFetch, todoItemsToPlanNodes, truncateOutput, withDefaultGuidance, withDescription, withToolResultGuidance };
796
+ export { CatastrophicCommandError, type CommandPolicy, type CreateApplyPatchToolOptions, type CreateBraveWebSearchAdapterOptions, type CreateEditFileToolOptions, type CreateGitDiffToolOptions, type CreateGlobToolOptions, type CreateListDirToolOptions, type CreateReadFileToolOptions, type CreateRunVitestToolOptions, type CreateSearchTextToolOptions, type CreateShellToolOptions, type CreateWebFetchToolOptions, type CreateWebSearchToolOptions, type CreateWriteFileToolOptions, DEFAULT_TOOL_GUIDANCE, type PlanModeTool, type PlanModeToolOptions, type PlanModeToolWithStore, type PlanNode, type QuestionTool, type QuestionToolOptions, type RepoMapOptions, type ResolveAndScreenOptions, type ScreenedFetchOptions, type SessionArtifactStore, type SessionArtifactStoreOptions, SsrfBlockedError, type TodoItem, type TodolistTool, type ToolGuidanceMap, type TruncationOptions, type TruncationResult, type VitestSummary, type WebSearchCallback, type WebSearchResult, buildEnvContext, buildRepoMap, catastrophicShellReason, commandDenialReason, createApplyPatchTool, createBraveWebSearchAdapter, createEditFileTool, createGitDiffTool, createGlobTool, createListDirTool, createPlanModeTool, createQuestionTool, createReadFileTool, createRunVitestTool, createSearchTextTool, createSessionArtifactStore, createShellTool, createTodolistTool, createWebFetchTool, createWebSearchTool, createWriteFileTool, denyCatastrophicCommands, formatCode, formatDiff, formatError, formatFileList, injectGuidance, isBlockedIp, isCommandAllowed, renderToolList, resolveAndScreen, screenedFetch, todoItemsToPlanNodes, truncateOutput, withDefaultGuidance, withDescription, withShellExitGuidance, withToolResultGuidance };
package/dist/index.js CHANGED
@@ -266,7 +266,7 @@ function createEditFileTool(opts) {
266
266
  const { projectRoot } = opts;
267
267
  return defineTool({
268
268
  name: "edit_file",
269
- description: "Replace the first occurrence of old_string with new_string in a project-relative file. Falls back to whitespace-normalized matching when the exact match fails. Creates a .bak backup before editing. Returns { ok, replacements } or { ok: false, error }.",
269
+ description: "Make an exact string replacement in a project-relative file. Replaces the FIRST occurrence of old_string with new_string (a whitespace-normalized fallback is attempted if the exact match fails) and writes a .bak backup first. Read the file first so old_string matches the on-disk text exactly; include enough surrounding context to make it unique \u2014 only the first match is replaced, so a too-short old_string can edit the wrong location. old_string must be non-empty and differ from new_string; to change every occurrence, call edit_file repeatedly. Returns { ok, replacements } or { ok: false, error }.",
270
270
  inputSchema: z.object({
271
271
  path: z.string().min(1).describe("Project-relative file path."),
272
272
  old_string: z.string().min(1).describe("String to find in the file."),
@@ -274,6 +274,9 @@ function createEditFileTool(opts) {
274
274
  }),
275
275
  // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: unified diff parsing is inherently complex
276
276
  handler: async ({ path, old_string, new_string }) => {
277
+ if (old_string === new_string) {
278
+ return JSON.stringify({ ok: false, error: "no_change", path });
279
+ }
277
280
  if (isForbiddenPath(path)) {
278
281
  return JSON.stringify({ ok: false, error: "forbidden_path", path });
279
282
  }
@@ -522,7 +525,7 @@ function createGlobTool(opts) {
522
525
  const { projectRoot } = opts;
523
526
  return defineTool({
524
527
  name: "glob_files",
525
- description: "List project files matching a glob-like pattern. Excludes node_modules, .git, dist, .theo by default. Returns relative paths. Pattern supports * and ** wildcards. Returns { ok, files } or { ok: false, error }.",
528
+ description: "Find files by glob pattern across the project \u2014 fast at any repo size. Use glob_files when you know the filename SHAPE; use search_text when you know the file CONTENT; use read_file when you know the exact path. The pattern supports * and ** wildcards (e.g. '**/*.ts', 'src/**/*.json'); node_modules/.git/dist/.theo are excluded and results are relative paths. Returns { ok, files } or { ok: false, error }.",
526
529
  inputSchema: z.object({
527
530
  pattern: z.string().min(1).describe("Glob pattern (e.g. '**/*.ts', 'src/**/*.json')."),
528
531
  cwd: z.string().optional().describe("Project-relative subdirectory to search from.")
@@ -1024,6 +1027,28 @@ function withToolResultGuidance(tool, guidance) {
1024
1027
  function withDefaultGuidance(tool) {
1025
1028
  return withToolResultGuidance(tool, DEFAULT_TOOL_GUIDANCE);
1026
1029
  }
1030
+ function withShellExitGuidance(tool) {
1031
+ if (tool.name !== "shell_exec") return tool;
1032
+ return {
1033
+ name: tool.name,
1034
+ description: tool.description,
1035
+ inputSchema: tool.inputSchema,
1036
+ handler: async (input) => {
1037
+ const out = await tool.handler(input);
1038
+ let parsed;
1039
+ try {
1040
+ parsed = JSON.parse(out);
1041
+ } catch {
1042
+ return out;
1043
+ }
1044
+ if (isRecord(parsed) && parsed.ok === true && typeof parsed.exit_code === "number" && parsed.exit_code !== 0 && !("guidance" in parsed)) {
1045
+ const guidance = `The command exited ${parsed.exit_code}. Read the stderr above, fix the cause, then retry.`;
1046
+ return JSON.stringify({ ...parsed, guidance });
1047
+ }
1048
+ return out;
1049
+ }
1050
+ };
1051
+ }
1027
1052
  var DEFAULT_MAX_ENTRIES = 500;
1028
1053
  function createListDirTool(opts) {
1029
1054
  const { projectRoot, max = DEFAULT_MAX_ENTRIES } = opts;
@@ -1209,7 +1234,7 @@ function createReadFileTool(opts) {
1209
1234
  const { projectRoot } = opts;
1210
1235
  return defineTool({
1211
1236
  name: "read_file",
1212
- description: "Read a single project-relative text file as UTF-8. Refuses paths that escape the project root, are in the sensitive-file blocklist (.env, .git/, node_modules/, .theo/, lock files), or contain a null byte in the first 8 KB (binary file). Returns { ok, content } or { ok: false, error }.",
1237
+ description: "Read a project-relative text file as UTF-8. ALWAYS read a file before you edit it (edit_file) or overwrite it (write_file), so your old_string / new content matches the real bytes exactly. Returns the WHOLE file (there is no offset or line-range parameter); to locate a symbol inside a large file, use search_text instead of re-reading. Refuses paths that escape the project root, sensitive files (.env, .git/, node_modules/, .theo/, lock files), and binary files (null byte in the first 8 KB); caps at 5 MB. Returns { ok, content, size } or { ok: false, error }.",
1213
1238
  inputSchema: z.object({
1214
1239
  path: z.string().min(1).describe("Project-relative file path.")
1215
1240
  }),
@@ -1399,7 +1424,7 @@ function createSearchTextTool(opts) {
1399
1424
  } = opts;
1400
1425
  return defineTool({
1401
1426
  name: "search_text",
1402
- description: `Search the project tree for a literal text query. Skips sensitive dirs (.env/.git/node_modules/.theo), binary files, and files over 1 MB. Returns up to ${String(maxMatches)} matches as { file, line, preview }. Use 'path' to scope the search to a subdirectory.`,
1427
+ description: `Search file CONTENTS for a LITERAL, CASE-SENSITIVE query across the project tree (the query is matched as a substring, not a regex). Use search_text when you know the content; use glob_files when you know the filename shape; use read_file when you know the exact path. Skips sensitive dirs (.env/.git/node_modules/.theo), binary files, and files over 1 MB; 'path' scopes the search to a subdirectory. Returns up to ${String(maxMatches)} matches as { file, line, preview } \u2014 cite locations to the user as file:line. Returns { ok, matches } or { ok: false, error }.`,
1403
1428
  inputSchema: z.object({
1404
1429
  query: z.string().min(1).describe("Literal text to search for. Case-sensitive."),
1405
1430
  path: z.string().optional().describe("Optional project-relative directory to scope the search.")
@@ -1510,7 +1535,7 @@ function createShellTool(opts) {
1510
1535
  const { projectRoot, defaultTimeoutMs = DEFAULT_TIMEOUT_MS3, allowCatastrophic = false } = opts;
1511
1536
  return defineTool({
1512
1537
  name: "shell_exec",
1513
- description: "Execute a shell command in the project directory. Returns stdout, stderr, and exit code. Default timeout 30s, max 5 minutes. Output capped at 5 MB. Returns { ok, stdout, stderr, exit_code } or { ok: false, error }.",
1538
+ description: "Execute a shell command in the project directory. Use this for terminal operations \u2014 running tests, git, package managers, build tools. Do NOT use it for file operations (reading, writing, editing, finding files): prefer the specialized read_file/write_file/edit_file/glob_files/search_text tools, which are path-checked and safer. Only commit, push, or change git state when the user explicitly asks. timeout_ms defaults to 30000 (max 300000); stdout/stderr are capped (~5 MB). Returns { ok, stdout, stderr, exit_code } or { ok: false, error }.",
1514
1539
  inputSchema: z.object({
1515
1540
  command: z.string().min(1).describe("Shell command to execute."),
1516
1541
  timeout_ms: z.number().int().positive().optional().describe("Timeout in milliseconds (default 30000, max 300000).")
@@ -1688,7 +1713,7 @@ ${done}/${items.length} done | ${inProg} in progress | ${pending} pending`);
1688
1713
  };
1689
1714
  return {
1690
1715
  name: "todolist",
1691
- description: "Track multi-step task progress. Actions: 'add' (create task with title), 'complete' (mark done by id), 'in_progress' (mark started by id), 'remove' (delete by id), 'list' (show all), 'clear_completed' (remove done items). Returns { ok, items, items_summary } (items = structured array; items_summary = formatted text).",
1716
+ description: "Create and maintain a structured task list for the current session \u2014 tracks progress and keeps a multi-step plan visible across turns. Use it proactively when the work has 3+ steps or the user gave multiple tasks; skip it for a single trivial step. Keep exactly ONE item 'in_progress' at a time, and mark 'complete' only after the work is actually done. Actions: 'add' (create with title), 'in_progress' (mark started by id), 'complete' (mark done by id), 'remove' (delete by id), 'list' (show all), 'clear_completed' (remove done items). Returns { ok, items, items_summary } (items = structured array; items_summary = formatted text).",
1692
1717
  inputSchema: {
1693
1718
  type: "object",
1694
1719
  properties: {
@@ -1744,7 +1769,7 @@ function createWebFetchTool(opts) {
1744
1769
  const allowPrivateHosts = opts?.allowPrivateHosts ?? false;
1745
1770
  return defineTool({
1746
1771
  name: "web_fetch",
1747
- description: "Fetch content from a URL via HTTP/HTTPS. Rejects non-http(s) URLs. Response body capped at 1 MB. Returns { ok, content, status_code } or { ok: false, error }.",
1772
+ description: "Fetch the contents of a URL via HTTP/HTTPS. Use only for URLs the user provided or that you are confident help with the task; never invent or guess URLs. Rejects non-http(s) URLs and is SSRF-guarded by default (private/loopback/link-local/cloud-metadata hosts are refused with an ssrf_blocked error). The response body is capped at 1 MB. Returns { ok, content, status_code, content_type } or { ok: false, error }.",
1748
1773
  inputSchema: z.object({
1749
1774
  url: z.string().min(1).describe("URL to fetch (http or https only)."),
1750
1775
  timeout_ms: z.number().int().positive().optional().describe("Timeout in milliseconds (default 30000).")
@@ -1825,7 +1850,7 @@ function createWebSearchTool(opts) {
1825
1850
  const { search, defaultMaxResults = 5 } = opts;
1826
1851
  return defineTool({
1827
1852
  name: "web_search",
1828
- description: "Search the web for a query. Returns a list of results with title, URL, and snippet. The search provider is injected by the consumer. Returns { ok, results } or { ok: false, error }.",
1853
+ description: "Search the web for a query \u2014 use when you need current information beyond the repo or your training cutoff (library docs, an error message, an API). Returns a list of results with title, URL, and snippet; follow up with web_fetch on a promising result to read it in full. The search provider is injected by the consumer. Returns { ok, results } or { ok: false, error }.",
1829
1854
  inputSchema: z.object({
1830
1855
  query: z.string().min(1).describe("Search query."),
1831
1856
  max_results: z.number().int().positive().max(20).optional().describe("Maximum results to return (default 5, max 20).")
@@ -1883,7 +1908,7 @@ function createWriteFileTool(opts) {
1883
1908
  const { projectRoot } = opts;
1884
1909
  return defineTool({
1885
1910
  name: "write_file",
1886
- description: "Write UTF-8 content to a project-relative file. Creates parent directories recursively. Refuses paths that escape the project root, sensitive files (.env, .git/, node_modules/, .theo/, lock files), and binary-file overwrites. Returns { ok, path, bytes } or { ok: false, error }.",
1911
+ description: "Write UTF-8 content to a project-relative file, creating parent directories as needed. OVERWRITES any existing file at the path. Prefer editing an existing file with edit_file over rewriting it; use write_file to create a NEW file or fully replace a small one. If the file already exists, read_file it first so you do not discard content you have not seen. Refuses paths that escape the project root, sensitive files (.env, .git/, node_modules/, .theo/, lock files), and binary-file overwrites. Returns { ok, path, bytes } or { ok: false, error }.",
1887
1912
  inputSchema: z.object({
1888
1913
  path: z.string().min(1).describe("Project-relative file path."),
1889
1914
  content: z.string().describe("UTF-8 content to write.")
@@ -1934,6 +1959,6 @@ async function isBinaryFile(absolutePath) {
1934
1959
  }
1935
1960
  }
1936
1961
 
1937
- export { CatastrophicCommandError, DEFAULT_TOOL_GUIDANCE, SsrfBlockedError, buildEnvContext, buildRepoMap, catastrophicShellReason, commandDenialReason, createApplyPatchTool, createBraveWebSearchAdapter, createEditFileTool, createGitDiffTool, createGlobTool, createListDirTool, createPlanModeTool, createQuestionTool, createReadFileTool, createRunVitestTool, createSearchTextTool, createSessionArtifactStore, createShellTool, createTodolistTool, createWebFetchTool, createWebSearchTool, createWriteFileTool, denyCatastrophicCommands, formatCode, formatDiff, formatError, formatFileList, injectGuidance, isBlockedIp, isCommandAllowed, renderToolList, resolveAndScreen, screenedFetch, todoItemsToPlanNodes, truncateOutput, withDefaultGuidance, withDescription, withToolResultGuidance };
1962
+ export { CatastrophicCommandError, DEFAULT_TOOL_GUIDANCE, SsrfBlockedError, buildEnvContext, buildRepoMap, catastrophicShellReason, commandDenialReason, createApplyPatchTool, createBraveWebSearchAdapter, createEditFileTool, createGitDiffTool, createGlobTool, createListDirTool, createPlanModeTool, createQuestionTool, createReadFileTool, createRunVitestTool, createSearchTextTool, createSessionArtifactStore, createShellTool, createTodolistTool, createWebFetchTool, createWebSearchTool, createWriteFileTool, denyCatastrophicCommands, formatCode, formatDiff, formatError, formatFileList, injectGuidance, isBlockedIp, isCommandAllowed, renderToolList, resolveAndScreen, screenedFetch, todoItemsToPlanNodes, truncateOutput, withDefaultGuidance, withDescription, withShellExitGuidance, withToolResultGuidance };
1938
1963
  //# sourceMappingURL=index.js.map
1939
1964
  //# sourceMappingURL=index.js.map