Skip to content

Commit d78af91

Browse files
authored
Add support for safe-inputs front matter section (#5090)
1 parent 9b95b86 commit d78af91

21 files changed

+2790
-379
lines changed

.github/workflows/dev.lock.yml

Lines changed: 719 additions & 367 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/dev.md

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,62 @@ name: Dev
55
description: Test workflow for development and experimentation purposes
66
timeout-minutes: 5
77
strict: false
8-
# Using experimental Claude engine for testing
9-
engine: claude
8+
# Using Codex engine for better error messages
9+
engine: codex
1010
permissions:
1111
contents: read
1212
issues: read
1313
pull-requests: read
1414
discussions: read
15+
imports:
16+
- shared/pr-data-safe-input.md
1517
tools:
1618
bash: ["*"]
1719
edit:
1820
github:
1921
toolsets: [default, repos, issues, discussions]
2022
safe-outputs:
2123
assign-to-agent:
24+
safe-inputs:
25+
test-js-math:
26+
description: "Test JavaScript math operations"
27+
inputs:
28+
a:
29+
type: number
30+
description: "First number"
31+
required: true
32+
b:
33+
type: number
34+
description: "Second number"
35+
required: true
36+
script: |
37+
// Users can write simple code without exports
38+
const sum = a + b;
39+
const product = a * b;
40+
return { sum, product, inputs: { a, b } };
41+
test-js-string:
42+
description: "Test JavaScript string operations"
43+
inputs:
44+
text:
45+
type: string
46+
description: "Input text"
47+
required: true
48+
script: |
49+
// Simple string manipulation
50+
return {
51+
original: text,
52+
uppercase: text.toUpperCase(),
53+
length: text.length
54+
};
2255
---
23-
Assign the most recent unassigned issue to the agent.
56+
Use the `fetch-pr-data` tool to fetch Copilot agent PRs from this repository using `search: "head:copilot/"`. Then compute basic PR statistics:
57+
- Total number of Copilot PRs in the last 30 days
58+
- Number of merged vs closed vs open PRs
59+
- Average time from PR creation to merge (for merged PRs)
60+
- Most active day of the week for PR creation
61+
62+
Also test the JavaScript safe-inputs tools:
63+
1. Call `test-js-math` with a=5 and b=3 to verify math operations work
64+
2. Call `test-js-string` with text="Hello World" to verify string operations work
65+
66+
Present the statistics and test results in a clear summary.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
safe-inputs:
3+
fetch-pr-data:
4+
description: "Fetches pull request data from GitHub using gh CLI. Returns JSON array of PRs with fields: number, title, author, headRefName, createdAt, state, url, body, labels, updatedAt, closedAt, mergedAt"
5+
inputs:
6+
repo:
7+
type: string
8+
description: "Repository in owner/repo format (defaults to current repository)"
9+
required: false
10+
search:
11+
type: string
12+
description: "Search query for filtering PRs (e.g., 'head:copilot/' for Copilot PRs)"
13+
required: false
14+
state:
15+
type: string
16+
description: "PR state filter: open, closed, merged, or all (default: all)"
17+
default: "all"
18+
limit:
19+
type: number
20+
description: "Maximum number of PRs to fetch (default: 100)"
21+
default: 100
22+
days:
23+
type: number
24+
description: "Number of days to look back (default: 30)"
25+
default: 30
26+
run: |
27+
# Fetch PR data using gh CLI
28+
REPO="${INPUT_REPO:-$GITHUB_REPOSITORY}"
29+
STATE="${INPUT_STATE:-all}"
30+
LIMIT="${INPUT_LIMIT:-100}"
31+
DAYS="${INPUT_DAYS:-30}"
32+
SEARCH="${INPUT_SEARCH:-}"
33+
34+
# Calculate date N days ago (cross-platform)
35+
DATE_AGO=$(date -d "${DAYS} days ago" '+%Y-%m-%d' 2>/dev/null || date -v-${DAYS}d '+%Y-%m-%d')
36+
37+
# Build search query
38+
QUERY="created:>=${DATE_AGO}"
39+
if [ -n "$SEARCH" ]; then
40+
QUERY="${SEARCH} ${QUERY}"
41+
fi
42+
43+
# Fetch PRs
44+
gh pr list --repo "$REPO" \
45+
--search "$QUERY" \
46+
--state "$STATE" \
47+
--json number,title,author,headRefName,createdAt,state,url,body,labels,updatedAt,closedAt,mergedAt \
48+
--limit "$LIMIT"
49+
env:
50+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
---
52+
<!--
53+
## PR Data Fetch Safe Input Tool
54+
55+
This shared workflow provides a `fetch-pr-data` safe-input tool that fetches pull request data from GitHub.
56+
57+
### Usage
58+
59+
Import this shared workflow to get access to the `fetch-pr-data` tool:
60+
61+
```yaml
62+
imports:
63+
- shared/pr-data-safe-input.md
64+
```
65+
66+
The agent can then use the tool to fetch PR data:
67+
- `fetch-pr-data` with no arguments returns PRs from the last 30 days
68+
- `fetch-pr-data` with `search: "head:copilot/"` returns Copilot agent PRs
69+
- `fetch-pr-data` with `state: "merged"` returns only merged PRs
70+
71+
### Parameters
72+
73+
| Parameter | Type | Default | Description |
74+
|-----------|------|---------|-------------|
75+
| repo | string | current repo | Repository in owner/repo format |
76+
| search | string | - | Search query (e.g., "head:copilot/") |
77+
| state | string | all | PR state: open, closed, merged, all |
78+
| limit | number | 100 | Maximum PRs to return |
79+
| days | number | 30 | Days to look back |
80+
81+
### Output
82+
83+
Returns JSON array with PR objects containing:
84+
- number, title, author, headRefName
85+
- createdAt, updatedAt, closedAt, mergedAt
86+
- state, url, body, labels
87+
-->

docs/src/content/docs/reference/frontmatter-full.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2444,6 +2444,14 @@ roles: []
24442444
# (optional)
24452445
strict: true
24462446

2447+
# Safe inputs configuration for defining custom lightweight MCP tools as
2448+
# JavaScript or shell scripts. Tools are mounted in an MCP server and have access
2449+
# to secrets specified by the user. Only one of 'script' (JavaScript) or 'run'
2450+
# (shell) must be specified per tool.
2451+
# (optional)
2452+
safe-inputs:
2453+
{}
2454+
24472455
# Runtime environment version overrides. Allows customizing runtime versions
24482456
# (e.g., Node.js, Python) or defining new runtimes. Runtimes from imported shared
24492457
# workflows are also merged.

0 commit comments

Comments
 (0)