gsd-pi 2.10.2 → 2.10.5

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 (136) hide show
  1. package/README.md +2 -0
  2. package/dist/cli.js +7 -0
  3. package/dist/loader.js +1 -0
  4. package/dist/onboarding.js +104 -59
  5. package/dist/update-cmd.d.ts +1 -0
  6. package/dist/update-cmd.js +40 -0
  7. package/node_modules/@gsd/native/dist/hasher/index.d.ts +32 -0
  8. package/node_modules/@gsd/native/dist/hasher/index.js +37 -0
  9. package/node_modules/@gsd/native/dist/native.d.ts +4 -1
  10. package/node_modules/@gsd/native/dist/native.js +39 -9
  11. package/node_modules/@gsd/native/dist/xxhash/index.d.ts +14 -0
  12. package/node_modules/@gsd/native/dist/xxhash/index.js +17 -0
  13. package/node_modules/@gsd/pi-coding-agent/dist/core/agent-session.d.ts +6 -0
  14. package/node_modules/@gsd/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
  15. package/node_modules/@gsd/pi-coding-agent/dist/core/agent-session.js +58 -9
  16. package/node_modules/@gsd/pi-coding-agent/dist/core/agent-session.js.map +1 -1
  17. package/node_modules/@gsd/pi-coding-agent/dist/core/auth-storage.d.ts +72 -12
  18. package/node_modules/@gsd/pi-coding-agent/dist/core/auth-storage.d.ts.map +1 -1
  19. package/node_modules/@gsd/pi-coding-agent/dist/core/auth-storage.js +254 -43
  20. package/node_modules/@gsd/pi-coding-agent/dist/core/auth-storage.js.map +1 -1
  21. package/node_modules/@gsd/pi-coding-agent/dist/core/auth-storage.test.d.ts +2 -0
  22. package/node_modules/@gsd/pi-coding-agent/dist/core/auth-storage.test.d.ts.map +1 -0
  23. package/node_modules/@gsd/pi-coding-agent/dist/core/auth-storage.test.js +159 -0
  24. package/node_modules/@gsd/pi-coding-agent/dist/core/auth-storage.test.js.map +1 -0
  25. package/node_modules/@gsd/pi-coding-agent/dist/core/model-registry.d.ts +4 -2
  26. package/node_modules/@gsd/pi-coding-agent/dist/core/model-registry.d.ts.map +1 -1
  27. package/node_modules/@gsd/pi-coding-agent/dist/core/model-registry.js +6 -4
  28. package/node_modules/@gsd/pi-coding-agent/dist/core/model-registry.js.map +1 -1
  29. package/node_modules/@gsd/pi-coding-agent/dist/core/settings-manager.d.ts +15 -0
  30. package/node_modules/@gsd/pi-coding-agent/dist/core/settings-manager.d.ts.map +1 -1
  31. package/node_modules/@gsd/pi-coding-agent/dist/core/settings-manager.js +12 -0
  32. package/node_modules/@gsd/pi-coding-agent/dist/core/settings-manager.js.map +1 -1
  33. package/node_modules/@gsd/pi-coding-agent/dist/core/tools/bash-interceptor.d.ts +40 -0
  34. package/node_modules/@gsd/pi-coding-agent/dist/core/tools/bash-interceptor.d.ts.map +1 -0
  35. package/node_modules/@gsd/pi-coding-agent/dist/core/tools/bash-interceptor.js +92 -0
  36. package/node_modules/@gsd/pi-coding-agent/dist/core/tools/bash-interceptor.js.map +1 -0
  37. package/node_modules/@gsd/pi-coding-agent/dist/core/tools/bash-interceptor.test.d.ts +2 -0
  38. package/node_modules/@gsd/pi-coding-agent/dist/core/tools/bash-interceptor.test.d.ts.map +1 -0
  39. package/node_modules/@gsd/pi-coding-agent/dist/core/tools/bash-interceptor.test.js +156 -0
  40. package/node_modules/@gsd/pi-coding-agent/dist/core/tools/bash-interceptor.test.js.map +1 -0
  41. package/node_modules/@gsd/pi-coding-agent/dist/core/tools/bash.d.ts +8 -0
  42. package/node_modules/@gsd/pi-coding-agent/dist/core/tools/bash.d.ts.map +1 -1
  43. package/node_modules/@gsd/pi-coding-agent/dist/core/tools/bash.js +18 -0
  44. package/node_modules/@gsd/pi-coding-agent/dist/core/tools/bash.js.map +1 -1
  45. package/node_modules/@gsd/pi-coding-agent/dist/core/tools/index.d.ts +1 -0
  46. package/node_modules/@gsd/pi-coding-agent/dist/core/tools/index.d.ts.map +1 -1
  47. package/node_modules/@gsd/pi-coding-agent/dist/core/tools/index.js +1 -0
  48. package/node_modules/@gsd/pi-coding-agent/dist/core/tools/index.js.map +1 -1
  49. package/node_modules/@gsd/pi-coding-agent/dist/index.d.ts +2 -2
  50. package/node_modules/@gsd/pi-coding-agent/dist/index.d.ts.map +1 -1
  51. package/node_modules/@gsd/pi-coding-agent/dist/index.js +1 -1
  52. package/node_modules/@gsd/pi-coding-agent/dist/index.js.map +1 -1
  53. package/node_modules/@gsd/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  54. package/node_modules/@gsd/pi-coding-agent/dist/modes/interactive/interactive-mode.js +1 -1
  55. package/node_modules/@gsd/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
  56. package/node_modules/@gsd/pi-coding-agent/src/core/agent-session.ts +65 -9
  57. package/node_modules/@gsd/pi-coding-agent/src/core/auth-storage.test.ts +194 -0
  58. package/node_modules/@gsd/pi-coding-agent/src/core/auth-storage.ts +283 -53
  59. package/node_modules/@gsd/pi-coding-agent/src/core/model-registry.ts +6 -4
  60. package/node_modules/@gsd/pi-coding-agent/src/core/settings-manager.ts +29 -0
  61. package/node_modules/@gsd/pi-coding-agent/src/core/tools/bash-interceptor.test.ts +198 -0
  62. package/node_modules/@gsd/pi-coding-agent/src/core/tools/bash-interceptor.ts +115 -0
  63. package/node_modules/@gsd/pi-coding-agent/src/core/tools/bash.ts +29 -0
  64. package/node_modules/@gsd/pi-coding-agent/src/core/tools/index.ts +8 -0
  65. package/node_modules/@gsd/pi-coding-agent/src/index.ts +6 -0
  66. package/node_modules/@gsd/pi-coding-agent/src/modes/interactive/interactive-mode.ts +1 -1
  67. package/package.json +8 -2
  68. package/packages/native/dist/hasher/index.d.ts +32 -0
  69. package/packages/native/dist/hasher/index.js +37 -0
  70. package/packages/native/dist/native.d.ts +4 -1
  71. package/packages/native/dist/native.js +39 -9
  72. package/packages/native/dist/xxhash/index.d.ts +14 -0
  73. package/packages/native/dist/xxhash/index.js +17 -0
  74. package/packages/native/src/native.ts +39 -9
  75. package/packages/pi-coding-agent/dist/core/agent-session.d.ts +6 -0
  76. package/packages/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
  77. package/packages/pi-coding-agent/dist/core/agent-session.js +58 -9
  78. package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
  79. package/packages/pi-coding-agent/dist/core/auth-storage.d.ts +72 -12
  80. package/packages/pi-coding-agent/dist/core/auth-storage.d.ts.map +1 -1
  81. package/packages/pi-coding-agent/dist/core/auth-storage.js +254 -43
  82. package/packages/pi-coding-agent/dist/core/auth-storage.js.map +1 -1
  83. package/packages/pi-coding-agent/dist/core/auth-storage.test.d.ts +2 -0
  84. package/packages/pi-coding-agent/dist/core/auth-storage.test.d.ts.map +1 -0
  85. package/packages/pi-coding-agent/dist/core/auth-storage.test.js +159 -0
  86. package/packages/pi-coding-agent/dist/core/auth-storage.test.js.map +1 -0
  87. package/packages/pi-coding-agent/dist/core/model-registry.d.ts +4 -2
  88. package/packages/pi-coding-agent/dist/core/model-registry.d.ts.map +1 -1
  89. package/packages/pi-coding-agent/dist/core/model-registry.js +6 -4
  90. package/packages/pi-coding-agent/dist/core/model-registry.js.map +1 -1
  91. package/packages/pi-coding-agent/dist/core/settings-manager.d.ts +15 -0
  92. package/packages/pi-coding-agent/dist/core/settings-manager.d.ts.map +1 -1
  93. package/packages/pi-coding-agent/dist/core/settings-manager.js +12 -0
  94. package/packages/pi-coding-agent/dist/core/settings-manager.js.map +1 -1
  95. package/packages/pi-coding-agent/dist/core/tools/bash-interceptor.d.ts +40 -0
  96. package/packages/pi-coding-agent/dist/core/tools/bash-interceptor.d.ts.map +1 -0
  97. package/packages/pi-coding-agent/dist/core/tools/bash-interceptor.js +92 -0
  98. package/packages/pi-coding-agent/dist/core/tools/bash-interceptor.js.map +1 -0
  99. package/packages/pi-coding-agent/dist/core/tools/bash-interceptor.test.d.ts +2 -0
  100. package/packages/pi-coding-agent/dist/core/tools/bash-interceptor.test.d.ts.map +1 -0
  101. package/packages/pi-coding-agent/dist/core/tools/bash-interceptor.test.js +156 -0
  102. package/packages/pi-coding-agent/dist/core/tools/bash-interceptor.test.js.map +1 -0
  103. package/packages/pi-coding-agent/dist/core/tools/bash.d.ts +8 -0
  104. package/packages/pi-coding-agent/dist/core/tools/bash.d.ts.map +1 -1
  105. package/packages/pi-coding-agent/dist/core/tools/bash.js +18 -0
  106. package/packages/pi-coding-agent/dist/core/tools/bash.js.map +1 -1
  107. package/packages/pi-coding-agent/dist/core/tools/index.d.ts +1 -0
  108. package/packages/pi-coding-agent/dist/core/tools/index.d.ts.map +1 -1
  109. package/packages/pi-coding-agent/dist/core/tools/index.js +1 -0
  110. package/packages/pi-coding-agent/dist/core/tools/index.js.map +1 -1
  111. package/packages/pi-coding-agent/dist/index.d.ts +2 -2
  112. package/packages/pi-coding-agent/dist/index.d.ts.map +1 -1
  113. package/packages/pi-coding-agent/dist/index.js +1 -1
  114. package/packages/pi-coding-agent/dist/index.js.map +1 -1
  115. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  116. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js +1 -1
  117. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
  118. package/packages/pi-coding-agent/src/core/agent-session.ts +65 -9
  119. package/packages/pi-coding-agent/src/core/auth-storage.test.ts +194 -0
  120. package/packages/pi-coding-agent/src/core/auth-storage.ts +283 -53
  121. package/packages/pi-coding-agent/src/core/model-registry.ts +6 -4
  122. package/packages/pi-coding-agent/src/core/settings-manager.ts +29 -0
  123. package/packages/pi-coding-agent/src/core/tools/bash-interceptor.test.ts +198 -0
  124. package/packages/pi-coding-agent/src/core/tools/bash-interceptor.ts +115 -0
  125. package/packages/pi-coding-agent/src/core/tools/bash.ts +29 -0
  126. package/packages/pi-coding-agent/src/core/tools/index.ts +8 -0
  127. package/packages/pi-coding-agent/src/index.ts +6 -0
  128. package/packages/pi-coding-agent/src/modes/interactive/interactive-mode.ts +1 -1
  129. package/src/resources/extensions/async-jobs/async-bash-tool.ts +211 -0
  130. package/src/resources/extensions/async-jobs/await-tool.ts +101 -0
  131. package/src/resources/extensions/async-jobs/cancel-job-tool.ts +34 -0
  132. package/src/resources/extensions/async-jobs/index.ts +133 -0
  133. package/src/resources/extensions/async-jobs/job-manager.ts +250 -0
  134. package/src/resources/extensions/gsd/git-service.ts +13 -3
  135. package/src/resources/extensions/gsd/prompts/system.md +5 -2
  136. package/src/resources/extensions/gsd/tests/git-service.test.ts +36 -0
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Bash command interceptor — blocks shell commands that duplicate dedicated tools.
3
+ *
4
+ * Each rule defines a regex pattern, a suggested replacement tool, and a message.
5
+ * A command is only blocked when the suggested tool exists in the session's active tool list.
6
+ */
7
+ export interface BashInterceptorRule {
8
+ pattern: string;
9
+ flags?: string;
10
+ tool: string;
11
+ message: string;
12
+ }
13
+ export declare const DEFAULT_BASH_INTERCEPTOR_RULES: BashInterceptorRule[];
14
+ export interface InterceptionResult {
15
+ block: boolean;
16
+ message?: string;
17
+ suggestedTool?: string;
18
+ }
19
+ export interface CompiledInterceptor {
20
+ check: (command: string, availableTools: string[]) => InterceptionResult;
21
+ }
22
+ /**
23
+ * Compile rules into an interceptor with pre-built regex objects.
24
+ * Silently skips rules with invalid patterns.
25
+ *
26
+ * Pre-compiling at construction time avoids repeated `new RegExp()` calls
27
+ * on every bash command invocation.
28
+ */
29
+ export declare function compileInterceptor(rules: BashInterceptorRule[]): CompiledInterceptor;
30
+ /**
31
+ * Check whether a bash command should be intercepted.
32
+ *
33
+ * Compiles rules on each call — prefer `compileInterceptor()` for repeated use.
34
+ *
35
+ * @param command - The shell command to check
36
+ * @param availableTools - Tool names present in the current session
37
+ * @param rules - Override the default rule set (optional)
38
+ */
39
+ export declare function checkBashInterception(command: string, availableTools: string[], rules?: BashInterceptorRule[]): InterceptionResult;
40
+ //# sourceMappingURL=bash-interceptor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bash-interceptor.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash-interceptor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,mBAAmB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,8BAA8B,EAAE,mBAAmB,EAuC/D,CAAC;AAEF,MAAM,WAAW,kBAAkB;IAClC,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,mBAAmB;IACnC,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,KAAK,kBAAkB,CAAC;CACzE;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,mBAAmB,EAAE,GAAG,mBAAmB,CAwBpF;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACpC,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,MAAM,EAAE,EACxB,KAAK,CAAC,EAAE,mBAAmB,EAAE,GAC3B,kBAAkB,CAGpB"}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Bash command interceptor — blocks shell commands that duplicate dedicated tools.
3
+ *
4
+ * Each rule defines a regex pattern, a suggested replacement tool, and a message.
5
+ * A command is only blocked when the suggested tool exists in the session's active tool list.
6
+ */
7
+ export const DEFAULT_BASH_INTERCEPTOR_RULES = [
8
+ {
9
+ // cat/head/tail for file viewing — excludes heredoc syntax (cat <<)
10
+ pattern: "^\\s*(cat(?!\\s*<<)|head|tail|less|more)\\s+",
11
+ tool: "read",
12
+ message: "Use the read tool to view file contents instead of shell commands.",
13
+ },
14
+ {
15
+ pattern: "^\\s*(grep|rg|ripgrep|ag|ack)\\s+",
16
+ tool: "grep",
17
+ message: "Use the grep tool for searching file contents instead of shell commands.",
18
+ },
19
+ {
20
+ pattern: "^\\s*(find|fd|locate)\\s+.*(-name|-iname|-type|--type|-glob)",
21
+ tool: "find",
22
+ message: "Use the find tool for locating files by name/type instead of shell commands.",
23
+ },
24
+ {
25
+ pattern: "^\\s*sed\\s+(-i|--in-place)",
26
+ tool: "edit",
27
+ message: "Use the edit tool for in-place file modifications instead of sed.",
28
+ },
29
+ {
30
+ pattern: "^\\s*perl\\s+.*-[pn]?i",
31
+ tool: "edit",
32
+ message: "Use the edit tool for in-place file modifications instead of perl.",
33
+ },
34
+ {
35
+ pattern: "^\\s*awk\\s+.*-i\\s+inplace",
36
+ tool: "edit",
37
+ message: "Use the edit tool for in-place file modifications instead of awk.",
38
+ },
39
+ {
40
+ // echo/printf/heredoc writing to a file via > (not >> append, not 2> stderr redirect)
41
+ // Matches a single > not preceded by |, >, or a digit (fd redirect like 2>)
42
+ pattern: "^\\s*(echo|printf|cat\\s*<<)\\s+.*(?<![|>\\d])>(?!>)\\s*\\S",
43
+ tool: "write",
44
+ message: "Use the write tool to create/overwrite files instead of shell redirects.",
45
+ },
46
+ ];
47
+ /**
48
+ * Compile rules into an interceptor with pre-built regex objects.
49
+ * Silently skips rules with invalid patterns.
50
+ *
51
+ * Pre-compiling at construction time avoids repeated `new RegExp()` calls
52
+ * on every bash command invocation.
53
+ */
54
+ export function compileInterceptor(rules) {
55
+ const compiled = rules.flatMap((rule) => {
56
+ try {
57
+ return [{ regex: new RegExp(rule.pattern, rule.flags), rule }];
58
+ }
59
+ catch {
60
+ return []; // skip invalid regex
61
+ }
62
+ });
63
+ return {
64
+ check(command, availableTools) {
65
+ const trimmed = command.trim();
66
+ for (const { regex, rule } of compiled) {
67
+ if (regex.test(trimmed) && availableTools.includes(rule.tool)) {
68
+ return {
69
+ block: true,
70
+ message: `Blocked: ${rule.message}\n\nOriginal command: ${command}`,
71
+ suggestedTool: rule.tool,
72
+ };
73
+ }
74
+ }
75
+ return { block: false };
76
+ },
77
+ };
78
+ }
79
+ /**
80
+ * Check whether a bash command should be intercepted.
81
+ *
82
+ * Compiles rules on each call — prefer `compileInterceptor()` for repeated use.
83
+ *
84
+ * @param command - The shell command to check
85
+ * @param availableTools - Tool names present in the current session
86
+ * @param rules - Override the default rule set (optional)
87
+ */
88
+ export function checkBashInterception(command, availableTools, rules) {
89
+ const effectiveRules = rules ?? DEFAULT_BASH_INTERCEPTOR_RULES;
90
+ return compileInterceptor(effectiveRules).check(command, availableTools);
91
+ }
92
+ //# sourceMappingURL=bash-interceptor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bash-interceptor.js","sourceRoot":"","sources":["../../../src/core/tools/bash-interceptor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,MAAM,CAAC,MAAM,8BAA8B,GAA0B;IACpE;QACC,oEAAoE;QACpE,OAAO,EAAE,8CAA8C;QACvD,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,oEAAoE;KAC7E;IACD;QACC,OAAO,EAAE,mCAAmC;QAC5C,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,0EAA0E;KACnF;IACD;QACC,OAAO,EAAE,8DAA8D;QACvE,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,8EAA8E;KACvF;IACD;QACC,OAAO,EAAE,6BAA6B;QACtC,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,mEAAmE;KAC5E;IACD;QACC,OAAO,EAAE,wBAAwB;QACjC,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,oEAAoE;KAC7E;IACD;QACC,OAAO,EAAE,6BAA6B;QACtC,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,mEAAmE;KAC5E;IACD;QACC,sFAAsF;QACtF,4EAA4E;QAC5E,OAAO,EAAE,6DAA6D;QACtE,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,0EAA0E;KACnF;CACD,CAAC;AAYF;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAA4B;IAC9D,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACvC,IAAI,CAAC;YACJ,OAAO,CAAC,EAAE,KAAK,EAAE,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QAChE,CAAC;QAAC,MAAM,CAAC;YACR,OAAO,EAAE,CAAC,CAAC,qBAAqB;QACjC,CAAC;IACF,CAAC,CAAC,CAAC;IAEH,OAAO;QACN,KAAK,CAAC,OAAe,EAAE,cAAwB;YAC9C,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;YAC/B,KAAK,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,QAAQ,EAAE,CAAC;gBACxC,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,cAAc,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;oBAC/D,OAAO;wBACN,KAAK,EAAE,IAAI;wBACX,OAAO,EAAE,YAAY,IAAI,CAAC,OAAO,yBAAyB,OAAO,EAAE;wBACnE,aAAa,EAAE,IAAI,CAAC,IAAI;qBACxB,CAAC;gBACH,CAAC;YACF,CAAC;YACD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;QACzB,CAAC;KACD,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,qBAAqB,CACpC,OAAe,EACf,cAAwB,EACxB,KAA6B;IAE7B,MAAM,cAAc,GAAG,KAAK,IAAI,8BAA8B,CAAC;IAC/D,OAAO,kBAAkB,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;AAC1E,CAAC","sourcesContent":["/**\n * Bash command interceptor — blocks shell commands that duplicate dedicated tools.\n *\n * Each rule defines a regex pattern, a suggested replacement tool, and a message.\n * A command is only blocked when the suggested tool exists in the session's active tool list.\n */\n\nexport interface BashInterceptorRule {\n\tpattern: string;\n\tflags?: string;\n\ttool: string;\n\tmessage: string;\n}\n\nexport const DEFAULT_BASH_INTERCEPTOR_RULES: BashInterceptorRule[] = [\n\t{\n\t\t// cat/head/tail for file viewing — excludes heredoc syntax (cat <<)\n\t\tpattern: \"^\\\\s*(cat(?!\\\\s*<<)|head|tail|less|more)\\\\s+\",\n\t\ttool: \"read\",\n\t\tmessage: \"Use the read tool to view file contents instead of shell commands.\",\n\t},\n\t{\n\t\tpattern: \"^\\\\s*(grep|rg|ripgrep|ag|ack)\\\\s+\",\n\t\ttool: \"grep\",\n\t\tmessage: \"Use the grep tool for searching file contents instead of shell commands.\",\n\t},\n\t{\n\t\tpattern: \"^\\\\s*(find|fd|locate)\\\\s+.*(-name|-iname|-type|--type|-glob)\",\n\t\ttool: \"find\",\n\t\tmessage: \"Use the find tool for locating files by name/type instead of shell commands.\",\n\t},\n\t{\n\t\tpattern: \"^\\\\s*sed\\\\s+(-i|--in-place)\",\n\t\ttool: \"edit\",\n\t\tmessage: \"Use the edit tool for in-place file modifications instead of sed.\",\n\t},\n\t{\n\t\tpattern: \"^\\\\s*perl\\\\s+.*-[pn]?i\",\n\t\ttool: \"edit\",\n\t\tmessage: \"Use the edit tool for in-place file modifications instead of perl.\",\n\t},\n\t{\n\t\tpattern: \"^\\\\s*awk\\\\s+.*-i\\\\s+inplace\",\n\t\ttool: \"edit\",\n\t\tmessage: \"Use the edit tool for in-place file modifications instead of awk.\",\n\t},\n\t{\n\t\t// echo/printf/heredoc writing to a file via > (not >> append, not 2> stderr redirect)\n\t\t// Matches a single > not preceded by |, >, or a digit (fd redirect like 2>)\n\t\tpattern: \"^\\\\s*(echo|printf|cat\\\\s*<<)\\\\s+.*(?<![|>\\\\d])>(?!>)\\\\s*\\\\S\",\n\t\ttool: \"write\",\n\t\tmessage: \"Use the write tool to create/overwrite files instead of shell redirects.\",\n\t},\n];\n\nexport interface InterceptionResult {\n\tblock: boolean;\n\tmessage?: string;\n\tsuggestedTool?: string;\n}\n\nexport interface CompiledInterceptor {\n\tcheck: (command: string, availableTools: string[]) => InterceptionResult;\n}\n\n/**\n * Compile rules into an interceptor with pre-built regex objects.\n * Silently skips rules with invalid patterns.\n *\n * Pre-compiling at construction time avoids repeated `new RegExp()` calls\n * on every bash command invocation.\n */\nexport function compileInterceptor(rules: BashInterceptorRule[]): CompiledInterceptor {\n\tconst compiled = rules.flatMap((rule) => {\n\t\ttry {\n\t\t\treturn [{ regex: new RegExp(rule.pattern, rule.flags), rule }];\n\t\t} catch {\n\t\t\treturn []; // skip invalid regex\n\t\t}\n\t});\n\n\treturn {\n\t\tcheck(command: string, availableTools: string[]): InterceptionResult {\n\t\t\tconst trimmed = command.trim();\n\t\t\tfor (const { regex, rule } of compiled) {\n\t\t\t\tif (regex.test(trimmed) && availableTools.includes(rule.tool)) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tblock: true,\n\t\t\t\t\t\tmessage: `Blocked: ${rule.message}\\n\\nOriginal command: ${command}`,\n\t\t\t\t\t\tsuggestedTool: rule.tool,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn { block: false };\n\t\t},\n\t};\n}\n\n/**\n * Check whether a bash command should be intercepted.\n *\n * Compiles rules on each call — prefer `compileInterceptor()` for repeated use.\n *\n * @param command - The shell command to check\n * @param availableTools - Tool names present in the current session\n * @param rules - Override the default rule set (optional)\n */\nexport function checkBashInterception(\n\tcommand: string,\n\tavailableTools: string[],\n\trules?: BashInterceptorRule[],\n): InterceptionResult {\n\tconst effectiveRules = rules ?? DEFAULT_BASH_INTERCEPTOR_RULES;\n\treturn compileInterceptor(effectiveRules).check(command, availableTools);\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=bash-interceptor.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bash-interceptor.test.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash-interceptor.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,156 @@
1
+ import { describe, it } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { checkBashInterception, compileInterceptor, DEFAULT_BASH_INTERCEPTOR_RULES, } from "./bash-interceptor.js";
4
+ const ALL_TOOLS = ["read", "grep", "find", "edit", "write"];
5
+ const NO_TOOLS = [];
6
+ describe("checkBashInterception", () => {
7
+ describe("read rule (cat/head/tail/less/more)", () => {
8
+ it("blocks cat with a file argument", () => {
9
+ const r = checkBashInterception("cat README.md", ALL_TOOLS);
10
+ assert.equal(r.block, true);
11
+ assert.equal(r.suggestedTool, "read");
12
+ });
13
+ it("blocks head and tail", () => {
14
+ assert.equal(checkBashInterception("head -n 20 file.ts", ALL_TOOLS).block, true);
15
+ assert.equal(checkBashInterception("tail -f app.log", ALL_TOOLS).block, true);
16
+ });
17
+ it("does NOT block cat used as heredoc (cat <<EOF)", () => {
18
+ const r = checkBashInterception("cat <<EOF > file.txt", ALL_TOOLS);
19
+ assert.notEqual(r.suggestedTool, "read");
20
+ });
21
+ it("does NOT block when read tool is absent", () => {
22
+ assert.equal(checkBashInterception("cat README.md", NO_TOOLS).block, false);
23
+ assert.equal(checkBashInterception("cat README.md", ["grep"]).block, false);
24
+ });
25
+ });
26
+ describe("grep rule", () => {
27
+ it("blocks grep and rg", () => {
28
+ assert.equal(checkBashInterception("grep foo bar.ts", ALL_TOOLS).block, true);
29
+ assert.equal(checkBashInterception("rg -r pattern .", ALL_TOOLS).block, true);
30
+ });
31
+ it("blocks grep with leading whitespace", () => {
32
+ assert.equal(checkBashInterception(" grep -r foo .", ALL_TOOLS).block, true);
33
+ });
34
+ it("does NOT block when grep tool is absent", () => {
35
+ assert.equal(checkBashInterception("grep foo bar", ["read", "edit"]).block, false);
36
+ });
37
+ });
38
+ describe("find rule", () => {
39
+ it("blocks find with -name flag", () => {
40
+ assert.equal(checkBashInterception('find . -name "*.ts"', ALL_TOOLS).block, true);
41
+ });
42
+ it("blocks find with -type flag", () => {
43
+ assert.equal(checkBashInterception("find /tmp -maxdepth 1 -type f", ALL_TOOLS).block, true);
44
+ });
45
+ it("does NOT block find without name/type flags", () => {
46
+ assert.equal(checkBashInterception("find /tmp -maxdepth 1", ALL_TOOLS).block, false);
47
+ });
48
+ it("does NOT block when find tool is absent", () => {
49
+ assert.equal(checkBashInterception('find . -name "*.ts"', ["read", "grep"]).block, false);
50
+ });
51
+ });
52
+ describe("edit rule (sed/perl/awk)", () => {
53
+ it("blocks sed -i", () => {
54
+ assert.equal(checkBashInterception("sed -i 's/foo/bar/' file.ts", ALL_TOOLS).block, true);
55
+ assert.equal(checkBashInterception("sed --in-place 's/x/y/' f", ALL_TOOLS).block, true);
56
+ });
57
+ it("does NOT block sed without -i (read-only)", () => {
58
+ assert.equal(checkBashInterception("sed 's/foo/bar/' file.ts", ALL_TOOLS).block, false);
59
+ });
60
+ it("blocks perl -pi and perl -p -i", () => {
61
+ assert.equal(checkBashInterception("perl -pi -e 's/foo/bar/' file", ALL_TOOLS).block, true);
62
+ assert.equal(checkBashInterception("perl -p -i -e 's/x/y/' f", ALL_TOOLS).block, true);
63
+ });
64
+ it("blocks awk -i inplace", () => {
65
+ assert.equal(checkBashInterception("awk -i inplace '{print}' file", ALL_TOOLS).block, true);
66
+ });
67
+ it("does NOT block when edit tool is absent", () => {
68
+ assert.equal(checkBashInterception("sed -i 's/a/b/' f", ["read", "grep"]).block, false);
69
+ });
70
+ });
71
+ describe("write rule (echo/printf/heredoc redirect)", () => {
72
+ it("blocks echo with > redirect", () => {
73
+ assert.equal(checkBashInterception("echo hello > file.txt", ALL_TOOLS).block, true);
74
+ });
75
+ it("blocks printf with > redirect", () => {
76
+ assert.equal(checkBashInterception('printf "%s" content > out.txt', ALL_TOOLS).block, true);
77
+ });
78
+ it("does NOT block echo without redirect", () => {
79
+ assert.equal(checkBashInterception("echo hello", ALL_TOOLS).block, false);
80
+ });
81
+ it("does NOT block >> append redirect (write tool does not support appending)", () => {
82
+ assert.equal(checkBashInterception("echo hello >> file.txt", ALL_TOOLS).block, false);
83
+ });
84
+ it("does NOT block stderr redirect (2>)", () => {
85
+ assert.equal(checkBashInterception("echo test 2> /dev/null", ALL_TOOLS).block, false);
86
+ });
87
+ it("does NOT block pipe (echo foo | grep bar)", () => {
88
+ assert.equal(checkBashInterception("echo foo | grep bar", ALL_TOOLS).block, false);
89
+ });
90
+ it("does NOT block when write tool is absent", () => {
91
+ assert.equal(checkBashInterception("echo hello > file.txt", ["read", "grep"]).block, false);
92
+ });
93
+ });
94
+ describe("pass-through commands", () => {
95
+ it("passes npm install", () => {
96
+ assert.equal(checkBashInterception("npm install", ALL_TOOLS).block, false);
97
+ });
98
+ it("passes ls > output.txt (not an echo/printf/cat)", () => {
99
+ assert.equal(checkBashInterception("ls > output.txt", ALL_TOOLS).block, false);
100
+ });
101
+ it("passes tee file.txt", () => {
102
+ assert.equal(checkBashInterception("tee file.txt", ALL_TOOLS).block, false);
103
+ });
104
+ it("passes git log", () => {
105
+ assert.equal(checkBashInterception("git log --oneline", ALL_TOOLS).block, false);
106
+ });
107
+ });
108
+ describe("block message content", () => {
109
+ it("includes the original command in the block message", () => {
110
+ const r = checkBashInterception("cat README.md", ALL_TOOLS);
111
+ assert.ok(r.message?.includes("cat README.md"), "message should contain original command");
112
+ });
113
+ it("returns block:false with no message when not blocked", () => {
114
+ const r = checkBashInterception("npm install", ALL_TOOLS);
115
+ assert.equal(r.block, false);
116
+ assert.equal(r.message, undefined);
117
+ });
118
+ });
119
+ });
120
+ describe("compileInterceptor", () => {
121
+ it("produces same results as checkBashInterception", () => {
122
+ const interceptor = compileInterceptor(DEFAULT_BASH_INTERCEPTOR_RULES);
123
+ const cases = [
124
+ ["cat README.md", ALL_TOOLS, true],
125
+ ["npm install", ALL_TOOLS, false],
126
+ ["grep foo bar", ALL_TOOLS, true],
127
+ ["echo hello >> file", ALL_TOOLS, false],
128
+ ["echo test 2> /dev/null", ALL_TOOLS, false],
129
+ ];
130
+ for (const [cmd, tools, expected] of cases) {
131
+ assert.equal(interceptor.check(cmd, tools).block, expected, `pre-compiled: "${cmd}" expected block=${expected}`);
132
+ }
133
+ });
134
+ it("silently skips rules with invalid regex patterns", () => {
135
+ const rules = [
136
+ { pattern: "[invalid(", tool: "read", message: "broken" },
137
+ { pattern: "^\\s*cat\\s+", tool: "read", message: "valid" },
138
+ ];
139
+ const interceptor = compileInterceptor(rules);
140
+ assert.equal(interceptor.check("cat file.txt", ["read"]).block, true);
141
+ });
142
+ it("returns block:false when available tools list is empty", () => {
143
+ const interceptor = compileInterceptor(DEFAULT_BASH_INTERCEPTOR_RULES);
144
+ assert.equal(interceptor.check("cat README.md", []).block, false);
145
+ });
146
+ it("allows custom rule override", () => {
147
+ const customRules = [
148
+ { pattern: "^\\s*curl\\s+", tool: "fetch", message: "Use fetch tool instead." },
149
+ ];
150
+ const interceptor = compileInterceptor(customRules);
151
+ assert.equal(interceptor.check("curl https://example.com", ["fetch"]).block, true);
152
+ // default rules not active
153
+ assert.equal(interceptor.check("cat file.txt", ["read"]).block, false);
154
+ });
155
+ });
156
+ //# sourceMappingURL=bash-interceptor.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bash-interceptor.test.js","sourceRoot":"","sources":["../../../src/core/tools/bash-interceptor.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EACN,qBAAqB,EACrB,kBAAkB,EAClB,8BAA8B,GAE9B,MAAM,uBAAuB,CAAC;AAE/B,MAAM,SAAS,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAC5D,MAAM,QAAQ,GAAa,EAAE,CAAC;AAE9B,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACtC,QAAQ,CAAC,qCAAqC,EAAE,GAAG,EAAE;QACpD,EAAE,CAAC,iCAAiC,EAAE,GAAG,EAAE;YAC1C,MAAM,CAA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AAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE;SAC3D,CAAC;QACF,MAAM,WAAW,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAC9C,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wDAAwD,EAAE,GAAG,EAAE;QACjE,MAAM,WAAW,GAAG,kBAAkB,CAAC,8BAA8B,CAAC,CAAC;QACvE,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACnE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACtC,MAAM,WAAW,GAA0B;YAC1C,EAAE,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,yBAAyB,EAAE;SAC/E,CAAC;QACF,MAAM,WAAW,GAAG,kBAAkB,CAAC,WAAW,CAAC,CAAC;QACpD,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,0BAA0B,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QACnF,2BAA2B;QAC3B,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import { describe, it } from \"node:test\";\nimport assert from \"node:assert/strict\";\nimport {\n\tcheckBashInterception,\n\tcompileInterceptor,\n\tDEFAULT_BASH_INTERCEPTOR_RULES,\n\ttype BashInterceptorRule,\n} from \"./bash-interceptor.js\";\n\nconst ALL_TOOLS = [\"read\", \"grep\", \"find\", \"edit\", \"write\"];\nconst NO_TOOLS: string[] = [];\n\ndescribe(\"checkBashInterception\", () => {\n\tdescribe(\"read rule (cat/head/tail/less/more)\", () => {\n\t\tit(\"blocks cat with a file argument\", () => {\n\t\t\tconst r = checkBashInterception(\"cat README.md\", ALL_TOOLS);\n\t\t\tassert.equal(r.block, true);\n\t\t\tassert.equal(r.suggestedTool, \"read\");\n\t\t});\n\n\t\tit(\"blocks head and tail\", () => {\n\t\t\tassert.equal(checkBashInterception(\"head -n 20 file.ts\", ALL_TOOLS).block, true);\n\t\t\tassert.equal(checkBashInterception(\"tail -f app.log\", ALL_TOOLS).block, true);\n\t\t});\n\n\t\tit(\"does NOT block cat used as heredoc (cat <<EOF)\", () => {\n\t\t\tconst r = checkBashInterception(\"cat <<EOF > file.txt\", ALL_TOOLS);\n\t\t\tassert.notEqual(r.suggestedTool, \"read\");\n\t\t});\n\n\t\tit(\"does NOT block when read tool is absent\", () => {\n\t\t\tassert.equal(checkBashInterception(\"cat README.md\", NO_TOOLS).block, false);\n\t\t\tassert.equal(checkBashInterception(\"cat README.md\", [\"grep\"]).block, false);\n\t\t});\n\t});\n\n\tdescribe(\"grep rule\", () => {\n\t\tit(\"blocks grep and rg\", () => {\n\t\t\tassert.equal(checkBashInterception(\"grep foo bar.ts\", ALL_TOOLS).block, true);\n\t\t\tassert.equal(checkBashInterception(\"rg -r pattern .\", ALL_TOOLS).block, true);\n\t\t});\n\n\t\tit(\"blocks grep with leading whitespace\", () => {\n\t\t\tassert.equal(checkBashInterception(\" grep -r foo .\", ALL_TOOLS).block, true);\n\t\t});\n\n\t\tit(\"does NOT block when grep tool is absent\", () => {\n\t\t\tassert.equal(checkBashInterception(\"grep foo bar\", [\"read\", \"edit\"]).block, false);\n\t\t});\n\t});\n\n\tdescribe(\"find rule\", () => {\n\t\tit(\"blocks find with -name flag\", () => {\n\t\t\tassert.equal(checkBashInterception('find . -name \"*.ts\"', ALL_TOOLS).block, true);\n\t\t});\n\n\t\tit(\"blocks find with -type flag\", () => {\n\t\t\tassert.equal(checkBashInterception(\"find /tmp -maxdepth 1 -type f\", ALL_TOOLS).block, true);\n\t\t});\n\n\t\tit(\"does NOT block find without name/type flags\", () => {\n\t\t\tassert.equal(checkBashInterception(\"find /tmp -maxdepth 1\", ALL_TOOLS).block, false);\n\t\t});\n\n\t\tit(\"does NOT block when find tool is absent\", () => {\n\t\t\tassert.equal(checkBashInterception('find . -name \"*.ts\"', [\"read\", \"grep\"]).block, false);\n\t\t});\n\t});\n\n\tdescribe(\"edit rule (sed/perl/awk)\", () => {\n\t\tit(\"blocks sed -i\", () => {\n\t\t\tassert.equal(checkBashInterception(\"sed -i 's/foo/bar/' file.ts\", ALL_TOOLS).block, true);\n\t\t\tassert.equal(checkBashInterception(\"sed --in-place 's/x/y/' f\", ALL_TOOLS).block, true);\n\t\t});\n\n\t\tit(\"does NOT block sed without -i (read-only)\", () => {\n\t\t\tassert.equal(checkBashInterception(\"sed 's/foo/bar/' file.ts\", ALL_TOOLS).block, false);\n\t\t});\n\n\t\tit(\"blocks perl -pi and perl -p -i\", () => {\n\t\t\tassert.equal(checkBashInterception(\"perl -pi -e 's/foo/bar/' file\", ALL_TOOLS).block, true);\n\t\t\tassert.equal(checkBashInterception(\"perl -p -i -e 's/x/y/' f\", ALL_TOOLS).block, true);\n\t\t});\n\n\t\tit(\"blocks awk -i inplace\", () => {\n\t\t\tassert.equal(checkBashInterception(\"awk -i inplace '{print}' file\", ALL_TOOLS).block, true);\n\t\t});\n\n\t\tit(\"does NOT block when edit tool is absent\", () => {\n\t\t\tassert.equal(checkBashInterception(\"sed -i 's/a/b/' f\", [\"read\", \"grep\"]).block, false);\n\t\t});\n\t});\n\n\tdescribe(\"write rule (echo/printf/heredoc redirect)\", () => {\n\t\tit(\"blocks echo with > redirect\", () => {\n\t\t\tassert.equal(checkBashInterception(\"echo hello > file.txt\", ALL_TOOLS).block, true);\n\t\t});\n\n\t\tit(\"blocks printf with > redirect\", () => {\n\t\t\tassert.equal(checkBashInterception('printf \"%s\" content > out.txt', ALL_TOOLS).block, true);\n\t\t});\n\n\t\tit(\"does NOT block echo without redirect\", () => {\n\t\t\tassert.equal(checkBashInterception(\"echo hello\", ALL_TOOLS).block, false);\n\t\t});\n\n\t\tit(\"does NOT block >> append redirect (write tool does not support appending)\", () => {\n\t\t\tassert.equal(checkBashInterception(\"echo hello >> file.txt\", ALL_TOOLS).block, false);\n\t\t});\n\n\t\tit(\"does NOT block stderr redirect (2>)\", () => {\n\t\t\tassert.equal(checkBashInterception(\"echo test 2> /dev/null\", ALL_TOOLS).block, false);\n\t\t});\n\n\t\tit(\"does NOT block pipe (echo foo | grep bar)\", () => {\n\t\t\tassert.equal(checkBashInterception(\"echo foo | grep bar\", ALL_TOOLS).block, false);\n\t\t});\n\n\t\tit(\"does NOT block when write tool is absent\", () => {\n\t\t\tassert.equal(checkBashInterception(\"echo hello > file.txt\", [\"read\", \"grep\"]).block, false);\n\t\t});\n\t});\n\n\tdescribe(\"pass-through commands\", () => {\n\t\tit(\"passes npm install\", () => {\n\t\t\tassert.equal(checkBashInterception(\"npm install\", ALL_TOOLS).block, false);\n\t\t});\n\n\t\tit(\"passes ls > output.txt (not an echo/printf/cat)\", () => {\n\t\t\tassert.equal(checkBashInterception(\"ls > output.txt\", ALL_TOOLS).block, false);\n\t\t});\n\n\t\tit(\"passes tee file.txt\", () => {\n\t\t\tassert.equal(checkBashInterception(\"tee file.txt\", ALL_TOOLS).block, false);\n\t\t});\n\n\t\tit(\"passes git log\", () => {\n\t\t\tassert.equal(checkBashInterception(\"git log --oneline\", ALL_TOOLS).block, false);\n\t\t});\n\t});\n\n\tdescribe(\"block message content\", () => {\n\t\tit(\"includes the original command in the block message\", () => {\n\t\t\tconst r = checkBashInterception(\"cat README.md\", ALL_TOOLS);\n\t\t\tassert.ok(r.message?.includes(\"cat README.md\"), \"message should contain original command\");\n\t\t});\n\n\t\tit(\"returns block:false with no message when not blocked\", () => {\n\t\t\tconst r = checkBashInterception(\"npm install\", ALL_TOOLS);\n\t\t\tassert.equal(r.block, false);\n\t\t\tassert.equal(r.message, undefined);\n\t\t});\n\t});\n});\n\ndescribe(\"compileInterceptor\", () => {\n\tit(\"produces same results as checkBashInterception\", () => {\n\t\tconst interceptor = compileInterceptor(DEFAULT_BASH_INTERCEPTOR_RULES);\n\t\tconst cases: [string, string[], boolean][] = [\n\t\t\t[\"cat README.md\", ALL_TOOLS, true],\n\t\t\t[\"npm install\", ALL_TOOLS, false],\n\t\t\t[\"grep foo bar\", ALL_TOOLS, true],\n\t\t\t[\"echo hello >> file\", ALL_TOOLS, false],\n\t\t\t[\"echo test 2> /dev/null\", ALL_TOOLS, false],\n\t\t];\n\t\tfor (const [cmd, tools, expected] of cases) {\n\t\t\tassert.equal(\n\t\t\t\tinterceptor.check(cmd, tools).block,\n\t\t\t\texpected,\n\t\t\t\t`pre-compiled: \"${cmd}\" expected block=${expected}`,\n\t\t\t);\n\t\t}\n\t});\n\n\tit(\"silently skips rules with invalid regex patterns\", () => {\n\t\tconst rules: BashInterceptorRule[] = [\n\t\t\t{ pattern: \"[invalid(\", tool: \"read\", message: \"broken\" },\n\t\t\t{ pattern: \"^\\\\s*cat\\\\s+\", tool: \"read\", message: \"valid\" },\n\t\t];\n\t\tconst interceptor = compileInterceptor(rules);\n\t\tassert.equal(interceptor.check(\"cat file.txt\", [\"read\"]).block, true);\n\t});\n\n\tit(\"returns block:false when available tools list is empty\", () => {\n\t\tconst interceptor = compileInterceptor(DEFAULT_BASH_INTERCEPTOR_RULES);\n\t\tassert.equal(interceptor.check(\"cat README.md\", []).block, false);\n\t});\n\n\tit(\"allows custom rule override\", () => {\n\t\tconst customRules: BashInterceptorRule[] = [\n\t\t\t{ pattern: \"^\\\\s*curl\\\\s+\", tool: \"fetch\", message: \"Use fetch tool instead.\" },\n\t\t];\n\t\tconst interceptor = compileInterceptor(customRules);\n\t\tassert.equal(interceptor.check(\"curl https://example.com\", [\"fetch\"]).block, true);\n\t\t// default rules not active\n\t\tassert.equal(interceptor.check(\"cat file.txt\", [\"read\"]).block, false);\n\t});\n});\n"]}
@@ -1,5 +1,6 @@
1
1
  import type { AgentTool } from "@gsd/pi-agent-core";
2
2
  import { type Static } from "@sinclair/typebox";
3
+ import { type BashInterceptorRule } from "./bash-interceptor.js";
3
4
  import { type TruncationResult } from "./truncate.js";
4
5
  import type { ArtifactManager } from "../artifact-manager.js";
5
6
  declare const bashSchema: import("@sinclair/typebox").TObject<{
@@ -48,6 +49,13 @@ export interface BashToolOptions {
48
49
  spawnHook?: BashSpawnHook;
49
50
  /** Session-scoped artifact storage. When provided, spills to artifact files instead of temp files. */
50
51
  artifactManager?: ArtifactManager;
52
+ /** Bash interceptor configuration — blocks commands that duplicate dedicated tools */
53
+ interceptor?: {
54
+ enabled: boolean;
55
+ rules?: BashInterceptorRule[];
56
+ };
57
+ /** Tool names available in the session, used by the interceptor to check if replacement tools exist */
58
+ availableToolNames?: string[] | (() => string[]);
51
59
  }
52
60
  export declare function createBashTool(cwd: string, options?: BashToolOptions): AgentTool<typeof bashSchema>;
53
61
  /** Default bash tool using process.cwd() - for backwards compatibility */
@@ -1 +1 @@
1
- {"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,KAAK,MAAM,EAAQ,MAAM,mBAAmB,CAAC;AAGtD,OAAO,EAAoD,KAAK,gBAAgB,EAAgB,MAAM,eAAe,CAAC;AACtH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAkC9D,QAAA,MAAM,UAAU;;;EAGd,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC/B,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,cAAc,CAAC,EAAE,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D;IAC3D,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,sGAAsG;IACtG,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,sFAAsF;IACtF,WAAW,CAAC,EAAE;QACb,OAAO,EAAE,OAAO,CAAC;QACjB,KAAK,CAAC,EAAE,mBAAmB,EAAE,CAAC;KAC9B,CAAC;IACF,uGAAuG;IACvG,kBAAkB,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,MAAM,EAAE,CAAC,CAAC;CACjD;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAsLnG;AAED,0EAA0E;AAC1E,eAAO,MAAM,QAAQ;;;QAAgC,CAAC"}
@@ -6,6 +6,7 @@ import { join } from "node:path";
6
6
  import { Type } from "@sinclair/typebox";
7
7
  import { spawn } from "child_process";
8
8
  import { getShellConfig, getShellEnv, killProcessTree, sanitizeCommand } from "../../utils/shell.js";
9
+ import { compileInterceptor, DEFAULT_BASH_INTERCEPTOR_RULES } from "./bash-interceptor.js";
9
10
  import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, truncateTail } from "./truncate.js";
10
11
  // Cached Win32 FFI handles for restoring VT input after child processes
11
12
  let _vtHandles = null;
@@ -133,12 +134,29 @@ export function createBashTool(cwd, options) {
133
134
  const commandPrefix = options?.commandPrefix;
134
135
  const spawnHook = options?.spawnHook;
135
136
  const artifactManager = options?.artifactManager;
137
+ // Pre-compile interceptor rules once at construction time
138
+ const interceptorInstance = options?.interceptor?.enabled
139
+ ? compileInterceptor(options.interceptor.rules ?? DEFAULT_BASH_INTERCEPTOR_RULES)
140
+ : null;
136
141
  return {
137
142
  name: "bash",
138
143
  label: "bash",
139
144
  description: `Execute a bash command in the current working directory. Returns stdout and stderr. Output is truncated to last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). If truncated, full output is saved to a temp file. Optionally provide a timeout in seconds.`,
140
145
  parameters: bashSchema,
141
146
  execute: async (_toolCallId, { command, timeout }, signal, onUpdate) => {
147
+ // Check bash interceptor — block commands that duplicate dedicated tools
148
+ if (interceptorInstance) {
149
+ const toolNames = typeof options.availableToolNames === "function"
150
+ ? options.availableToolNames()
151
+ : options.availableToolNames ?? [];
152
+ const interception = interceptorInstance.check(command, toolNames);
153
+ if (interception.block) {
154
+ return {
155
+ content: [{ type: "text", text: interception.message ?? "Command blocked by interceptor" }],
156
+ details: undefined,
157
+ };
158
+ }
159
+ }
142
160
  // Apply command prefix if configured (e.g., "shopt -s expand_aliases" for alias support)
143
161
  const resolvedCommand = sanitizeCommand(commandPrefix ? `${commandPrefix}\n${command}` : command);
144
162
  const spawnContext = resolveSpawnContext(resolvedCommand, cwd, spawnHook);
@@ -1 +1 @@
1
- {"version":3,"file":"bash.js","sourceRoot":"","sources":["../../../src/core/tools/bash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAe,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACrG,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,UAAU,EAAyB,YAAY,EAAE,MAAM,eAAe,CAAC;AAGtH,wEAAwE;AACxE,IAAI,UAAU,GAAqE,IAAI,CAAC;AACxF,SAAS,qBAAqB;IAC7B,IAAI,OAAO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MAAM,CAAC,CAAC,CAAC;oBAC3B,CAAC;yBAAM,IAAI,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;wBAC/C,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;wBAC9C,IAAI,MAAM;4BAAE,MAAM,IAAI,MAAM,CAAC;wBAC7B,MAAM,IAAI,2BAA2B,WAAW,UAAU,CAAC;wBAC3D,MAAM,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;oBAC3B,CAAC;yBAAM,CAAC;wBACP,MAAM,CAAC,GAAG,CAAC,CAAC;oBACb,CAAC;gBACF,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACJ,CAAC;KACD,CAAC;AACH,CAAC;AAED,0EAA0E;AAC1E,MAAM,CAAC,MAAM,QAAQ,GAAG,cAAc,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC","sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport { createWriteStream, existsSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport type { AgentTool } from \"@gsd/pi-agent-core\";\nimport { type Static, Type } from \"@sinclair/typebox\";\nimport { spawn } from \"child_process\";\nimport { getShellConfig, getShellEnv, killProcessTree, sanitizeCommand } from \"../../utils/shell.js\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult, truncateTail } from \"./truncate.js\";\nimport type { ArtifactManager } from \"../artifact-manager.js\";\n\n// Cached Win32 FFI handles for restoring VT input after child processes\nlet _vtHandles: { GetConsoleMode: any; SetConsoleMode: any; handle: any } | null = null;\nfunction restoreWindowsVTInput(): void {\n\tif (process.platform !== \"win32\") return;\n\ttry {\n\t\tif (!_vtHandles) {\n\t\t\tconst cjsRequire = createRequire(import.meta.url);\n\t\t\tconst koffi = cjsRequire(\"koffi\");\n\t\t\tconst k32 = koffi.load(\"kernel32.dll\");\n\t\t\tconst GetStdHandle = k32.func(\"void* __stdcall GetStdHandle(int)\");\n\t\t\tconst GetConsoleMode = k32.func(\"bool __stdcall GetConsoleMode(void*, _Out_ uint32_t*)\");\n\t\t\tconst SetConsoleMode = k32.func(\"bool __stdcall SetConsoleMode(void*, uint32_t)\");\n\t\t\tconst handle = GetStdHandle(-10);\n\t\t\t_vtHandles = { GetConsoleMode, SetConsoleMode, handle };\n\t\t}\n\t\tconst ENABLE_VIRTUAL_TERMINAL_INPUT = 0x0200;\n\t\tconst mode = new Uint32Array(1);\n\t\t_vtHandles.GetConsoleMode(_vtHandles.handle, mode);\n\t\tif (!(mode[0]! & ENABLE_VIRTUAL_TERMINAL_INPUT)) {\n\t\t\t_vtHandles.SetConsoleMode(_vtHandles.handle, mode[0]! | ENABLE_VIRTUAL_TERMINAL_INPUT);\n\t\t}\n\t} catch { /* koffi not available */ }\n}\n\n/**\n * Generate a unique temp file path for bash output\n */\nfunction getTempFilePath(): string {\n\tconst id = randomBytes(8).toString(\"hex\");\n\treturn join(tmpdir(), `pi-bash-${id}.log`);\n}\n\nconst bashSchema = Type.Object({\n\tcommand: Type.String({ description: \"Bash command to execute\" }),\n\ttimeout: Type.Optional(Type.Number({ description: \"Timeout in seconds (optional, no default timeout)\" })),\n});\n\nexport type BashToolInput = Static<typeof bashSchema>;\n\nexport interface BashToolDetails {\n\ttruncation?: TruncationResult;\n\tfullOutputPath?: string;\n\tartifactId?: string;\n}\n\n/**\n * Pluggable operations for the bash tool.\n * Override these to delegate command execution to remote systems (e.g., SSH).\n */\nexport interface BashOperations {\n\t/**\n\t * Execute a command and stream output.\n\t * @param command - The command to execute\n\t * @param cwd - Working directory\n\t * @param options - Execution options\n\t * @returns Promise resolving to exit code (null if killed)\n\t */\n\texec: (\n\t\tcommand: string,\n\t\tcwd: string,\n\t\toptions: {\n\t\t\tonData: (data: Buffer) => void;\n\t\t\tsignal?: AbortSignal;\n\t\t\ttimeout?: number;\n\t\t\tenv?: NodeJS.ProcessEnv;\n\t\t},\n\t) => Promise<{ exitCode: number | null }>;\n}\n\n/**\n * Default bash operations using local shell\n */\nconst defaultBashOperations: BashOperations = {\n\texec: (command, cwd, { onData, signal, timeout, env }) => {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst { shell, args } = getShellConfig();\n\n\t\t\tif (!existsSync(cwd)) {\n\t\t\t\treject(new Error(`Working directory does not exist: ${cwd}\\nCannot execute bash commands.`));\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst child = spawn(shell, [...args, command], {\n\t\t\t\tcwd,\n\t\t\t\tdetached: true,\n\t\t\t\tenv: env ?? getShellEnv(),\n\t\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t\t});\n\n\t\t\tlet timedOut = false;\n\n\t\t\t// Set timeout if provided\n\t\t\tlet timeoutHandle: NodeJS.Timeout | undefined;\n\t\t\tif (timeout !== undefined && timeout > 0) {\n\t\t\t\ttimeoutHandle = setTimeout(() => {\n\t\t\t\t\ttimedOut = true;\n\t\t\t\t\tif (child.pid) {\n\t\t\t\t\t\tkillProcessTree(child.pid);\n\t\t\t\t\t}\n\t\t\t\t}, timeout * 1000);\n\t\t\t}\n\n\t\t\t// Stream stdout and stderr\n\t\t\tif (child.stdout) {\n\t\t\t\tchild.stdout.on(\"data\", onData);\n\t\t\t}\n\t\t\tif (child.stderr) {\n\t\t\t\tchild.stderr.on(\"data\", onData);\n\t\t\t}\n\n\t\t\t// Handle shell spawn errors\n\t\t\tchild.on(\"error\", (err) => {\n\t\t\t\tif (timeoutHandle) clearTimeout(timeoutHandle);\n\t\t\t\tif (signal) signal.removeEventListener(\"abort\", onAbort);\n\t\t\t\treject(err);\n\t\t\t});\n\n\t\t\t// Handle abort signal - kill entire process tree\n\t\t\tconst onAbort = () => {\n\t\t\t\tif (child.pid) {\n\t\t\t\t\tkillProcessTree(child.pid);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tif (signal) {\n\t\t\t\tif (signal.aborted) {\n\t\t\t\t\tonAbort();\n\t\t\t\t} else {\n\t\t\t\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Handle process exit\n\t\t\tchild.on(\"close\", (code) => {\n\t\t\t\trestoreWindowsVTInput();\n\t\t\t\tif (timeoutHandle) clearTimeout(timeoutHandle);\n\t\t\t\tif (signal) signal.removeEventListener(\"abort\", onAbort);\n\n\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\treject(new Error(\"aborted\"));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (timedOut) {\n\t\t\t\t\treject(new Error(`timeout:${timeout}`));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tresolve({ exitCode: code });\n\t\t\t});\n\t\t});\n\t},\n};\n\nexport interface BashSpawnContext {\n\tcommand: string;\n\tcwd: string;\n\tenv: NodeJS.ProcessEnv;\n}\n\nexport type BashSpawnHook = (context: BashSpawnContext) => BashSpawnContext;\n\nfunction resolveSpawnContext(command: string, cwd: string, spawnHook?: BashSpawnHook): BashSpawnContext {\n\tconst baseContext: BashSpawnContext = {\n\t\tcommand,\n\t\tcwd,\n\t\tenv: { ...getShellEnv() },\n\t};\n\n\treturn spawnHook ? spawnHook(baseContext) : baseContext;\n}\n\nexport interface BashToolOptions {\n\t/** Custom operations for command execution. Default: local shell */\n\toperations?: BashOperations;\n\t/** Command prefix prepended to every command (e.g., \"shopt -s expand_aliases\" for alias support) */\n\tcommandPrefix?: string;\n\t/** Hook to adjust command, cwd, or env before execution */\n\tspawnHook?: BashSpawnHook;\n\t/** Session-scoped artifact storage. When provided, spills to artifact files instead of temp files. */\n\tartifactManager?: ArtifactManager;\n}\n\nexport function createBashTool(cwd: string, options?: BashToolOptions): AgentTool<typeof bashSchema> {\n\tconst ops = options?.operations ?? defaultBashOperations;\n\tconst commandPrefix = options?.commandPrefix;\n\tconst spawnHook = options?.spawnHook;\n\tconst artifactManager = options?.artifactManager;\n\n\treturn {\n\t\tname: \"bash\",\n\t\tlabel: \"bash\",\n\t\tdescription: `Execute a bash command in the current working directory. Returns stdout and stderr. Output is truncated to last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). If truncated, full output is saved to a temp file. Optionally provide a timeout in seconds.`,\n\t\tparameters: bashSchema,\n\t\texecute: async (\n\t\t\t_toolCallId: string,\n\t\t\t{ command, timeout }: { command: string; timeout?: number },\n\t\t\tsignal?: AbortSignal,\n\t\t\tonUpdate?,\n\t\t) => {\n\t\t\t// Apply command prefix if configured (e.g., \"shopt -s expand_aliases\" for alias support)\n\t\t\tconst resolvedCommand = sanitizeCommand(commandPrefix ? `${commandPrefix}\\n${command}` : command);\n\t\t\tconst spawnContext = resolveSpawnContext(resolvedCommand, cwd, spawnHook);\n\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\t// We'll stream to a file if output gets large\n\t\t\t\tlet spillFilePath: string | undefined;\n\t\t\t\tlet spillArtifactId: string | undefined;\n\t\t\t\tlet spillFileStream: ReturnType<typeof createWriteStream> | undefined;\n\t\t\t\tlet totalBytes = 0;\n\n\t\t\t\t// Keep a rolling buffer of the last chunk for tail truncation\n\t\t\t\tconst chunks: Buffer[] = [];\n\t\t\t\tlet chunksBytes = 0;\n\t\t\t\t// Keep more than we need so we have enough for truncation\n\t\t\t\tconst maxChunksBytes = DEFAULT_MAX_BYTES * 2;\n\n\t\t\t\tconst handleData = (data: Buffer) => {\n\t\t\t\t\ttotalBytes += data.length;\n\n\t\t\t\t\t// Start writing to file once we exceed the threshold\n\t\t\t\t\tif (totalBytes > DEFAULT_MAX_BYTES && !spillFilePath) {\n\t\t\t\t\t\tif (artifactManager) {\n\t\t\t\t\t\t\tconst allocated = artifactManager.allocatePath(\"bash\");\n\t\t\t\t\t\t\tspillFilePath = allocated.path;\n\t\t\t\t\t\t\tspillArtifactId = allocated.id;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tspillFilePath = getTempFilePath();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tspillFileStream = createWriteStream(spillFilePath);\n\t\t\t\t\t\t// Write all buffered chunks to the file\n\t\t\t\t\t\tfor (const chunk of chunks) {\n\t\t\t\t\t\t\tspillFileStream.write(chunk);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// Write to temp file if we have one\n\t\t\t\t\tif (spillFileStream) {\n\t\t\t\t\t\tspillFileStream.write(data);\n\t\t\t\t\t}\n\n\t\t\t\t\t// Keep rolling buffer of recent data\n\t\t\t\t\tchunks.push(data);\n\t\t\t\t\tchunksBytes += data.length;\n\n\t\t\t\t\t// Trim old chunks if buffer is too large\n\t\t\t\t\twhile (chunksBytes > maxChunksBytes && chunks.length > 1) {\n\t\t\t\t\t\tconst removed = chunks.shift()!;\n\t\t\t\t\t\tchunksBytes -= removed.length;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Stream partial output to callback (truncated rolling buffer)\n\t\t\t\t\tif (onUpdate) {\n\t\t\t\t\t\tconst fullBuffer = Buffer.concat(chunks);\n\t\t\t\t\t\tconst fullText = fullBuffer.toString(\"utf-8\");\n\t\t\t\t\t\tconst truncation = truncateTail(fullText);\n\t\t\t\t\t\tonUpdate({\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: truncation.content || \"\" }],\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\ttruncation: truncation.truncated ? truncation : undefined,\n\t\t\t\t\t\t\t\tfullOutputPath: spillFilePath,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\tops.exec(spawnContext.command, spawnContext.cwd, {\n\t\t\t\t\tonData: handleData,\n\t\t\t\t\tsignal,\n\t\t\t\t\ttimeout,\n\t\t\t\t\tenv: spawnContext.env,\n\t\t\t\t})\n\t\t\t\t\t.then(({ exitCode }) => {\n\t\t\t\t\t\t// Close temp file stream\n\t\t\t\t\t\tif (spillFileStream) {\n\t\t\t\t\t\t\tspillFileStream.end();\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Combine all buffered chunks\n\t\t\t\t\t\tconst fullBuffer = Buffer.concat(chunks);\n\t\t\t\t\t\tconst fullOutput = fullBuffer.toString(\"utf-8\");\n\n\t\t\t\t\t\t// Apply tail truncation\n\t\t\t\t\t\tconst truncation = truncateTail(fullOutput);\n\t\t\t\t\t\tlet outputText = truncation.content || \"(no output)\";\n\n\t\t\t\t\t\t// Build details with truncation info\n\t\t\t\t\t\tlet details: BashToolDetails | undefined;\n\n\t\t\t\t\t\tif (truncation.truncated) {\n\t\t\t\t\t\t\tdetails = {\n\t\t\t\t\t\t\t\ttruncation,\n\t\t\t\t\t\t\t\tfullOutputPath: spillFilePath,\n\t\t\t\t\t\t\t\t...(spillArtifactId ? { artifactId: spillArtifactId } : {}),\n\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\t// Build actionable notice\n\t\t\t\t\t\t\tconst startLine = truncation.totalLines - truncation.outputLines + 1;\n\t\t\t\t\t\t\tconst endLine = truncation.totalLines;\n\t\t\t\t\t\t\tconst outputRef = spillArtifactId ? `artifact://${spillArtifactId}` : spillFilePath;\n\n\t\t\t\t\t\t\tif (truncation.lastLinePartial) {\n\t\t\t\t\t\t\t\tconst lastLineSize = formatSize(Buffer.byteLength(fullOutput.split(\"\\n\").pop() || \"\", \"utf-8\"));\n\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing last ${formatSize(truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). Full output: ${outputRef}]`;\n\t\t\t\t\t\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines}. Full output: ${outputRef}]`;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Full output: ${outputRef}]`;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (exitCode !== 0 && exitCode !== null) {\n\t\t\t\t\t\t\toutputText += `\\n\\nCommand exited with code ${exitCode}`;\n\t\t\t\t\t\t\treject(new Error(outputText));\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tresolve({ content: [{ type: \"text\", text: outputText }], details });\n\t\t\t\t\t\t}\n\t\t\t\t\t})\n\t\t\t\t\t.catch((err: Error) => {\n\t\t\t\t\t\t// Close temp file stream\n\t\t\t\t\t\tif (spillFileStream) {\n\t\t\t\t\t\t\tspillFileStream.end();\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Combine all buffered chunks for error output\n\t\t\t\t\t\tconst fullBuffer = Buffer.concat(chunks);\n\t\t\t\t\t\tlet output = fullBuffer.toString(\"utf-8\");\n\n\t\t\t\t\t\tif (err.message === \"aborted\") {\n\t\t\t\t\t\t\tif (output) output += \"\\n\\n\";\n\t\t\t\t\t\t\toutput += \"Command aborted\";\n\t\t\t\t\t\t\treject(new Error(output));\n\t\t\t\t\t\t} else if (err.message.startsWith(\"timeout:\")) {\n\t\t\t\t\t\t\tconst timeoutSecs = err.message.split(\":\")[1];\n\t\t\t\t\t\t\tif (output) output += \"\\n\\n\";\n\t\t\t\t\t\t\toutput += `Command timed out after ${timeoutSecs} seconds`;\n\t\t\t\t\t\t\treject(new Error(output));\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\treject(err);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t});\n\t\t},\n\t};\n}\n\n/** Default bash tool using process.cwd() - for backwards compatibility */\nexport const bashTool = createBashTool(process.cwd());\n"]}
1
+ {"version":3,"file":"bash.js","sourceRoot":"","sources":["../../../src/core/tools/bash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAA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AAC;wBAC/B,IAAI,MAAM;4BAAE,MAAM,IAAI,MAAM,CAAC;wBAC7B,MAAM,IAAI,iBAAiB,CAAC;wBAC5B,MAAM,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;oBAC3B,CAAC;yBAAM,IAAI,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;wBAC/C,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;wBAC9C,IAAI,MAAM;4BAAE,MAAM,IAAI,MAAM,CAAC;wBAC7B,MAAM,IAAI,2BAA2B,WAAW,UAAU,CAAC;wBAC3D,MAAM,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;oBAC3B,CAAC;yBAAM,CAAC;wBACP,MAAM,CAAC,GAAG,CAAC,CAAC;oBACb,CAAC;gBACF,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACJ,CAAC;KACD,CAAC;AACH,CAAC;AAED,0EAA0E;AAC1E,MAAM,CAAC,MAAM,QAAQ,GAAG,cAAc,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC","sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport { createWriteStream, existsSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport type { AgentTool } from \"@gsd/pi-agent-core\";\nimport { type Static, Type } from \"@sinclair/typebox\";\nimport { spawn } from \"child_process\";\nimport { getShellConfig, getShellEnv, killProcessTree, sanitizeCommand } from \"../../utils/shell.js\";\nimport { type BashInterceptorRule, compileInterceptor, DEFAULT_BASH_INTERCEPTOR_RULES } from \"./bash-interceptor.js\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult, truncateTail } from \"./truncate.js\";\nimport type { ArtifactManager } from \"../artifact-manager.js\";\n\n// Cached Win32 FFI handles for restoring VT input after child processes\nlet _vtHandles: { GetConsoleMode: any; SetConsoleMode: any; handle: any } | null = null;\nfunction restoreWindowsVTInput(): void {\n\tif (process.platform !== \"win32\") return;\n\ttry {\n\t\tif (!_vtHandles) {\n\t\t\tconst cjsRequire = createRequire(import.meta.url);\n\t\t\tconst koffi = cjsRequire(\"koffi\");\n\t\t\tconst k32 = koffi.load(\"kernel32.dll\");\n\t\t\tconst GetStdHandle = k32.func(\"void* __stdcall GetStdHandle(int)\");\n\t\t\tconst GetConsoleMode = k32.func(\"bool __stdcall GetConsoleMode(void*, _Out_ uint32_t*)\");\n\t\t\tconst SetConsoleMode = k32.func(\"bool __stdcall SetConsoleMode(void*, uint32_t)\");\n\t\t\tconst handle = GetStdHandle(-10);\n\t\t\t_vtHandles = { GetConsoleMode, SetConsoleMode, handle };\n\t\t}\n\t\tconst ENABLE_VIRTUAL_TERMINAL_INPUT = 0x0200;\n\t\tconst mode = new Uint32Array(1);\n\t\t_vtHandles.GetConsoleMode(_vtHandles.handle, mode);\n\t\tif (!(mode[0]! & ENABLE_VIRTUAL_TERMINAL_INPUT)) {\n\t\t\t_vtHandles.SetConsoleMode(_vtHandles.handle, mode[0]! | ENABLE_VIRTUAL_TERMINAL_INPUT);\n\t\t}\n\t} catch { /* koffi not available */ }\n}\n\n/**\n * Generate a unique temp file path for bash output\n */\nfunction getTempFilePath(): string {\n\tconst id = randomBytes(8).toString(\"hex\");\n\treturn join(tmpdir(), `pi-bash-${id}.log`);\n}\n\nconst bashSchema = Type.Object({\n\tcommand: Type.String({ description: \"Bash command to execute\" }),\n\ttimeout: Type.Optional(Type.Number({ description: \"Timeout in seconds (optional, no default timeout)\" })),\n});\n\nexport type BashToolInput = Static<typeof bashSchema>;\n\nexport interface BashToolDetails {\n\ttruncation?: TruncationResult;\n\tfullOutputPath?: string;\n\tartifactId?: string;\n}\n\n/**\n * Pluggable operations for the bash tool.\n * Override these to delegate command execution to remote systems (e.g., SSH).\n */\nexport interface BashOperations {\n\t/**\n\t * Execute a command and stream output.\n\t * @param command - The command to execute\n\t * @param cwd - Working directory\n\t * @param options - Execution options\n\t * @returns Promise resolving to exit code (null if killed)\n\t */\n\texec: (\n\t\tcommand: string,\n\t\tcwd: string,\n\t\toptions: {\n\t\t\tonData: (data: Buffer) => void;\n\t\t\tsignal?: AbortSignal;\n\t\t\ttimeout?: number;\n\t\t\tenv?: NodeJS.ProcessEnv;\n\t\t},\n\t) => Promise<{ exitCode: number | null }>;\n}\n\n/**\n * Default bash operations using local shell\n */\nconst defaultBashOperations: BashOperations = {\n\texec: (command, cwd, { onData, signal, timeout, env }) => {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst { shell, args } = getShellConfig();\n\n\t\t\tif (!existsSync(cwd)) {\n\t\t\t\treject(new Error(`Working directory does not exist: ${cwd}\\nCannot execute bash commands.`));\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst child = spawn(shell, [...args, command], {\n\t\t\t\tcwd,\n\t\t\t\tdetached: true,\n\t\t\t\tenv: env ?? getShellEnv(),\n\t\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t\t});\n\n\t\t\tlet timedOut = false;\n\n\t\t\t// Set timeout if provided\n\t\t\tlet timeoutHandle: NodeJS.Timeout | undefined;\n\t\t\tif (timeout !== undefined && timeout > 0) {\n\t\t\t\ttimeoutHandle = setTimeout(() => {\n\t\t\t\t\ttimedOut = true;\n\t\t\t\t\tif (child.pid) {\n\t\t\t\t\t\tkillProcessTree(child.pid);\n\t\t\t\t\t}\n\t\t\t\t}, timeout * 1000);\n\t\t\t}\n\n\t\t\t// Stream stdout and stderr\n\t\t\tif (child.stdout) {\n\t\t\t\tchild.stdout.on(\"data\", onData);\n\t\t\t}\n\t\t\tif (child.stderr) {\n\t\t\t\tchild.stderr.on(\"data\", onData);\n\t\t\t}\n\n\t\t\t// Handle shell spawn errors\n\t\t\tchild.on(\"error\", (err) => {\n\t\t\t\tif (timeoutHandle) clearTimeout(timeoutHandle);\n\t\t\t\tif (signal) signal.removeEventListener(\"abort\", onAbort);\n\t\t\t\treject(err);\n\t\t\t});\n\n\t\t\t// Handle abort signal - kill entire process tree\n\t\t\tconst onAbort = () => {\n\t\t\t\tif (child.pid) {\n\t\t\t\t\tkillProcessTree(child.pid);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tif (signal) {\n\t\t\t\tif (signal.aborted) {\n\t\t\t\t\tonAbort();\n\t\t\t\t} else {\n\t\t\t\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Handle process exit\n\t\t\tchild.on(\"close\", (code) => {\n\t\t\t\trestoreWindowsVTInput();\n\t\t\t\tif (timeoutHandle) clearTimeout(timeoutHandle);\n\t\t\t\tif (signal) signal.removeEventListener(\"abort\", onAbort);\n\n\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\treject(new Error(\"aborted\"));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (timedOut) {\n\t\t\t\t\treject(new Error(`timeout:${timeout}`));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tresolve({ exitCode: code });\n\t\t\t});\n\t\t});\n\t},\n};\n\nexport interface BashSpawnContext {\n\tcommand: string;\n\tcwd: string;\n\tenv: NodeJS.ProcessEnv;\n}\n\nexport type BashSpawnHook = (context: BashSpawnContext) => BashSpawnContext;\n\nfunction resolveSpawnContext(command: string, cwd: string, spawnHook?: BashSpawnHook): BashSpawnContext {\n\tconst baseContext: BashSpawnContext = {\n\t\tcommand,\n\t\tcwd,\n\t\tenv: { ...getShellEnv() },\n\t};\n\n\treturn spawnHook ? spawnHook(baseContext) : baseContext;\n}\n\nexport interface BashToolOptions {\n\t/** Custom operations for command execution. Default: local shell */\n\toperations?: BashOperations;\n\t/** Command prefix prepended to every command (e.g., \"shopt -s expand_aliases\" for alias support) */\n\tcommandPrefix?: string;\n\t/** Hook to adjust command, cwd, or env before execution */\n\tspawnHook?: BashSpawnHook;\n\t/** Session-scoped artifact storage. When provided, spills to artifact files instead of temp files. */\n\tartifactManager?: ArtifactManager;\n\t/** Bash interceptor configuration — blocks commands that duplicate dedicated tools */\n\tinterceptor?: {\n\t\tenabled: boolean;\n\t\trules?: BashInterceptorRule[];\n\t};\n\t/** Tool names available in the session, used by the interceptor to check if replacement tools exist */\n\tavailableToolNames?: string[] | (() => string[]);\n}\n\nexport function createBashTool(cwd: string, options?: BashToolOptions): AgentTool<typeof bashSchema> {\n\tconst ops = options?.operations ?? defaultBashOperations;\n\tconst commandPrefix = options?.commandPrefix;\n\tconst spawnHook = options?.spawnHook;\n\tconst artifactManager = options?.artifactManager;\n\n\t// Pre-compile interceptor rules once at construction time\n\tconst interceptorInstance =\n\t\toptions?.interceptor?.enabled\n\t\t\t? compileInterceptor(options.interceptor.rules ?? DEFAULT_BASH_INTERCEPTOR_RULES)\n\t\t\t: null;\n\n\treturn {\n\t\tname: \"bash\",\n\t\tlabel: \"bash\",\n\t\tdescription: `Execute a bash command in the current working directory. Returns stdout and stderr. Output is truncated to last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). If truncated, full output is saved to a temp file. Optionally provide a timeout in seconds.`,\n\t\tparameters: bashSchema,\n\t\texecute: async (\n\t\t\t_toolCallId: string,\n\t\t\t{ command, timeout }: { command: string; timeout?: number },\n\t\t\tsignal?: AbortSignal,\n\t\t\tonUpdate?,\n\t\t) => {\n\t\t\t// Check bash interceptor — block commands that duplicate dedicated tools\n\t\t\tif (interceptorInstance) {\n\t\t\t\tconst toolNames =\n\t\t\t\t\ttypeof options!.availableToolNames === \"function\"\n\t\t\t\t\t\t? options!.availableToolNames()\n\t\t\t\t\t\t: options!.availableToolNames ?? [];\n\t\t\t\tconst interception = interceptorInstance.check(command, toolNames);\n\t\t\t\tif (interception.block) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: interception.message ?? \"Command blocked by interceptor\" }],\n\t\t\t\t\t\tdetails: undefined,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Apply command prefix if configured (e.g., \"shopt -s expand_aliases\" for alias support)\n\t\t\tconst resolvedCommand = sanitizeCommand(commandPrefix ? `${commandPrefix}\\n${command}` : command);\n\t\t\tconst spawnContext = resolveSpawnContext(resolvedCommand, cwd, spawnHook);\n\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\t// We'll stream to a file if output gets large\n\t\t\t\tlet spillFilePath: string | undefined;\n\t\t\t\tlet spillArtifactId: string | undefined;\n\t\t\t\tlet spillFileStream: ReturnType<typeof createWriteStream> | undefined;\n\t\t\t\tlet totalBytes = 0;\n\n\t\t\t\t// Keep a rolling buffer of the last chunk for tail truncation\n\t\t\t\tconst chunks: Buffer[] = [];\n\t\t\t\tlet chunksBytes = 0;\n\t\t\t\t// Keep more than we need so we have enough for truncation\n\t\t\t\tconst maxChunksBytes = DEFAULT_MAX_BYTES * 2;\n\n\t\t\t\tconst handleData = (data: Buffer) => {\n\t\t\t\t\ttotalBytes += data.length;\n\n\t\t\t\t\t// Start writing to file once we exceed the threshold\n\t\t\t\t\tif (totalBytes > DEFAULT_MAX_BYTES && !spillFilePath) {\n\t\t\t\t\t\tif (artifactManager) {\n\t\t\t\t\t\t\tconst allocated = artifactManager.allocatePath(\"bash\");\n\t\t\t\t\t\t\tspillFilePath = allocated.path;\n\t\t\t\t\t\t\tspillArtifactId = allocated.id;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tspillFilePath = getTempFilePath();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tspillFileStream = createWriteStream(spillFilePath);\n\t\t\t\t\t\t// Write all buffered chunks to the file\n\t\t\t\t\t\tfor (const chunk of chunks) {\n\t\t\t\t\t\t\tspillFileStream.write(chunk);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// Write to temp file if we have one\n\t\t\t\t\tif (spillFileStream) {\n\t\t\t\t\t\tspillFileStream.write(data);\n\t\t\t\t\t}\n\n\t\t\t\t\t// Keep rolling buffer of recent data\n\t\t\t\t\tchunks.push(data);\n\t\t\t\t\tchunksBytes += data.length;\n\n\t\t\t\t\t// Trim old chunks if buffer is too large\n\t\t\t\t\twhile (chunksBytes > maxChunksBytes && chunks.length > 1) {\n\t\t\t\t\t\tconst removed = chunks.shift()!;\n\t\t\t\t\t\tchunksBytes -= removed.length;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Stream partial output to callback (truncated rolling buffer)\n\t\t\t\t\tif (onUpdate) {\n\t\t\t\t\t\tconst fullBuffer = Buffer.concat(chunks);\n\t\t\t\t\t\tconst fullText = fullBuffer.toString(\"utf-8\");\n\t\t\t\t\t\tconst truncation = truncateTail(fullText);\n\t\t\t\t\t\tonUpdate({\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: truncation.content || \"\" }],\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\ttruncation: truncation.truncated ? truncation : undefined,\n\t\t\t\t\t\t\t\tfullOutputPath: spillFilePath,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\tops.exec(spawnContext.command, spawnContext.cwd, {\n\t\t\t\t\tonData: handleData,\n\t\t\t\t\tsignal,\n\t\t\t\t\ttimeout,\n\t\t\t\t\tenv: spawnContext.env,\n\t\t\t\t})\n\t\t\t\t\t.then(({ exitCode }) => {\n\t\t\t\t\t\t// Close temp file stream\n\t\t\t\t\t\tif (spillFileStream) {\n\t\t\t\t\t\t\tspillFileStream.end();\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Combine all buffered chunks\n\t\t\t\t\t\tconst fullBuffer = Buffer.concat(chunks);\n\t\t\t\t\t\tconst fullOutput = fullBuffer.toString(\"utf-8\");\n\n\t\t\t\t\t\t// Apply tail truncation\n\t\t\t\t\t\tconst truncation = truncateTail(fullOutput);\n\t\t\t\t\t\tlet outputText = truncation.content || \"(no output)\";\n\n\t\t\t\t\t\t// Build details with truncation info\n\t\t\t\t\t\tlet details: BashToolDetails | undefined;\n\n\t\t\t\t\t\tif (truncation.truncated) {\n\t\t\t\t\t\t\tdetails = {\n\t\t\t\t\t\t\t\ttruncation,\n\t\t\t\t\t\t\t\tfullOutputPath: spillFilePath,\n\t\t\t\t\t\t\t\t...(spillArtifactId ? { artifactId: spillArtifactId } : {}),\n\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\t// Build actionable notice\n\t\t\t\t\t\t\tconst startLine = truncation.totalLines - truncation.outputLines + 1;\n\t\t\t\t\t\t\tconst endLine = truncation.totalLines;\n\t\t\t\t\t\t\tconst outputRef = spillArtifactId ? `artifact://${spillArtifactId}` : spillFilePath;\n\n\t\t\t\t\t\t\tif (truncation.lastLinePartial) {\n\t\t\t\t\t\t\t\tconst lastLineSize = formatSize(Buffer.byteLength(fullOutput.split(\"\\n\").pop() || \"\", \"utf-8\"));\n\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing last ${formatSize(truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). Full output: ${outputRef}]`;\n\t\t\t\t\t\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines}. Full output: ${outputRef}]`;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Full output: ${outputRef}]`;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (exitCode !== 0 && exitCode !== null) {\n\t\t\t\t\t\t\toutputText += `\\n\\nCommand exited with code ${exitCode}`;\n\t\t\t\t\t\t\treject(new Error(outputText));\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tresolve({ content: [{ type: \"text\", text: outputText }], details });\n\t\t\t\t\t\t}\n\t\t\t\t\t})\n\t\t\t\t\t.catch((err: Error) => {\n\t\t\t\t\t\t// Close temp file stream\n\t\t\t\t\t\tif (spillFileStream) {\n\t\t\t\t\t\t\tspillFileStream.end();\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Combine all buffered chunks for error output\n\t\t\t\t\t\tconst fullBuffer = Buffer.concat(chunks);\n\t\t\t\t\t\tlet output = fullBuffer.toString(\"utf-8\");\n\n\t\t\t\t\t\tif (err.message === \"aborted\") {\n\t\t\t\t\t\t\tif (output) output += \"\\n\\n\";\n\t\t\t\t\t\t\toutput += \"Command aborted\";\n\t\t\t\t\t\t\treject(new Error(output));\n\t\t\t\t\t\t} else if (err.message.startsWith(\"timeout:\")) {\n\t\t\t\t\t\t\tconst timeoutSecs = err.message.split(\":\")[1];\n\t\t\t\t\t\t\tif (output) output += \"\\n\\n\";\n\t\t\t\t\t\t\toutput += `Command timed out after ${timeoutSecs} seconds`;\n\t\t\t\t\t\t\treject(new Error(output));\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\treject(err);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t});\n\t\t},\n\t};\n}\n\n/** Default bash tool using process.cwd() - for backwards compatibility */\nexport const bashTool = createBashTool(process.cwd());\n"]}
@@ -1,4 +1,5 @@
1
1
  export { type BashOperations, type BashSpawnContext, type BashSpawnHook, type BashToolDetails, type BashToolInput, type BashToolOptions, bashTool, createBashTool, } from "./bash.js";
2
+ export { type BashInterceptorRule, checkBashInterception, type CompiledInterceptor, compileInterceptor, DEFAULT_BASH_INTERCEPTOR_RULES, type InterceptionResult, } from "./bash-interceptor.js";
2
3
  export { createEditTool, type EditOperations, type EditToolDetails, type EditToolInput, type EditToolOptions, editTool, } from "./edit.js";
3
4
  export { createFindTool, type FindOperations, type FindToolDetails, type FindToolInput, type FindToolOptions, findTool, } from "./find.js";
4
5
  export { createGrepTool, type GrepOperations, type GrepToolDetails, type GrepToolInput, type GrepToolOptions, grepTool, } from "./grep.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,QAAQ,EACR,cAAc,GACd,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,cAAc,EACd,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,QAAQ,GACR,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,cAAc,EACd,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,QAAQ,GACR,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,cAAc,EACd,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,QAAQ,GACR,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,YAAY,EACZ,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,MAAM,GACN,MAAM,SAAS,CAAC;AACjB,OAAO,EACN,cAAc,EACd,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,QAAQ,GACR,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EACV,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,YAAY,EACZ,YAAY,EACZ,YAAY,GACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EACN,eAAe,EACf,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,SAAS,GACT,MAAM,YAAY,CAAC;AACpB,OAAO,EACN,sBAAsB,EACtB,KAAK,i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Y,GAAG,IAAI,EAAE,CAOrF"}
@@ -1,4 +1,5 @@
1
1
  export { bashTool, createBashTool, } from "./bash.js";
2
+ export { checkBashInterception, compileInterceptor, DEFAULT_BASH_INTERCEPTOR_RULES, } from "./bash-interceptor.js";
2
3
  export { createEditTool, editTool, } from "./edit.js";
3
4
  export { createFindTool, findTool, } from "./find.js";
4
5
  export { createGrepTool, grepTool, } from "./grep.js";