MCPcopy Create free account
hub / github.com/github/gh-aw / generateToolsMetaJSON

Function generateToolsMetaJSON

pkg/workflow/safe_outputs_tools_generation.go:268–336  ·  view source on GitHub ↗

generateToolsMetaJSON generates the content for tools_meta.json: a compact file that captures the workflow-specific customisations (description constraints, repo parameters, dynamic tools) without inlining the entire safe_outputs_tools.json into the compiled workflow YAML. At runtime, generate_safe

(data *WorkflowData, markdownPath string)

Source from the content-addressed store, hash-verified

266// the actions folder, applies the meta overrides from tools_meta.json, and writes
267// the final ${RUNNER_TEMP}/gh-aw/safeoutputs/tools.json.
268func generateToolsMetaJSON(data *WorkflowData, markdownPath string) (string, error) {
269 if data.SafeOutputs == nil {
270 empty := ToolsMeta{
271 DescriptionSuffixes: map[string]string{},
272 RepoParams: map[string]map[string]any{},
273 DynamicTools: []map[string]any{},
274 }
275 result, err := json.Marshal(empty)
276 if err != nil {
277 return "", fmt.Errorf("failed to marshal empty tools meta: %w", err)
278 }
279 return string(result), nil
280 }
281
282 safeOutputsConfigLog.Print("Generating tools meta JSON for workflow")
283
284 enabledTools := computeEnabledToolNames(data)
285
286 // Compute description suffix for each enabled predefined tool.
287 // enhanceToolDescription with an empty base returns just the constraint text
288 // (e.g. " CONSTRAINTS: Maximum 5 issue(s).") so JavaScript can append it.
289 descriptionSuffixes := make(map[string]string)
290 for toolName := range enabledTools {
291 suffix := enhanceToolDescription(toolName, "", data.SafeOutputs)
292 if suffix != "" {
293 descriptionSuffixes[toolName] = suffix
294 }
295 }
296
297 // Compute repo parameter definition for each tool that needs it.
298 repoParams := make(map[string]map[string]any)
299 for toolName := range enabledTools {
300 if param := computeRepoParamForTool(toolName, data.SafeOutputs); param != nil {
301 repoParams[toolName] = param
302 }
303 }
304
305 // Generate dynamic tool definitions (custom jobs + dispatch/call workflow tools).
306 dynamicTools, err := generateDynamicTools(data, markdownPath)
307 if err != nil {
308 safeOutputsConfigLog.Printf("Error generating dynamic tools: %v", err)
309 dynamicTools = []map[string]any{}
310 }
311 if dynamicTools == nil {
312 dynamicTools = []map[string]any{}
313 }
314
315 // Compute required field removals (e.g. body when allow-body: false).
316 requiredFieldRemovals := computeRequiredFieldRemovals(data.SafeOutputs)
317 requiredFieldAdditions := computeRequiredFieldAdditions(data.SafeOutputs)
318
319 meta := ToolsMeta{
320 DescriptionSuffixes: descriptionSuffixes,
321 RepoParams: repoParams,
322 DynamicTools: dynamicTools,
323 RequiredFieldRemovals: requiredFieldRemovals,
324 RequiredFieldAdditions: requiredFieldAdditions,
325 }

Calls 9

computeEnabledToolNamesFunction · 0.85
enhanceToolDescriptionFunction · 0.85
computeRepoParamForToolFunction · 0.85
generateDynamicToolsFunction · 0.85
PrintMethod · 0.80
ErrorfMethod · 0.45
PrintfMethod · 0.45

Tested by 1