MCPcopy Create free account
hub / github.com/compozy/agh / newToolApproveCommand

Function newToolApproveCommand

internal/cli/tool_operator.go:174–222  ·  view source on GitHub ↗
(deps commandDeps)

Source from the content-addressed store, hash-verified

172}
173
174func newToolApproveCommand(deps commandDeps) *cobra.Command {
175 var flags toolApprovalFlags
176 cmd := &cobra.Command{
177 Use: "approve <tool_id>",
178 Short: "Mint a one-shot approval token for one tool invocation",
179 Args: exactOneNonBlankArg(),
180 RunE: func(cmd *cobra.Command, args []string) error {
181 id, err := parseToolIDArg(args[0])
182 if err != nil {
183 return writeToolCommandError(cmd, err)
184 }
185 input, err := resolveToolApprovalInput(cmd, flags)
186 if err != nil {
187 return writeToolCommandError(cmd, toolValidationCommandError(id, "tool approval input is invalid", err))
188 }
189 if strings.TrimSpace(flags.scope.sessionID) == "" {
190 return writeToolCommandError(cmd, toolValidationCommandError(
191 id,
192 "tool approval scope is invalid",
193 toolspkg.NewValidationError(
194 "session_id",
195 toolspkg.ReasonSchemaInvalid,
196 "session id is required",
197 ),
198 ))
199 }
200 return runToolCommand(cmd, deps, func(client DaemonClient) error {
201 request := ToolApprovalRequest{
202 SessionID: strings.TrimSpace(flags.scope.sessionID),
203 WorkspaceID: strings.TrimSpace(flags.scope.workspaceID),
204 AgentName: strings.TrimSpace(flags.scope.agentName),
205 Input: input,
206 InputDigest: strings.TrimSpace(flags.inputDigest),
207 }
208 approval, err := client.CreateToolApproval(cmd.Context(), id.String(), request)
209 if err != nil {
210 return err
211 }
212 return writeCommandOutput(cmd, toolApprovalBundle(approval))
213 })
214 },
215 }
216 flags.scope.bind(cmd)
217 cmd.Flags().StringVar(&flags.input, "input", "", "Inline JSON input")
218 cmd.Flags().StringVar(&flags.inputFile, "input-file", "", "Path to JSON input file, or '-' for stdin")
219 cmd.Flags().StringVar(&flags.inputDigest, "input-digest", "", "Precomputed input digest")
220 mustMarkFlagRequired(cmd, "session")
221 return cmd
222}
223
224func newToolInvokeCommand(deps commandDeps) *cobra.Command {
225 var flags toolInvokeFlags

Callers 1

newToolCommandFunction · 0.85

Calls 12

exactOneNonBlankArgFunction · 0.85
parseToolIDArgFunction · 0.85
writeToolCommandErrorFunction · 0.85
resolveToolApprovalInputFunction · 0.85
runToolCommandFunction · 0.85
writeCommandOutputFunction · 0.85
toolApprovalBundleFunction · 0.85
mustMarkFlagRequiredFunction · 0.85
CreateToolApprovalMethod · 0.65
StringMethod · 0.45
bindMethod · 0.45

Tested by

no test coverage detected