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
48 changes: 27 additions & 21 deletions plugins/magpie-security/skills/issue-import-from-md/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ when_to_use: |
anchor the import on (`security-issue-import-from-pr`).
argument-hint: "[path-to-markdown-file]"
capability: capability:intake
surface_hash: sha256:e2437e84cdf98aa5
surface_hash: sha256:b741b2de80b78093
license: Apache-2.0
measured_tokens: 6282
measured_tokens: 6272
---

<!-- Placeholder convention (see AGENTS.md#placeholder-convention-used-in-skill-files):
Expand Down Expand Up @@ -185,7 +185,7 @@ Only on the user's confirmation run `tracker-publish` with that message file
Before running, the skill needs:

- **`gh` CLI authenticated** with collaborator access to
`<tracker>`. The skill calls `gh api repos/<tracker>/issues`,
`<tracker>`. The skill uses vetted-op `issue-create-labeled`,
`gh search issues`, and vetted-ops' `rollup-append`.
- **Project-board write access** for the `addProjectV2ItemById` /
`updateProjectV2ItemFieldValue` mutations from
Expand Down Expand Up @@ -343,30 +343,35 @@ skill must not stream per-finding confirmations.
For each finding the user did not `skip`, run Steps 5a-5f.
The batch is a serial loop, **not** parallel, so the `gh` calls and board mutations stay within GitHub rate limits.

### 5a — Create the tracker via `gh api`
### 5a — Create the tracker through vetted-ops

Bypasses the form so the `Security mailing list thread` required-field check does not fire.
Same pattern as [`security-issue-import-from-pr`'s](../issue-import-from-pr/SKILL.md#7a--create-the-tracker-via-gh-api) Step 7a.
For each confirmed finding, use `issue-create-labeled`
instead of raw `gh api` or `gh issue create`.

Write the confirmed `render-body` `text` (laid out as in [`tracker-body-template.md`](tracker-body-template.md)) to the body file.
Write the confirmed title, with the Write tool, to
`<scratch>/import-md-<basename>-<index>-title.txt`
and confirmed rendered body to
`<scratch>/import-md-<basename>-<index>-body.md`.

Create it per the safe-create recipe in
[`tools/github/operations.md`](../../../../tools/github/operations.md#create) — the finding title is attacker-controlled.
Title file `<scratch>/import-md-<basename>-<index>-title.txt` with the finding's `tracker_title`;
body file `<scratch>/import-md-<basename>-<index>-body.md`; `labels[]` set to the Step 3c labels in the same call:
For a GitHub tracker:

```bash
gh api repos/<tracker>/issues \
-F title=@<scratch>/import-md-<basename>-<index>-title.txt \
-F body=@<scratch>/import-md-<basename>-<index>-body.md \
-f 'labels[]=needs triage' \
-f 'labels[]=security issue' \
--jq '.number, .node_id, .html_url'
uv run --project ~/.claude/magpie/vetted-ops vetted-op --caller security-issue-import-from-md issue-create-labeled <scratch>/import-md-<basename>-<index>-title.txt <scratch>/import-md-<basename>-<index>-body.md '["needs triage","security issue"]'
```

No scope label, no `pr created` / `pr merged` — those come later in the lifecycle.
The finding title is attacker-controlled, so it travels as a file: the dispatcher reads and validates it, and the shell never sees it.
Keep the command bare, with no `$(…)`, or it runs inside the sandbox and fails.
The body travels through stdin.
The configured security labels are validated and applied atomically at creation.

Capture `number`, `node_id`, `html_url` from the response.
Capture `number`, `node_id`, and `url` from the JSON response.

If creation fails, record the failure for this finding as
required by the existing Step 5 workflow. Never retry using
raw GitHub commands.

For non-GitHub trackers, preserve the existing `issue-create`
backend operation.

### 5b — Apply labels

Expand All @@ -388,7 +393,8 @@ Without the secure setup, see [`backends/vetted-ops.md`](backends/vetted-ops.md)

### 5e — Cleanup (per finding)

Delete `<scratch>/import-md-<basename>-<index>-body.md` and
Delete `<scratch>/import-md-<basename>-<index>-title.txt`,
`<scratch>/import-md-<basename>-<index>-body.md`, and
`<scratch>/import-md-<basename>-<index>-rollup.md` so they do not accumulate.

### 5f — Loop progress
Expand All @@ -400,7 +406,7 @@ see progress on long batches:
[K/N] <tracker>#NNN — <finding title>
```

If a finding's `gh api` call fails (rate limit, transient network error, schema mismatch), surface the failure with the finding's index and continue.
If a finding's vetted issue-creation operation fails (rate limit, transient network error, schema mismatch), surface the failure with the finding's index and continue.
Do **not** abort the batch on the first failure — the user re-invokes for the failed indices once the cause is fixed.

---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
| Symptom | Likely cause | Fix |
|---|---|---|
| File parse yields zero findings | The file uses a different heading level or no `**Severity:**` metadata block | Stop; surface the expected shape from Step 1 and ask the user to reformat. |
| `gh api repos/<tracker>/issues` returns 422 | Title or body field shape doesn't match the issue template | Re-check the body against the eleven `### <field>` headings; the heading text is case-sensitive. |
| `issue-create-labeled` returns a GitHub 422 error | Title or body field shape doesn't match the issue template | Re-check the body against the eleven `### <field>` headings; the heading text is case-sensitive. |
| `addProjectV2ItemById` returns `not found` for the project | Project-board node ID changed in `<project-config>/project.md` | Re-run the introspection query in [`project-board.md`](../../../../tools/github/project-board.md) and update `<project-config>/project.md`. |
| Many possible-duplicate hits surfaced for every finding | The file is a re-scan against an already-triaged branch | Pause; consider whether the right action is `skip` for every finding (the existing trackers cover this) rather than landing duplicates. |
| `gh api` rate-limits mid-batch | Large file (50+ findings) hits the per-minute limit | The skill surfaces the partial-success recap from Step 6; re-invoke against the same file later for the failed indices (the duplicate-guard at Step 2 will catch the already-imported ones). |
37 changes: 29 additions & 8 deletions plugins/magpie-security/skills/issue-import-from-pr/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ when_to_use: |
`security-issue-import`.
argument-hint: "[pr-number] [repo:owner/name]"
capability: capability:intake
surface_hash: sha256:c746e4aecc3cf315
surface_hash: sha256:26be912ca52168e5
license: Apache-2.0
measured_tokens: 7730
measured_tokens: 7895
---

<!-- Placeholder convention (see AGENTS.md#placeholder-convention-used-in-skill-files):
Expand Down Expand Up @@ -449,14 +449,35 @@ and the explicit confirmation lets the user catch a wrong scope before any track

Sequenced. Each step depends on the previous one's output.

### 7a — Create the tracker via `gh api`
### 7a — Create the tracker through vetted-ops

Create it per the safe-create recipe in [`tools/github/operations.md`](../../../../tools/github/operations.md#create) (`-F title=@<file>`, never inline text):
title file `<scratch>/import-pr-<N>-title.txt` holding the confirmed title (it derives from the attacker-controlled PR title),
body file `<scratch>/import-pr-<N>-body.md` holding the confirmed `render-body` `text` (layout: [`tracker-body-template.md`](tracker-body-template.md)),
and one `labels[]` per Step 5c label.
Use `issue-create-labeled` instead of raw GitHub issue creation.

Capture `number`, `node_id`, `html_url` from the response.
Write the confirmed title, with the Write tool, to `<scratch>/import-pr-<N>-title.txt`
and the confirmed `render-body` text to
`<scratch>/import-pr-<N>-body.md`.

Serialize the exact Step 5c labels into a JSON array, `<labels-json>` below.
Do not invent or discard scope, PR-state, or security-marker labels.

For a GitHub tracker:

```bash
uv run --project ~/.claude/magpie/vetted-ops vetted-op --caller security-issue-import-from-pr issue-create-labeled <scratch>/import-pr-<N>-title.txt <scratch>/import-pr-<N>-body.md '<labels-json>'
```

The title derives from the attacker-controlled PR title, so it travels as a file: the dispatcher reads and validates it, and the shell never sees it.
The labels come from configuration, so they are written in the command.
Keep the command bare, with no `$(…)`, or it runs inside the sandbox and fails.
The report body travels through stdin.
All labels must be approved by the vetted-ops policy and are applied at creation.

Capture `number`, `node_id`, and `url` from the JSON response.

Stop on failure; never fall back to raw GitHub creation.

For non-GitHub trackers, use the existing `issue-create`
backend operation.

### 7b — Apply labels

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
|---|---|---|
| `gh api repos/<upstream>` returns 404 | Repo placeholder not substituted | Re-read `<project-config>/project.md` for the `upstream_repo:` value. |
| PR is `CLOSED` (not merged) | Fix abandoned upstream | Stop and confirm with the user that a tracker is still wanted; otherwise abandon. |
| `gh api repos/<tracker>/issues` returns 422 | Missing or invalid title / body field shape | Re-check the body against the issue template's eleven fields; the `### <field>` headings must match exactly (case-sensitive). |
| `issue-create-labeled` returns a GitHub 422 error | Missing or invalid title / body field shape | Re-check the body against the issue template's eleven fields; the `### <field>` headings must match exactly (case-sensitive). |
| `addProjectV2ItemById` returns `not found` for the project | Project-board node ID changed | Re-run the introspection query in [`project-board.md`](../../../../tools/github/project-board.md) and update [`project.md`](../../../../<project-config>/project.md). |
| Multiple existing trackers match the duplicate-guard search | Earlier closed-as-duplicate trackers reference the PR number in passing | Surface all hits to the user; let them confirm `force` to proceed anyway. |
| Mixed-scope PR (e.g. `<scope-b>/` + `<scope-a>/`) | The fix lives in more than one product | Stop; surface the per-scope split decision to the user before re-invoking. |
14 changes: 12 additions & 2 deletions plugins/magpie-security/skills/issue-import/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ when_to_use: |
`import last 30d` / `import all` for a backlog).
argument-hint: "[import] [last Nd|all] [skip threadId]"
capability: capability:intake
surface_hash: sha256:079bd7106b8b78ef
surface_hash: sha256:3210ccb4763beb17
license: Apache-2.0
measured_tokens: 8610
measured_tokens: 8686
---

<!-- Placeholder convention (see AGENTS.md#placeholder-convention-used-in-skill-files):
Expand Down Expand Up @@ -384,6 +384,16 @@ Each `keep` thread the Step 1 pre-filter dropped runs Steps 2 to 5; re-present i

## Step 7 — Apply confirmed imports

### Policy-scoped tracker creation requirement

GitHub imports require the vetted-ops `issue-create-labeled`
operation, caller permission for `security-issue-import`, and
policy-approved `needs triage` and `security issue` labels.

An existing installation with old caller grants or an incomplete
label allowlist must undergo policy reconciliation before creation.
Never fall back to raw GitHub issue creation.

Full procedure: [`apply.md`](apply.md).

## Step 8 — Recap
Expand Down
36 changes: 27 additions & 9 deletions plugins/magpie-security/skills/issue-import/apply.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,33 @@ For each confirmed `Report` or forwarder-relayed candidate:
If `fields_ok` is false, stop and show `extra_fields`: the body would not parse back into the form's fields.
The callout is the per-instance warning; the AGENTS.md rule remains the defence for downstream skills reading the body.

2. Create the issue with the `needs triage` and `security issue` labels,
per the safe-create recipe in
[`tools/github/operations.md`](../../../../tools/github/operations.md#create).
The title comes from an attacker-controlled email subject: title
file `<scratch>/issue-title-<threadId>.txt`, body file
`<scratch>/issue-body-<threadId>.md`, `labels[]=needs triage` and
`labels[]=security issue`. Capture the new issue's `number`.
The recipe's rule covers every `gh` call this skill makes with
attacker-controlled text as an argument.
2. **Create the tracker using the vetted operation.**

Never use raw `gh api` or `gh issue create` for confidential
security report content. The agent guard blocks those commands.

Write the confirmed title to `<scratch>/issue-title-<threadId>.txt`
with the Write tool, and use the body file rendered in item 1.

For a GitHub tracker:

```bash
uv run --project ~/.claude/magpie/vetted-ops vetted-op --caller security-issue-import issue-create-labeled <scratch>/issue-title-<threadId>.txt <scratch>/issue-body-<threadId>.md '["needs triage","security issue"]'
```

The title comes from an attacker-controlled email subject, so it
travels as a file: the dispatcher reads and validates it, and the
shell never sees it. Keep the command bare, with no `$(…)`, or it
runs inside the sandbox and fails.
The body travels on stdin, never in command arguments.

Capture `number`, `node_id`, and `url` from the JSON output.
Both labels are applied atomically at creation.

Stop if the vetted operation fails. Never fall back to raw `gh`.

For non-GitHub trackers, continue using the existing
`issue-create` operation through the configured backend.

3. **Set the project-board `Status` to `Needs triage`.**
The *Auto-add to project* workflow may already have added the issue
Expand Down
13 changes: 11 additions & 2 deletions plugins/magpie-setup/skills/setup/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,15 @@ applicable required operations from the canonical
Select the configured tracker backend and each distinct import caller.
Do not maintain another fixed caller-to-operation list here.

For GitHub security imports using `issue-create-labeled`, also check
the policy's `[values] labels` allowlist against the exact labels
required by each configured importer: intake labels (`needs triage`,
`security issue`) and, for PR imports, the configured scope and
PR-state labels. Propose only missing entries, using the project's
actual configured label names. Obtain explicit user approval before
the user applies the policy change. Missing labels must fail closed;
never bypass the vetted operation or relax its validation.

Show each missing caller or operation as a proposed policy diff. Preserve
existing permissions and unrelated callers; do not duplicate TOML keys.
Never add unrelated permissions. If the policy is missing, do not create it
Expand All @@ -366,13 +375,13 @@ user save it after explicit confirmation, as described under
[Personal tool configs](#personal-tool-configs-for-a-project-that-has-not-adopted-magpie).
Do not bypass sandbox write restrictions.

A declined, unapplied, or unchecked import-grant proposal remains unresolved
A declined, unapplied, or unchecked import permission or label-allowlist proposal remains unresolved
and must not produce a clean reconciliation stamp for the affected skill.

## Step 3b — Record what this run reconciled

For every skill in scope (Step 1) whose `requires_config:` set now fully
resolves **and whose applicable import caller grants have been verified**,
resolves **and whose applicable import caller grants and required labels have been verified**,
record that fact, keyed by that skill's frontmatter `name:`
(e.g. `code-review`). **Everything this step writes
stays inside the personal layer's `reconciled.json` — never the
Expand Down
29 changes: 24 additions & 5 deletions plugins/magpie-setup/skills/setup/reconcile.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,25 @@ baseline required.

Derive required operations from the canonical [vetted-ops README `[callers]` example](../../../../tools/vetted-ops/README.md#configuration), including backend-specific operations where applicable. Do not use a second hard-coded mapping.

For GitHub security imports using `issue-create-labeled`, also
validate the policy's `[values] labels` allowlist against the
labels required by each configured workflow:

- Email and Markdown imports: `needs triage` and `security issue`.
- PR imports: the configured scope, PR-state, and security-marker
labels from Step 5c of `security-issue-import-from-pr`.

Resolve project-specific label names from the adopter's current
configuration. Do not assume every project uses the same names.

Missing labels are findings even when all caller grants exist.
Propose only the missing labels, preserving existing policy values.
Never automatically modify or weaken the approved security policy.

If the required label values or the policy cannot be verified,
report the check as unchecked, not clean. Declined, unapplied, or
unverified changes prevent a clean reconciliation stamp.

A missing caller or missing required operation is a finding. Name the
caller, the missing operations, and the existing policy path. Propose
adding only those grants; do not grant `body-field-set`, which these
Expand Down Expand Up @@ -206,7 +225,7 @@ baseline required.
## Step 1 — Present the findings

List every finding from checks 2–3a as a numbered proposal, one item per
override, `requires_config` gap, or missing import caller policy grant:
override, `requires_config` gap, or missing import caller grant or required label:

```text
1. .apache-magpie-overrides/issue-triage.md anchors to
Expand All @@ -219,7 +238,7 @@ override, `requires_config` gap, or missing import caller policy grant:
```

No findings → say so plainly (*"every configured skill's anchors,
`requires_config` entries and applicable vetted-ops caller grants resolve"*), name any `unchecked` skills from
`requires_config` entries, applicable vetted-ops caller grants and required labels resolve"*), name any `unchecked` skills from
check 4, and go straight to Step 2 with nothing to confirm — writing
the stamp needs no confirmation when nothing is changing.

Expand All @@ -238,7 +257,7 @@ or let the user save the drafted policy; do not directly write the
security-control file from reconcile. A refusal does
not authorize a policy edit or a clean reconciliation stamp for that
unresolved configuration. Do not treat resolved `requires_config` files
alone as proof of a clean skill when its required caller grants are missing.
alone as proof of a clean skill when its required caller grants or labels are missing.
Preserve existing policy content not covered by the confirmed change.

Both `acknowledged` writes below fire **on decline**, not on show — unlike
Expand All @@ -254,9 +273,9 @@ suppressed by a write that never happened.
- **Confirmed and applied** — verify the resulting configuration
before writing the skill's clean stamp. For import caller policy
findings, re-read and parse the saved vetted-ops policy and confirm
that every required operation for the selected backend is present.
that every required operation for the selected backend is present and all applicable GitHub import labels are policy-approved.
User confirmation of a draft alone is not proof of application.
If the policy is unchanged, missing a grant, or cannot be verified,
If the policy is unchanged, missing a required grant or label, or cannot be verified,
leave the finding unresolved and do not stamp that skill clean.
Only after all applicable checks pass may its entry in the stamp's
`skills:` map be written (or refreshed) with its **current**
Expand Down
Loading
Loading