@sentry/warden 0.21.0 → 0.22.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.
Files changed (55) hide show
  1. package/CHANGELOG.md +180 -0
  2. package/README.md +3 -3
  3. package/dist/cli/commands/runs.d.ts.map +1 -1
  4. package/dist/cli/commands/runs.js +68 -10
  5. package/dist/cli/commands/runs.js.map +1 -1
  6. package/dist/cli/log-cleanup.d.ts.map +1 -1
  7. package/dist/cli/log-cleanup.js +4 -0
  8. package/dist/cli/log-cleanup.js.map +1 -1
  9. package/dist/cli/main.d.ts.map +1 -1
  10. package/dist/cli/main.js +218 -26
  11. package/dist/cli/main.js.map +1 -1
  12. package/dist/cli/output/index.d.ts +1 -1
  13. package/dist/cli/output/index.d.ts.map +1 -1
  14. package/dist/cli/output/index.js +1 -1
  15. package/dist/cli/output/index.js.map +1 -1
  16. package/dist/cli/output/ink-runner.d.ts.map +1 -1
  17. package/dist/cli/output/ink-runner.js +19 -1
  18. package/dist/cli/output/ink-runner.js.map +1 -1
  19. package/dist/cli/output/jsonl-schema-gen.d.ts.map +1 -1
  20. package/dist/cli/output/jsonl-schema-gen.js +4 -2
  21. package/dist/cli/output/jsonl-schema-gen.js.map +1 -1
  22. package/dist/cli/output/jsonl.d.ts +110 -4
  23. package/dist/cli/output/jsonl.d.ts.map +1 -1
  24. package/dist/cli/output/jsonl.js +177 -7
  25. package/dist/cli/output/jsonl.js.map +1 -1
  26. package/dist/cli/output/tasks.d.ts +4 -1
  27. package/dist/cli/output/tasks.d.ts.map +1 -1
  28. package/dist/cli/output/tasks.js +17 -1
  29. package/dist/cli/output/tasks.js.map +1 -1
  30. package/dist/sdk/analyze.d.ts.map +1 -1
  31. package/dist/sdk/analyze.js +20 -0
  32. package/dist/sdk/analyze.js.map +1 -1
  33. package/dist/sdk/runner.d.ts +1 -1
  34. package/dist/sdk/runner.d.ts.map +1 -1
  35. package/dist/sdk/types.d.ts +19 -0
  36. package/dist/sdk/types.d.ts.map +1 -1
  37. package/dist/types/index.d.ts +1 -0
  38. package/dist/types/index.d.ts.map +1 -1
  39. package/dist/types/index.js +13 -0
  40. package/dist/types/index.js.map +1 -1
  41. package/package.json +1 -1
  42. package/skills/warden/SKILL.md +5 -5
  43. package/skills/warden/SOURCES.md +39 -0
  44. package/skills/warden/references/cli-reference.md +11 -4
  45. package/skills/warden/references/config-schema.md +9 -0
  46. package/skills/warden/references/configuration.md +9 -0
  47. package/skills/warden-sweep/SKILL.md +43 -365
  48. package/skills/warden-sweep/SOURCES.md +43 -0
  49. package/skills/warden-sweep/references/issue-phase.md +24 -0
  50. package/skills/warden-sweep/references/organize-phase.md +31 -0
  51. package/skills/warden-sweep/references/patch-phase.md +142 -0
  52. package/skills/warden-sweep/references/resume-and-artifacts.md +51 -0
  53. package/skills/warden-sweep/references/scan-phase.md +46 -0
  54. package/skills/warden-sweep/references/script-interfaces.md +127 -0
  55. package/skills/warden-sweep/references/verify-phase.md +69 -0
@@ -0,0 +1,142 @@
1
+ # Patch Phase
2
+
3
+ Create isolated fixes for verified findings and open draft PRs.
4
+
5
+ ## Contents
6
+
7
+ - Rules
8
+ - Setup
9
+ - Per-Finding Process
10
+ - Dedup Check
11
+ - Worktree, Fix, Reviewers, And PR
12
+ - Report Template
13
+
14
+ ## Rules
15
+
16
+ - Patch high-severity and above.
17
+ - Patch medium findings only when they come from bug-detection skills such as `code-review` or `security-review`.
18
+ - Skip low and info findings.
19
+ - Process findings sequentially.
20
+ - Create one worktree and one branch per finding.
21
+ - Clean up worktrees after success or failure.
22
+
23
+ ## Setup
24
+
25
+ Index existing PRs before patching:
26
+
27
+ ```bash
28
+ uv run <skill-root>/scripts/index_prs.py ${SWEEP_DIR}
29
+ ```
30
+
31
+ Parse the JSON stdout and use `fileIndex` for dedup checks.
32
+
33
+ Determine the default branch and fetch latest:
34
+
35
+ ```bash
36
+ DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name')
37
+ git fetch origin "${DEFAULT_BRANCH}"
38
+ ```
39
+
40
+ ## Per-Finding Process
41
+
42
+ For each finding in `data/verified.jsonl`:
43
+
44
+ 1. If the finding ID already exists in `data/patches.jsonl`, skip it.
45
+ 2. Run the dedup check.
46
+ 3. Create a worktree.
47
+ 4. Apply the fix using `references/patch-prompt.md`.
48
+ 5. If the patch task returns `"status": "skipped"`, record an error, clean up the worktree, and continue.
49
+ 6. Find reviewers.
50
+ 7. Push the branch.
51
+ 8. Create a draft PR.
52
+ 9. Record the result in `data/patches.jsonl`.
53
+ 10. Clean up the worktree.
54
+
55
+ ## Dedup Check
56
+
57
+ Use the file index from `index_prs.py`:
58
+
59
+ 1. File match: if no open Warden PR touches the finding file, proceed.
60
+ 2. Chunk overlap: if a PR touches the same file, read `data/pr-diffs/<number>.diff` and check whether changed hunks overlap or sit within roughly 10 lines of the finding range.
61
+ 3. Same concern: compare PR title and finding title/description.
62
+
63
+ Skip the finding only when there is both chunk overlap and the PR addresses the same concern. Record it with `"status": "existing"` and the matching `prUrl`.
64
+
65
+ ## Worktree, Fix, Reviewers, And PR
66
+
67
+ ```bash
68
+ BRANCH="warden-sweep/${RUN_ID}/${FINDING_ID}"
69
+ WORKTREE="${SWEEP_DIR}/worktrees/${FINDING_ID}"
70
+ git worktree add "${WORKTREE}" -b "${BRANCH}" "origin/${DEFAULT_BRANCH}"
71
+ ```
72
+
73
+ Each finding branches from the default branch so PRs contain only the fix commit.
74
+
75
+ Run patch work using the host agent's task/delegation mechanism when available. Read `references/patch-prompt.md` and substitute the finding values and worktree path into the `${...}` placeholders.
76
+
77
+ If delegated tasks are not available, apply the prompt instructions yourself in the worktree.
78
+
79
+ ```bash
80
+ uv run <skill-root>/scripts/find_reviewers.py "${FILE_PATH}"
81
+ ```
82
+
83
+ ```bash
84
+ cd "${WORKTREE}" && git push -u origin HEAD:"${BRANCH}"
85
+ ```
86
+
87
+ Create the PR with a short "what" summary followed by the finding description and verification reasoning:
88
+
89
+ ```bash
90
+ gh pr create --draft \
91
+ --label "warden" \
92
+ --title "fix: ${TITLE}" \
93
+ --body "$(cat <<'EOF'
94
+ ${FIX_WHAT_DESCRIPTION}
95
+
96
+ ${DESCRIPTION}
97
+
98
+ ${REASONING}
99
+
100
+ Automated fix for Warden finding ${FINDING_ID} (${SEVERITY}, detected by ${SKILL}).
101
+
102
+ <!-- Only include the next line if Phase 3 succeeded and ISSUE_NUMBER is available -->
103
+ Ref #${ISSUE_NUMBER}
104
+
105
+ > This PR was auto-generated by a Warden Sweep (run ${RUN_ID}).
106
+ > The finding has been validated through automated deep tracing,
107
+ > but human confirmation is requested as this is batch work.
108
+ EOF
109
+ )" ${REVIEWERS}
110
+ ```
111
+
112
+ ## Record Result
113
+
114
+ Append to `data/patches.jsonl`. Use `"created"` for successful PRs, not the patch task's `"applied"` status.
115
+
116
+ ```json
117
+ {"findingId": "...", "prUrl": "https://...", "branch": "...", "reviewers": ["user1", "user2"], "filesChanged": ["..."], "status": "created|existing|error"}
118
+ ```
119
+
120
+ Clean up:
121
+
122
+ ```bash
123
+ cd "$(git rev-parse --show-toplevel)"
124
+ git worktree remove "${WORKTREE}" --force
125
+ ```
126
+
127
+ On failure at any step, write `"status": "error"` with an `"error"` message, clean up the worktree, and continue.
128
+
129
+ Update the manifest: set `phases.patch` to `"complete"`.
130
+
131
+ ## Report Template
132
+
133
+ ```markdown
134
+ ## PRs Created
135
+
136
+ **{created}** created, **{skipped}** skipped (existing), **{failed}** failed.
137
+
138
+ | # | Finding | PR | Status |
139
+ |---|---------|----|--------|
140
+ | 1 | `security-review-a1b2c3d4` SQL injection in query builder | #142 | created |
141
+ | 2 | `code-review-e5f6g7h8` Null pointer in handler | - | existing (#138) |
142
+ ```
@@ -0,0 +1,51 @@
1
+ # Resume And Artifacts
2
+
3
+ Use this reference when resuming a partial sweep or inspecting generated files.
4
+
5
+ ## Resume Rules
6
+
7
+ Each phase is incremental:
8
+
9
+ 1. Check `data/manifest.json` for phase state.
10
+ 2. For scan, pass `--sweep-dir` to `scan.py`.
11
+ 3. For verify, skip existing `data/verify/<id>.json` files.
12
+ 4. For issue, `create_issue.py` skips if `issueUrl` exists in the manifest.
13
+ 5. For patch, skip existing entries in `data/patches.jsonl`.
14
+ 6. For organize, rerun safely.
15
+
16
+ Continue from the first incomplete phase. Do not start a new sweep unless the user asks for a clean run.
17
+
18
+ ## Output Directory Structure
19
+
20
+ ```text
21
+ .warden/sweeps/<run-id>/
22
+ summary.md # Stats, key findings, PR links
23
+ findings/ # One markdown per verified finding
24
+ <finding-id>.md
25
+ security/ # Security-specific view
26
+ index.jsonl # Security findings index
27
+ <finding-id>.md # Copies of security findings
28
+ data/ # Structured data for tooling
29
+ manifest.json # Run metadata, phase state
30
+ scan-index.jsonl # Per-file scan tracking
31
+ all-findings.jsonl # Every finding from scan
32
+ verified.jsonl # Findings that passed verification
33
+ rejected.jsonl # Findings that failed verification
34
+ patches.jsonl # Finding -> PR URL -> reviewers
35
+ existing-prs.json # Cached open Warden PRs
36
+ report.json # Machine-readable summary
37
+ verify/ # Individual verification results
38
+ <finding-id>.json
39
+ logs/ # Warden JSONL logs per file
40
+ <hash>.jsonl
41
+ pr-diffs/ # Cached PR diffs for dedup
42
+ <number>.diff
43
+ ```
44
+
45
+ ## Failure Handling
46
+
47
+ - Preserve partial artifacts.
48
+ - Record per-finding errors in the relevant JSONL file.
49
+ - Distinguish timed-out files from errored files.
50
+ - Clean up worktrees before retrying patch work.
51
+ - Re-run organize after manual recovery to refresh reports.
@@ -0,0 +1,46 @@
1
+ # Scan Phase
2
+
3
+ Run Warden across repository files and collect normalized findings.
4
+
5
+ ## Run
6
+
7
+ ```bash
8
+ uv run <skill-root>/scripts/scan.py
9
+ ```
10
+
11
+ To scan only specific files:
12
+
13
+ ```bash
14
+ uv run <skill-root>/scripts/scan.py src/foo.ts src/bar.ts
15
+ ```
16
+
17
+ To resume a partial scan:
18
+
19
+ ```bash
20
+ uv run <skill-root>/scripts/scan.py --sweep-dir .warden/sweeps/<run-id>
21
+ ```
22
+
23
+ ## Process
24
+
25
+ 1. Parse the JSON stdout.
26
+ 2. Save `runId` and `sweepDir`.
27
+ 3. Treat exit code `1` as fatal and stop.
28
+ 4. Treat exit code `2` as partial: report timed-out and errored files separately, then continue only if the user accepts the partial results.
29
+ 5. Render every finding from the `findings` array.
30
+ 6. Update the checklist: Phase 1 complete.
31
+
32
+ ## Report Template
33
+
34
+ ```markdown
35
+ ## Scan Complete
36
+
37
+ Scanned **{filesScanned}** files, **{filesTimedOut}** timed out, **{filesErrored}** errors.
38
+
39
+ ### Findings ({totalFindings} total)
40
+
41
+ | # | Severity | Skill | File | Title |
42
+ |---|----------|-------|------|-------|
43
+ | 1 | **HIGH** | security-review | `src/db/query.ts:42` | SQL injection in query builder |
44
+ ```
45
+
46
+ Bold severity for high and above.
@@ -0,0 +1,127 @@
1
+ # Script Interfaces
2
+
3
+ Use this reference before running Warden Sweep scripts. Run scripts from the repository root and pass the host skill-root path.
4
+
5
+ ## Contents
6
+
7
+ - `scan.py`
8
+ - `index_prs.py`
9
+ - `create_issue.py`
10
+ - `organize.py`
11
+ - `extract_findings.py`
12
+ - `generate_report.py`
13
+ - `find_reviewers.py`
14
+
15
+ ## `scripts/scan.py`
16
+
17
+ Runs setup and scan in one call: generates a run ID, creates the sweep directory, checks dependencies, creates the `warden` label, enumerates files, runs Warden per file, writes `scan-index.jsonl`, and extracts findings.
18
+
19
+ ```bash
20
+ uv run <skill-root>/scripts/scan.py [file ...]
21
+ uv run <skill-root>/scripts/scan.py --sweep-dir .warden/sweeps/<run-id>
22
+ ```
23
+
24
+ Stdout JSON:
25
+
26
+ ```json
27
+ {
28
+ "runId": "abc123",
29
+ "sweepDir": ".warden/sweeps/abc123",
30
+ "filesScanned": 10,
31
+ "filesTimedOut": 0,
32
+ "filesErrored": 0,
33
+ "totalFindings": 3,
34
+ "findings": []
35
+ }
36
+ ```
37
+
38
+ Exit codes: `0` success, `1` fatal error, `2` partial scan.
39
+
40
+ ## `scripts/index_prs.py`
41
+
42
+ Fetches open Warden-labeled PRs, builds a file-to-PR dedup index, and caches diffs for overlapping PRs.
43
+
44
+ ```bash
45
+ uv run <skill-root>/scripts/index_prs.py <sweep-dir>
46
+ ```
47
+
48
+ Stdout JSON includes `fileIndex`. Side effects:
49
+
50
+ - writes `data/existing-prs.json`
51
+ - writes `data/pr-diffs/<number>.diff` for overlapping PRs
52
+
53
+ ## `scripts/create_issue.py`
54
+
55
+ Creates a GitHub tracking issue summarizing verified sweep results.
56
+
57
+ ```bash
58
+ uv run <skill-root>/scripts/create_issue.py <sweep-dir>
59
+ ```
60
+
61
+ Stdout JSON:
62
+
63
+ ```json
64
+ {
65
+ "issueUrl": "https://github.com/owner/repo/issues/123",
66
+ "issueNumber": 123
67
+ }
68
+ ```
69
+
70
+ Idempotent: skips creation when `issueUrl` already exists in the manifest.
71
+
72
+ ## `scripts/organize.py`
73
+
74
+ Tags security findings, labels security PRs, updates finding reports with PR links, posts final results to the tracking issue, generates the summary report, and finalizes the manifest.
75
+
76
+ ```bash
77
+ uv run <skill-root>/scripts/organize.py <sweep-dir>
78
+ ```
79
+
80
+ Stdout JSON includes final sweep counts and report paths. Side effects:
81
+
82
+ - creates `security/index.jsonl`
83
+ - copies security finding reports to `security/`
84
+ - creates or reuses the `security` GitHub label
85
+ - labels security PRs
86
+ - appends PR links to `findings/*.md`
87
+ - writes `summary.md` and `data/report.json`
88
+ - updates `phases.organize` in `data/manifest.json`
89
+
90
+ ## `scripts/extract_findings.py`
91
+
92
+ Parses Warden JSONL log files and extracts normalized findings. Usually called by `scan.py`.
93
+
94
+ ```bash
95
+ uv run <skill-root>/scripts/extract_findings.py <log-path-or-directory> -o <output.jsonl>
96
+ ```
97
+
98
+ Writes one normalized finding per line to `<output.jsonl>`.
99
+
100
+ ## `scripts/generate_report.py`
101
+
102
+ Builds `summary.md` and `report.json` from sweep data. Usually called by `organize.py`.
103
+
104
+ ```bash
105
+ uv run <skill-root>/scripts/generate_report.py <sweep-dir>
106
+ ```
107
+
108
+ Side effects:
109
+
110
+ - writes `<sweep-dir>/summary.md`
111
+ - writes `<sweep-dir>/data/report.json`
112
+
113
+ ## `scripts/find_reviewers.py`
114
+
115
+ Finds the top two git contributors for a file from the last 12 months.
116
+
117
+ ```bash
118
+ uv run <skill-root>/scripts/find_reviewers.py <file-path>
119
+ ```
120
+
121
+ Stdout JSON:
122
+
123
+ ```json
124
+ {
125
+ "reviewers": ["user1", "user2"]
126
+ }
127
+ ```
@@ -0,0 +1,69 @@
1
+ # Verify Phase
2
+
3
+ Deep-trace every finding before patching. This phase qualifies true issues and rejects false positives.
4
+
5
+ ## Input
6
+
7
+ Read findings from:
8
+
9
+ ```text
10
+ <sweep-dir>/data/all-findings.jsonl
11
+ ```
12
+
13
+ ## Process
14
+
15
+ For each finding:
16
+
17
+ 1. If `data/verify/<finding-id>.json` exists, skip it.
18
+ 2. Launch verification work using the host agent's task/delegation mechanism when available. Process findings in parallel batches up to 8 if the host supports parallel work.
19
+ 3. Read `references/verify-prompt.md` and substitute the finding values into the `${...}` placeholders.
20
+ 4. Parse the returned JSON.
21
+ 5. Write the raw result to `data/verify/<finding-id>.json`.
22
+ 6. Append verified findings to `data/verified.jsonl`.
23
+ 7. Append rejected findings to `data/rejected.jsonl`.
24
+ 8. For verified findings, generate `findings/<finding-id>.md`.
25
+
26
+ If the host does not support delegated tasks, run the same verification prompt serially.
27
+
28
+ ## Verified Finding Report
29
+
30
+ ````markdown
31
+ # ${TITLE}
32
+
33
+ **ID**: ${FINDING_ID} | **Severity**: ${SEVERITY} | **Confidence**: ${CONFIDENCE}
34
+ **Skill**: ${SKILL} | **File**: ${FILE_PATH}:${START_LINE}
35
+
36
+ ## Description
37
+ ${DESCRIPTION}
38
+
39
+ ## Verification
40
+ **Verdict**: Verified (${VERIFICATION_CONFIDENCE})
41
+ **Reasoning**: ${REASONING}
42
+ **Code trace**: ${TRACE_NOTES}
43
+
44
+ ## Suggested Fix
45
+ ${FIX_DESCRIPTION}
46
+ ```diff
47
+ ${FIX_DIFF}
48
+ ```
49
+ ````
50
+
51
+ Update the manifest: set `phases.verify` to `"complete"`.
52
+
53
+ ## Report Template
54
+
55
+ ```markdown
56
+ ## Verification Complete
57
+
58
+ **{verified}** verified, **{rejected}** rejected.
59
+
60
+ ### Verified Findings
61
+
62
+ | # | Severity | Confidence | File | Title | Reasoning |
63
+ |---|----------|------------|------|-------|-----------|
64
+ | 1 | **HIGH** | high | `src/db/query.ts:42` | SQL injection in query builder | User input flows directly into... |
65
+
66
+ ### Rejected ({rejected_count})
67
+
68
+ - `{findingId}` {file}: {reasoning}
69
+ ```