@iceinvein/agent-skills 0.24.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/package.json +1 -1
- package/skills/index.json +1 -1
- package/skills/magpie/README.md +14 -0
- package/skills/magpie/SKILL.md +7 -5
- package/skills/magpie/bin/magpie.ts +63 -3
- package/skills/magpie/evals/README.md +1 -1
- package/skills/magpie/evals/post-folds-selection-events/fixture.sh +35 -0
- package/skills/magpie/evals/post-folds-selection-events/graders/selection-read-from-magpie-view.md +6 -0
- package/skills/magpie/evals/post-folds-selection-events/prompt.md +2 -2
- package/skills/magpie/evals/rules.json +2 -2
- package/skills/magpie/package.json +1 -1
- package/skills/magpie/scripts/__tests__/helper.test.ts +300 -0
- package/skills/magpie/scripts/__tests__/labels.test.ts +46 -1
- package/skills/magpie/scripts/__tests__/mark-cmd.test.ts +129 -0
- package/skills/magpie/scripts/__tests__/post-cmd.test.ts +298 -1
- package/skills/magpie/scripts/__tests__/render-cmd.test.ts +15 -1
- package/skills/magpie/scripts/__tests__/render-findings.test.ts +13 -0
- package/skills/magpie/scripts/__tests__/server.test.ts +96 -1
- package/skills/magpie/scripts/__tests__/skill-lint.test.ts +23 -0
- package/skills/magpie/scripts/__tests__/view-cmd.test.ts +219 -0
- package/skills/magpie/scripts/helper.js +44 -4
- package/skills/magpie/scripts/labels.ts +11 -0
- package/skills/magpie/scripts/mark-cmd.ts +56 -0
- package/skills/magpie/scripts/post-cmd.ts +75 -5
- package/skills/magpie/scripts/render-cmd.ts +3 -1
- package/skills/magpie/scripts/render-findings.ts +3 -1
- package/skills/magpie/scripts/server.ts +31 -2
- package/skills/magpie/scripts/view-cmd.ts +143 -0
- package/skills/magpie/skill.json +1 -1
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs'
|
|
2
|
+
import { readFile } from 'node:fs/promises'
|
|
3
|
+
import { join } from 'node:path'
|
|
4
|
+
import { filePathMatches, parseUnifiedDiffToHunks, splitDiffByFile } from './diff-utils.ts'
|
|
5
|
+
import { foldSelection, readDismissed, readJsonLines } from './labels.ts'
|
|
6
|
+
import { rankActionable } from './render-issues-list.ts'
|
|
7
|
+
import { readTarget } from './target.ts'
|
|
8
|
+
import { type PostStatusMap, parseFinding, type ReviewFinding } from './types.ts'
|
|
9
|
+
|
|
10
|
+
export type ViewFinding = {
|
|
11
|
+
id: string
|
|
12
|
+
file: string
|
|
13
|
+
line: number | null
|
|
14
|
+
severity: string
|
|
15
|
+
action: string
|
|
16
|
+
title: string
|
|
17
|
+
description: string
|
|
18
|
+
suggestion: { body: string } | null
|
|
19
|
+
proof: unknown | null
|
|
20
|
+
hunk: string | null
|
|
21
|
+
fileDiff: string | null
|
|
22
|
+
postStatus: 'posted' | 'failed' | null
|
|
23
|
+
postMessage: string | null
|
|
24
|
+
dismissed: string | null
|
|
25
|
+
selected: boolean
|
|
26
|
+
recommended: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type View = {
|
|
30
|
+
pr: { number: number; title: string; url: string }
|
|
31
|
+
findings: ViewFinding[]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function fail(message: string): number {
|
|
35
|
+
process.stderr.write(`view: ${message}\n`)
|
|
36
|
+
return 2
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function readJson(path: string): Promise<unknown> {
|
|
40
|
+
return JSON.parse(await readFile(path, 'utf8'))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function readPr(path: string): Promise<View['pr']> {
|
|
44
|
+
if (!existsSync(path)) throw new Error(`${path} is missing`)
|
|
45
|
+
const raw = await readJson(path)
|
|
46
|
+
if (typeof raw !== 'object' || raw === null) throw new Error(`${path}: expected an object`)
|
|
47
|
+
const { number, title, url } = raw as Record<string, unknown>
|
|
48
|
+
if (typeof number !== 'number') throw new Error(`${path}: number must be a number`)
|
|
49
|
+
if (typeof title !== 'string') throw new Error(`${path}: title must be a string`)
|
|
50
|
+
if (typeof url !== 'string') throw new Error(`${path}: url must be a string`)
|
|
51
|
+
return { number, title, url }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The hunk, header included, whose new-side range holds `line`. */
|
|
55
|
+
function hunkAt(section: string, line: number): string | null {
|
|
56
|
+
const hunks = parseUnifiedDiffToHunks(section)
|
|
57
|
+
const blocks = section.split(/^(?=@@ )/m).filter((block) => block.startsWith('@@ '))
|
|
58
|
+
const index = hunks.findIndex((h) => line >= h.newStart && line < h.newStart + h.newLines)
|
|
59
|
+
return blocks[index] ?? null
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function postFields(status: PostStatusMap[string] | undefined): {
|
|
63
|
+
postStatus: ViewFinding['postStatus']
|
|
64
|
+
postMessage: string | null
|
|
65
|
+
} {
|
|
66
|
+
if (status === 'posted') return { postStatus: 'posted', postMessage: null }
|
|
67
|
+
if (status?.status === 'failed') return { postStatus: 'failed', postMessage: status.message }
|
|
68
|
+
return { postStatus: null, postMessage: null }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function runView(runDir: string, top: number): Promise<number> {
|
|
72
|
+
try {
|
|
73
|
+
const target = await readTarget(runDir)
|
|
74
|
+
if (target.mode === 'local') return fail(`${runDir} is a local run; there is nothing to post`)
|
|
75
|
+
} catch (err) {
|
|
76
|
+
return fail(err instanceof Error ? err.message : String(err))
|
|
77
|
+
}
|
|
78
|
+
const findingsPath = join(runDir, 'findings.final.json')
|
|
79
|
+
if (!existsSync(findingsPath)) {
|
|
80
|
+
process.stderr.write(`view: ${findingsPath} is missing\n`)
|
|
81
|
+
return 4
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let findings: ReviewFinding[]
|
|
85
|
+
let pr: View['pr']
|
|
86
|
+
let selected: Set<string>
|
|
87
|
+
let dismissed: Map<string, string>
|
|
88
|
+
try {
|
|
89
|
+
const raw = await readJson(findingsPath)
|
|
90
|
+
if (!Array.isArray(raw)) throw new Error(`${findingsPath}: expected an array of findings`)
|
|
91
|
+
findings = raw.map(parseFinding)
|
|
92
|
+
pr = await readPr(join(runDir, 'pr.json'))
|
|
93
|
+
selected = foldSelection(await readJsonLines(join(runDir, 'state', 'events')))
|
|
94
|
+
dismissed = await readDismissed(runDir)
|
|
95
|
+
} catch (err) {
|
|
96
|
+
return fail(err instanceof Error ? err.message : String(err))
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const statusPath = join(runDir, 'post-status.json')
|
|
100
|
+
let postStatus: PostStatusMap = {}
|
|
101
|
+
if (existsSync(statusPath)) {
|
|
102
|
+
try {
|
|
103
|
+
postStatus = (await readJson(statusPath)) as PostStatusMap
|
|
104
|
+
} catch (err) {
|
|
105
|
+
return fail(
|
|
106
|
+
`${statusPath} is not valid JSON: ${err instanceof Error ? err.message : String(err)}`,
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const diffPath = join(runDir, 'diff.patch')
|
|
111
|
+
const sections = existsSync(diffPath)
|
|
112
|
+
? splitDiffByFile(await readFile(diffPath, 'utf8'))
|
|
113
|
+
: new Map<string, string>()
|
|
114
|
+
const recommended = new Set(
|
|
115
|
+
rankActionable(findings, postStatus, dismissed, top).recommended.map((f) => f.id),
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
const view: View = {
|
|
119
|
+
pr,
|
|
120
|
+
findings: findings.map((f): ViewFinding => {
|
|
121
|
+
const fileDiff = [...sections].find(([path]) => filePathMatches(path, f.file))?.[1] ?? null
|
|
122
|
+
return {
|
|
123
|
+
id: f.id,
|
|
124
|
+
file: f.file,
|
|
125
|
+
line: f.line,
|
|
126
|
+
severity: f.severity,
|
|
127
|
+
action: f.risk.action,
|
|
128
|
+
title: f.title,
|
|
129
|
+
description: f.description,
|
|
130
|
+
suggestion: f.suggestion ? { body: f.suggestion.body } : null,
|
|
131
|
+
proof: f.proof ?? null,
|
|
132
|
+
hunk: fileDiff !== null && f.line !== null ? hunkAt(fileDiff, f.line) : null,
|
|
133
|
+
fileDiff,
|
|
134
|
+
...postFields(postStatus[f.id]),
|
|
135
|
+
dismissed: dismissed.get(f.id) ?? null,
|
|
136
|
+
selected: selected.has(f.id),
|
|
137
|
+
recommended: recommended.has(f.id),
|
|
138
|
+
}
|
|
139
|
+
}),
|
|
140
|
+
}
|
|
141
|
+
process.stdout.write(`${JSON.stringify(view)}\n`)
|
|
142
|
+
return 0
|
|
143
|
+
}
|
package/skills/magpie/skill.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "magpie",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Interactive PR review pipeline. Runs five parallel specialist subagents (security, bugs, performance, code-smells, architecture) plus a once-per-PR checks pass that finds tests and controls able to pass without proving their purpose, drops findings whose quoted evidence is not in the code, dedupes, runs critic subagents that re-check each finding against the worktree and set its risk label, peer-reviews via codex exec (falling back to a Claude second opinion when codex is unavailable), and serves an interactive HTML report for selecting or dismissing findings to post via gh, recording the outcome per finding as labels. Bundles a Bun CLI put on PATH by the skill's postinstall step under a bunx install, or by the plugin's bin/ under a Claude Code plugin install. Use when the user asks to review a GitHub pull request. Local mode (setup --local) runs the same pipeline on the current branch's diff from its merge base, uncommitted and untracked work included, against the caller's live tree, with no server or posting, and hands the ranked findings back in the terminal for an implementing or orchestrating agent to address. Splits oversized diffs into budgeted shards and rebuilds the diff from the local clone when gh pr diff refuses it.",
|
|
5
5
|
"author": "iceinvein",
|
|
6
6
|
"type": "prompt",
|