summaryrefslogtreecommitdiff
path: root/packages/core/src/tools/shell.ts
diff options
context:
space:
mode:
authormoon jooho <[email protected]>2025-07-04 09:13:02 +0900
committerGitHub <[email protected]>2025-07-04 00:13:02 +0000
commit8d3fec08e59b100da036b685d20b080203ba3a4c (patch)
treefdfb31c69d8cf15a536e650fb0fdd148d14051ae /packages/core/src/tools/shell.ts
parent654f8aeb614c3e5129f33d93aa9cfa06d347e3a0 (diff)
Add and improve JSDoc comments for core tool methods (#3128)
Diffstat (limited to 'packages/core/src/tools/shell.ts')
-rw-r--r--packages/core/src/tools/shell.ts16
1 files changed, 16 insertions, 0 deletions
diff --git a/packages/core/src/tools/shell.ts b/packages/core/src/tools/shell.ts
index bbb998d5..f0a30a9c 100644
--- a/packages/core/src/tools/shell.ts
+++ b/packages/core/src/tools/shell.ts
@@ -89,6 +89,15 @@ Process Group PGID: Process group started or \`(none)\``,
return description;
}
+ /**
+ * Extracts the root command from a given shell command string.
+ * This is used to identify the base command for permission checks.
+ *
+ * @param command The shell command string to parse
+ * @returns The root command name, or undefined if it cannot be determined
+ * @example getCommandRoot("ls -la /tmp") returns "ls"
+ * @example getCommandRoot("git status && npm test") returns "git"
+ */
getCommandRoot(command: string): string | undefined {
return command
.trim() // remove leading and trailing whitespace
@@ -98,6 +107,13 @@ Process Group PGID: Process group started or \`(none)\``,
.pop(); // take last part and return command root (or undefined if previous line was empty)
}
+ /**
+ * Determines whether a given shell command is allowed to execute based on
+ * the tool's configuration including allowlists and blocklists.
+ *
+ * @param command The shell command string to validate
+ * @returns True if the command is allowed to execute, false otherwise
+ */
isCommandAllowed(command: string): boolean {
// 0. Disallow command substitution
if (command.includes('$(') || command.includes('`')) {