@theokit/sdk-tools 0.4.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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 6dc0e26: Add `withShellExitGuidance` — a guidance wrapper for `shell_exec` soft failures.
8
+
9
+ `injectGuidance`/`withDefaultGuidance` inject an actionable `guidance` hint only on `{ ok:false, error }` results (by design). But `shell_exec` returns `{ ok:true, exit_code }` — a non-zero `exit_code` is a SOFT failure (the tool ran, the command failed) that the ok:false-only injector does not cover. `withShellExitGuidance(tool)` wraps `shell_exec` so a `{ ok:true, exit_code≠0 }` result gains a `guidance` hint ("The command exited N. Read the stderr above, fix the cause, then retry."). ADDITIVE, IDEMPOTENT, NEVER-THROW; a no-op for any other tool, for `exit_code 0`, and for non-JSON output. Composes after `withDefaultGuidance` (disjoint domains — no double-injection). Lets consumers drop app-side shell-exit guidance reimplementations.
10
+
3
11
  ## 0.4.0
4
12
 
5
13
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -1029,6 +1029,28 @@ function withToolResultGuidance(tool, guidance) {
1029
1029
  function withDefaultGuidance(tool) {
1030
1030
  return withToolResultGuidance(tool, DEFAULT_TOOL_GUIDANCE);
1031
1031
  }
1032
+ function withShellExitGuidance(tool) {
1033
+ if (tool.name !== "shell_exec") return tool;
1034
+ return {
1035
+ name: tool.name,
1036
+ description: tool.description,
1037
+ inputSchema: tool.inputSchema,
1038
+ handler: async (input) => {
1039
+ const out = await tool.handler(input);
1040
+ let parsed;
1041
+ try {
1042
+ parsed = JSON.parse(out);
1043
+ } catch {
1044
+ return out;
1045
+ }
1046
+ if (isRecord(parsed) && parsed.ok === true && typeof parsed.exit_code === "number" && parsed.exit_code !== 0 && !("guidance" in parsed)) {
1047
+ const guidance = `The command exited ${parsed.exit_code}. Read the stderr above, fix the cause, then retry.`;
1048
+ return JSON.stringify({ ...parsed, guidance });
1049
+ }
1050
+ return out;
1051
+ }
1052
+ };
1053
+ }
1032
1054
  var DEFAULT_MAX_ENTRIES = 500;
1033
1055
  function createListDirTool(opts) {
1034
1056
  const { projectRoot, max = DEFAULT_MAX_ENTRIES } = opts;
@@ -1978,6 +2000,7 @@ exports.todoItemsToPlanNodes = todoItemsToPlanNodes;
1978
2000
  exports.truncateOutput = truncateOutput;
1979
2001
  exports.withDefaultGuidance = withDefaultGuidance;
1980
2002
  exports.withDescription = withDescription;
2003
+ exports.withShellExitGuidance = withShellExitGuidance;
1981
2004
  exports.withToolResultGuidance = withToolResultGuidance;
1982
2005
  //# sourceMappingURL=index.cjs.map
1983
2006
  //# sourceMappingURL=index.cjs.map