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:, workspace_targets: nil) ⇒ GitCommit
constructor
A new instance of GitCommit.
Methods inherited from Base
Constructor Details
#initialize(committer:, workspace_targets: nil) ⇒ GitCommit
Returns a new instance of GitCommit.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/kward/tools/git_commit.rb', line 8 def initialize(committer:, workspace_targets: nil) @committer = committer @workspace_targets = workspace_targets properties = { message: { type: "string", description: "Commit message." }, paths: { type: "array", items: { type: "string" }, description: "Optional workspace-relative paths to include." } } properties = workspace_targets.properties(properties) if workspace_targets super( "git_commit", "Stage and commit changes in the selected worktree (active by default). Omit paths to include all current changes.", properties: properties, required: ["message"] ) end |
Instance Method Details
#call(args, _conversation, cancellation: nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/kward/tools/git_commit.rb', line 24 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? target = @workspace_targets&.target_name(args) = { message: , paths: paths } [:target] = target if target && target != WorkspaceTargets::ACTIVE result = @committer.call(**) 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 |