Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions pkg/workflow/tool_description_enhancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,33 @@ func submitPullRequestReviewConstraints(config *SubmitPullRequestReviewConfig) [
appendMaxConstraint(constraints, config.Max, "Maximum %d review(s) can be submitted.")
appendTargetConstraint(constraints, config.Target)
appendStringConstraint(constraints, config.TargetRepoSlug, "Reviews will be submitted in repository %q.")
appendAllowedReviewEventsConstraint(constraints, config.AllowedEvents)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the compiled tool description without updating the checked-in generated lock workflows, so the repository can fail its recompile/drift check and affected workflows will continue shipping the old description.

💡 Regenerate the compiled artifacts

Run make recompile and commit the resulting .lock.yml changes alongside this source change; verify the generated diff is intentional.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/codebase-design] This changes the compiled tool description, so committed lock files go stale. Recompiling pr-code-quality-reviewer changed its embedded submit_pull_request_review text, and ponytail-reviewer and pr-specification-reviewer embed the same text. The check-workflow-drift CI job should fail until the locks are regenerated.

💡 Suggested fix

Run make recompile in this PR and commit the regenerated .lock.yml files. Do not leave this to a maintainer, since the drift gate fails CI.

@copilot please address this.

})
}

// reviewEventValues lists every review event the submit_pull_request_review tool schema supports.
var reviewEventValues = []string{"APPROVE", "COMMENT", "REQUEST_CHANGES"}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewEventValues duplicates the supported-event set maintained elsewhere, so adding or renaming a review event can make this guidance claim a valid event is rejected (or omit a newly valid event).

💡 Share the canonical event set

Define one canonical supported-events list and reuse it for parsing/validation, schema generation, and this description constraint. That keeps the agent-facing policy synchronized with runtime enforcement as the enum evolves.

Comment on lines +394 to +395

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/codebase-design] The review event list is now hardcoded in several places. submit_pr_review.go (validEvents) and safe_outputs_validation_config.go (line 394) repeat the same values, and main_workflow_schema.json (line 9493) does too. A future event addition could leave this description out of sync.

💡 Suggested refactor

Define one package-level slice of review events and use it in the parser in submit_pr_review.go and in reviewEventValues. Keep the same order so the rendered text stays stable.

@copilot please address this.


// appendAllowedReviewEventsConstraint tells the agent which review events are permitted when
// allowed-events narrows the set, and explicitly names the excluded ones so the base
// description's references to APPROVE do not mislead the agent into a rejected call.
func appendAllowedReviewEventsConstraint(constraints *[]string, allowedEvents []string) {
if len(allowedEvents) == 0 {
return
}
text := "Allowed review events: " + strings.Join(allowedEvents, ", ") + "."
var excluded []string
for _, event := range reviewEventValues {
if !slices.Contains(allowedEvents, event) {
excluded = append(excluded, event)
}
}
if len(excluded) > 0 {
text += " Events not listed (" + strings.Join(excluded, ", ") + ") are rejected; do not use them."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/diagnosing-bugs] The new sentence is appended after the long WRITE-ONCE preamble, so it falls outside the visible part of the description. safeoutputs submit_pull_request_review --help cuts the description at 90 characters (TOOL_DESC_MAX_LEN in actions/setup/js/mcp_cli_bridge.cjs, line 78). That is the CLI path where the reported call failed, so this fix may not reach it.

💡 Suggested fix

Put the allowed-events sentence before the preamble so its first 90 characters carry the rule. Add a regression test that asserts the rule appears within the first 90 characters. Then confirm the output of safeoutputs submit_pull_request_review --help after recompiling.

@copilot please address this.

}
*constraints = append(*constraints, text)
}

func replyToPullRequestReviewCommentConstraints(config *ReplyToPullRequestReviewCommentConfig) []string {
return buildConstraints(config, func(config *ReplyToPullRequestReviewCommentConfig, constraints *[]string) {
appendMaxConstraint(constraints, config.Max, "Maximum %d reply/replies can be created.")
Expand Down
51 changes: 51 additions & 0 deletions pkg/workflow/tool_description_enhancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,57 @@ func TestEnhanceToolDescriptionSubmitPullRequestReviewTargetRepo(t *testing.T) {
}
}

func TestEnhanceToolDescriptionSubmitPullRequestReviewAllowedEvents(t *testing.T) {
tests := []struct {
name string
allowedEvents []string
wantContains []string
wantAbsent []string
}{
{
name: "APPROVE excluded",
allowedEvents: []string{"COMMENT", "REQUEST_CHANGES"},
wantContains: []string{"Allowed review events: COMMENT, REQUEST_CHANGES.", "(APPROVE) are rejected"},
},
{
name: "only COMMENT allowed",
allowedEvents: []string{"COMMENT"},
wantContains: []string{"Allowed review events: COMMENT.", "(APPROVE, REQUEST_CHANGES) are rejected"},
},
{
name: "all events allowed",
allowedEvents: []string{"APPROVE", "COMMENT", "REQUEST_CHANGES"},
wantContains: []string{"Allowed review events: APPROVE, COMMENT, REQUEST_CHANGES."},
wantAbsent: []string{"are rejected"},
},
{
name: "allowed-events not configured",
wantAbsent: []string{"Allowed review events", "are rejected"},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
description := enhanceToolDescription("submit_pull_request_review", "Submit a PR review.", &SafeOutputsConfig{
SubmitPullRequestReview: &SubmitPullRequestReviewConfig{
BaseSafeOutputConfig: BaseSafeOutputConfig{Max: defaultIntStr(1)},
AllowedEvents: tt.allowedEvents,
},
})
for _, want := range tt.wantContains {
if !strings.Contains(description, want) {
t.Errorf("expected %q in description, got: %s", want, description)
}
}
for _, absent := range tt.wantAbsent {
if strings.Contains(description, absent) {
t.Errorf("did not expect %q in description, got: %s", absent, description)
}
}
})
}
}

func TestEnhanceToolDescriptionNormalizeClosingKeywordsCreateIssue(t *testing.T) {
description := enhanceToolDescription("create_issue", "Create an issue.", &SafeOutputsConfig{
CreateIssues: &CreateIssuesConfig{
Expand Down
Loading