Class: Kward::Tools::GitCommit
- Defined in:
- lib/kward/tools/git_commit.rb
Overview
Tool wrapper for the trusted host-side Git commit operation.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #call(args, _conversation, cancellation: nil) ⇒ Object
-
#initialize(committer:) ⇒ GitCommit
constructor
A new instance of GitCommit.
Methods inherited from Base
Constructor Details
#initialize(committer:) ⇒ GitCommit
Returns a new instance of GitCommit.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/kward/tools/git_commit.rb', line 8 def initialize(committer:) @committer = committer super( "git_commit", "Stage and commit changes in the active worktree. Omit paths to include all current changes.", properties: { message: { type: "string", description: "Commit message." }, paths: { type: "array", items: { type: "string" }, description: "Optional workspace-relative paths to include." } }, required: ["message"] ) end |
Instance Method Details
#call(args, _conversation, cancellation: nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/kward/tools/git_commit.rb', line 21 def call(args, _conversation, cancellation: nil) cancellation&.raise_if_cancelled! = argument(args, :message, "").to_s paths = argument(args, :paths, nil) return "Error: commit message is required" if .strip.empty? return "Error: paths must be an array" unless paths.nil? || paths.is_a?(Array) return "Error: paths must contain strings" if paths && paths.any? { |path| !path.is_a?(String) } paths = nil if paths&.empty? result = @committer.call(message: , paths: paths) output = result[:output].to_s.strip return "Git commit succeeded\n#{output}" if result[:success] failure = output.empty? ? "Git commit failed." : "Git commit failed.\n#{output}" "Error: #{failure}" end |