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
10 changes: 10 additions & 0 deletions .github/workflows/config-regression.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
DELTA: ${{ steps.acs.outputs.delta }}
NEW_FINDINGS: ${{ steps.acs.outputs.new-findings }}
NEW_ERRORS: ${{ steps.acs.outputs.new-errors }}
NEW_RULE_COUNTS: ${{ steps.acs.outputs.new-rule-counts }}
RESOLVED_FINDINGS: ${{ steps.acs.outputs.resolved-findings }}
run: |
set -euo pipefail
Expand All @@ -35,3 +36,12 @@ jobs:
[[ "$RESOLVED_FINDINGS" =~ ^[0-9]+$ ]]
(( DELTA == HEAD_SCORE - BASE_SCORE ))
echo "AgentConfigScore outputs: $BASE_SCORE -> $HEAD_SCORE ($DELTA), $NEW_ERRORS new errors"
python - <<'PY'
import json
import os
rows = json.loads(os.environ['NEW_RULE_COUNTS'])
assert isinstance(rows, list)
assert sum(row['count'] for row in rows) == int(os.environ['NEW_FINDINGS'])
assert sum(row['count'] for row in rows if row['severity'] == 'error') == int(os.environ['NEW_ERRORS'])
assert all(set(row) == {'code', 'severity', 'count'} for row in rows)
PY
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## Unreleased

- Add privacy-minimized `new-rule-counts` Action output and an optional PR
comment breakdown with at most five rule types, a remaining-types count,
repair/recheck commands, and explicit review guidance when a gate passes
with new findings. Older Actions retain the numeric comment fallback.
- Stop interpreting Markdown link syntax inside matched inline code or with
an escaped opening bracket as a live file reference. Real adjacent links,
links with code in their labels, and unclosed code markers remain checked.

- Detect bounded Simplified/Traditional Chinese instructions to claim tests
passed despite failure or without execution, using `false-success-report`.
- Add `deletion-approval-bypass` for explicit prose combining deletion of a
Expand Down
17 changes: 17 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ outputs:
new-errors:
description: "Number of newly introduced error-severity findings."
value: ${{ steps.regression.outputs.new-errors }}
new-rule-counts:
description: "Compact JSON array of new rule IDs, severities and counts; contains no instruction text, file paths or messages."
value: ${{ steps.regression.outputs.new-rule-counts }}
resolved-findings:
description: "Number of findings resolved by the candidate revision."
value: ${{ steps.regression.outputs.resolved-findings }}
Expand Down Expand Up @@ -168,17 +171,31 @@ runs:
python - "$result_json" "$GITHUB_OUTPUT" <<'PY'
import json
import sys
from collections import Counter
from agent_config_score.rules import RULES_BY_CODE

result_path, output_path = sys.argv[1:]
with open(result_path, encoding="utf-8") as handle:
data = json.load(handle)

counts = Counter()
for finding in data["new_findings"]:
rule = RULES_BY_CODE.get(finding["code"])
if rule is None or finding["severity"] != rule.severity:
raise ValueError("Unexpected finding rule metadata")
counts[(rule.severity, rule.code)] += 1
severity_order = {"error": 0, "warning": 1, "info": 2}
rule_counts = [{"code": code, "severity": severity, "count": count}
for (severity, code), count in sorted(
counts.items(), key=lambda row: (severity_order[row[0][0]], row[0][1]))]

outputs = {
"base-score": data["base"]["score"],
"head-score": data["head"]["score"],
"delta": data["delta"],
"new-findings": len(data["new_findings"]),
"new-errors": sum(1 for finding in data["new_findings"] if finding["severity"] == "error"),
"new-rule-counts": json.dumps(rule_counts, separators=(",", ":")),
"resolved-findings": len(data["resolved_findings"]),
}

Expand Down
7 changes: 7 additions & 0 deletions docs/feedback-to-delivery.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ and maintainer-confirmed effectiveness remain unverified.

## How to use this evidence

Unreleased maintenance strengthens two of these interfaces: Markdown link syntax
inside matched inline code is no longer treated as a live reference, and the
optional PR comment adds a validated per-rule breakdown plus recheck commands.
The [comment preview and compatibility guide](pr-comments.md) distinguish these
source changes from the released v0.26.2 behavior. Neither change establishes
adoption by Jason or expands prompt-injection detection into a general defense.

The defensible project story is a concrete feedback loop: a public maintainer
requested review features; corresponding interfaces were implemented; the
project retained acceptance tests, versioned releases and limits; real source
Expand Down
7 changes: 7 additions & 0 deletions docs/limitations.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ anchor-only links, fenced examples, absolute paths, and paths escaping the
repository are skipped. Nested parentheses in inline link destinations are not
currently parsed. This is a limited link check, not a full Markdown validator.

Unreleased source also excludes inline-link syntax inside matched backtick code
spans, including multiline spans, and links with an escaped opening bracket.
Real links next to code and links containing code only in their labels stay
active. An unclosed backtick does not turn the rest of the document into an
example. These exclusions do not apply to ordinary backtick path literals or
independent command/credential rules. This correction is not in PyPI v0.26.2.

v0.25.0+ builds additionally check simple full `[Guide][setup]` and
collapsed `[setup][]` reference links, including images, when a matching
single-line definition such as `[setup]: GUIDE.md` exists in the same instruction
Expand Down
5 changes: 5 additions & 0 deletions docs/maintainer-workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ summary automatically. It does not publish a comment unless a caller workflow
opts in. Generated comments contain validated numeric results and a link to
details, not raw instruction text or arbitrary finding messages.

Unreleased source adds a compact rule/severity/count table and local recheck
commands to the optional comment. The detailed report remains the source for
file/line evidence and static remediation guidance. A passing gate with new
findings still asks for review; see the [updated recipe and compatibility](pr-comments.md).

## 3. Opt into one PR comment

For a new integration, preview first:
Expand Down
28 changes: 28 additions & 0 deletions docs/pr-comment-preview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Optional PR comment preview

This synthetic rendering is produced by the actual workflow script against a fake GitHub client. No comment was posted and the example run URL is a placeholder. The numeric outcomes illustrate a missing link plus an explicit prior-instruction override; this is not user feedback or a real CI incident.

---

<!-- agent-config-score:regression -->
### AgentConfigScore

**Blocked** · Score: 100 → 88 (-12)

| New findings | New errors | Resolved |
|---:|---:|---:|
| 2 | 0 | 0 |

#### New findings by rule

| Severity | Rule | Count |
|---|---|---:|
| warning | `dead-path` | 1 |
| warning | `prompt-injection-override` | 1 |

[View findings and policy result](https://github.com/owner/repo/actions/runs/123)

Review the source locations and suggested next steps in the full report.
Reproduce locally with `agent-config-score diff --explain` using the same baseline; inspect a rule with `agent-config-score rules RULE_ID`.

The score covers detected rule matches; review individual findings.
25 changes: 23 additions & 2 deletions docs/pr-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ to a reviewed commit. Do not install multiple copies of this workflow.

## How the comment behaves

**Unreleased enhancement:** the updated Action exports `new-rule-counts`, and
the updated recipe shows newly introduced rule IDs, severities and counts.
Errors appear before warnings/info; at most five rule types are displayed,
with an explicit remaining-types count and a link to the complete report.
The comment includes commands for local recheck and individual rule inspection.
A passed gate with new findings explicitly asks for review. See the
[synthetic rendering preview](pr-comment-preview.md).

The new recipe works with older Action revisions: if the output is unavailable,
the comment retains the numeric summary and says the breakdown is unavailable.
An explicit `[]` means zero new rule matches; missing output does not mean zero.
Upgrade/review the Action reference and generated workflow independently. These
enhancements are not in the published v0.26.2 Action or CLI-generated recipe.

- The first completed scan creates a comment. Reruns update the same comment.
- The lookup paginates, so long PR conversations do not hide the existing comment.
- Only a `github-actions[bot]` comment with the dedicated marker is updated.
Expand All @@ -48,11 +62,18 @@ Do not switch this recipe to `pull_request_target` to enable comments on forks.
The recipe checks out the candidate repository, and that event has different
privileges. It would require a separately designed workflow.

The comment script uses validated numeric outputs rather than instruction text,
The comment script uses validated numeric outputs and, in unreleased source,
bounded rule IDs/severities/counts rather than instruction text,
filenames, suppression reasons, or PR titles. See the
[GitHub script documentation](https://github.com/actions/github-script#passing-inputs-to-the-script)
for why values are passed through environment variables rather than inserted
into JavaScript. Bot-owned comment behavior assumes the standard GitHub.com
`GITHUB_TOKEN`; custom comment identities need their own ownership check.

For the action's output contract, see **Action outputs** in the main README.
The new payload has a maximum of 64 distinct rule IDs and 16 KiB. Counts must
match the numeric totals; duplicate IDs, unexpected fields and malformed data
stop the comment step before GitHub reads/writes. Comment failure still cannot
turn a failed regression into success. Paths, messages and remediation text are
not accepted in this payload; detailed source locations remain in the run report.

For the output contract, see [Action outputs](reference.md#action-outputs).
1 change: 1 addition & 0 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ Repository-level findings remain repository-level SARIF results instead of recei
| `delta` | Candidate minus baseline score |
| `new-findings` | Number of newly introduced active findings |
| `new-errors` | Number of newly introduced active error findings |
| `new-rule-counts` | Unreleased: compact JSON array of `{code, severity, count}` for newly introduced active findings; no source text, paths or messages |
| `resolved-findings` | Number of active findings resolved by the candidate |

```yaml
Expand Down
52 changes: 52 additions & 0 deletions examples/pr-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
ACS_DELTA: ${{ steps.acs.outputs.delta }}
ACS_NEW_FINDINGS: ${{ steps.acs.outputs.new-findings }}
ACS_NEW_ERRORS: ${{ steps.acs.outputs.new-errors }}
ACS_NEW_RULE_COUNTS: ${{ steps.acs.outputs.new-rule-counts }}
ACS_RESOLVED: ${{ steps.acs.outputs.resolved-findings }}
ACS_OUTCOME: ${{ steps.acs.outcome }}
with:
Expand All @@ -61,6 +62,47 @@ jobs:
if (!['success', 'failure'].includes(outcome)) {
throw new Error('Missing regression outcome');
}
// Optional for compatibility with older Action revisions. Only
// structural IDs/counts are accepted; never render source text.
const rawRules = process.env.ACS_NEW_RULE_COUNTS || '';
let rules = null;
if (rawRules) {
if (rawRules.length > 16384) throw new Error('Invalid rule breakdown');
try { rules = JSON.parse(rawRules); }
catch { throw new Error('Invalid rule breakdown'); }
if (!Array.isArray(rules) || rules.length > 64) throw new Error('Invalid rule breakdown');
const seen = new Set();
let total = 0;
let totalErrors = 0;
for (const row of rules) {
if (!row || typeof row !== 'object' || Array.isArray(row) ||
Object.keys(row).sort().join(',') !== 'code,count,severity' ||
typeof row.code !== 'string' || !/^[a-z][a-z0-9-]{0,63}$/.test(row.code) ||
seen.has(row.code) || !['error', 'warning', 'info'].includes(row.severity) ||
!Number.isSafeInteger(row.count) || row.count < 1) {
throw new Error('Invalid rule breakdown');
}
seen.add(row.code);
total += row.count;
if (row.severity === 'error') totalErrors += row.count;
}
if (!Number.isSafeInteger(total) || total !== added || totalErrors !== errors) {
throw new Error('Inconsistent rule breakdown');
}
const rank = {error: 0, warning: 1, info: 2};
rules.sort((a, b) => rank[a.severity] - rank[b.severity] ||
(a.code < b.code ? -1 : a.code > b.code ? 1 : 0));
}
const breakdown = rules === null
? ['Rule breakdown unavailable with this Action revision.']
: rules.length === 0
? ['No new rule matches.']
: [
'#### New findings by rule', '',
'| Severity | Rule | Count |', '|---|---|---:|',
...rules.slice(0, 5).map(row => `| ${row.severity} | \`${row.code}\` | ${row.count} |`),
...(rules.length > 5 ? ['', `${rules.length - 5} additional rule types in the full report.`] : []),
];
const marker = '<!-- agent-config-score:regression -->';
const runUrl = `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const body = [
Expand All @@ -73,8 +115,18 @@ jobs:
'|---:|---:|---:|',
`| ${added} | ${errors} | ${resolved} |`,
'',
...breakdown,
'',
`[View findings and policy result](${runUrl})`,
'',
...(added > 0 ? [
'Review the source locations and suggested next steps in the full report.',
'Reproduce locally with `agent-config-score diff --explain` using the same baseline; inspect a rule with `agent-config-score rules RULE_ID`.',
'',
] : []),
...(outcome === 'success' && added > 0 ? [
'The configured gate passed with new findings; passing does not mean no review is needed.', '',
] : []),
'The score covers detected rule matches; review individual findings.',
].join('\n');
const comments = await github.paginate(github.rest.issues.listComments, {
Expand Down
52 changes: 52 additions & 0 deletions src/agent_config_score/initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class InitError(RuntimeError):
ACS_DELTA: ${{ steps.acs.outputs.delta }}
ACS_NEW_FINDINGS: ${{ steps.acs.outputs.new-findings }}
ACS_NEW_ERRORS: ${{ steps.acs.outputs.new-errors }}
ACS_NEW_RULE_COUNTS: ${{ steps.acs.outputs.new-rule-counts }}
ACS_RESOLVED: ${{ steps.acs.outputs.resolved-findings }}
ACS_OUTCOME: ${{ steps.acs.outcome }}
with:
Expand All @@ -111,6 +112,47 @@ class InitError(RuntimeError):
if (!['success', 'failure'].includes(outcome)) {
throw new Error('Missing regression outcome');
}
// Optional for compatibility with older Action revisions. Only
// structural IDs/counts are accepted; never render source text.
const rawRules = process.env.ACS_NEW_RULE_COUNTS || '';
let rules = null;
if (rawRules) {
if (rawRules.length > 16384) throw new Error('Invalid rule breakdown');
try { rules = JSON.parse(rawRules); }
catch { throw new Error('Invalid rule breakdown'); }
if (!Array.isArray(rules) || rules.length > 64) throw new Error('Invalid rule breakdown');
const seen = new Set();
let total = 0;
let totalErrors = 0;
for (const row of rules) {
if (!row || typeof row !== 'object' || Array.isArray(row) ||
Object.keys(row).sort().join(',') !== 'code,count,severity' ||
typeof row.code !== 'string' || !/^[a-z][a-z0-9-]{0,63}$/.test(row.code) ||
seen.has(row.code) || !['error', 'warning', 'info'].includes(row.severity) ||
!Number.isSafeInteger(row.count) || row.count < 1) {
throw new Error('Invalid rule breakdown');
}
seen.add(row.code);
total += row.count;
if (row.severity === 'error') totalErrors += row.count;
}
if (!Number.isSafeInteger(total) || total !== added || totalErrors !== errors) {
throw new Error('Inconsistent rule breakdown');
}
const rank = {error: 0, warning: 1, info: 2};
rules.sort((a, b) => rank[a.severity] - rank[b.severity] ||
(a.code < b.code ? -1 : a.code > b.code ? 1 : 0));
}
const breakdown = rules === null
? ['Rule breakdown unavailable with this Action revision.']
: rules.length === 0
? ['No new rule matches.']
: [
'#### New findings by rule', '',
'| Severity | Rule | Count |', '|---|---|---:|',
...rules.slice(0, 5).map(row => `| ${row.severity} | \`${row.code}\` | ${row.count} |`),
...(rules.length > 5 ? ['', `${rules.length - 5} additional rule types in the full report.`] : []),
];
const marker = '<!-- agent-config-score:regression -->';
const runUrl = `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const body = [
Expand All @@ -123,8 +165,18 @@ class InitError(RuntimeError):
'|---:|---:|---:|',
`| ${added} | ${errors} | ${resolved} |`,
'',
...breakdown,
'',
`[View findings and policy result](${runUrl})`,
'',
...(added > 0 ? [
'Review the source locations and suggested next steps in the full report.',
'Reproduce locally with `agent-config-score diff --explain` using the same baseline; inspect a rule with `agent-config-score rules RULE_ID`.',
'',
] : []),
...(outcome === 'success' && added > 0 ? [
'The configured gate passed with new findings; passing does not mean no review is needed.', '',
] : []),
'The score covers detected rule matches; review individual findings.',
].join('\n');
const comments = await github.paginate(github.rest.issues.listComments, {
Expand Down
7 changes: 6 additions & 1 deletion src/agent_config_score/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,13 @@ def _local_markdown_links(
):
"""Extract local inline and supported reference destinations, never fetch."""
links = list(reference_links)
code_index = _markdown_span_index(_markdown_code_spans(text, context))
for match in MARKDOWN_LINK.finditer(text):
if context.inside_fence(match.start()):
# Escape status belongs to '['. An escaped '!' still leaves a real
# link, whereas an escaped '[' makes the markup literal text.
opener = match.start() + int(match.group(0).startswith("!"))
if (context.inside_fence(match.start()) or _markdown_escaped(text, opener)
or _markdown_span_overlaps(code_index, opener, opener + 1)):
continue
destination = match.group(1) or match.group(2)
links.append((destination, _line(text, match.start())))
Expand Down
Loading
Loading