@delegance/claude-autopilot 1.8.0 → 1.9.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/CHANGELOG.md +26 -0
- package/package.json +1 -1
- package/src/cli/index.ts +3 -0
- package/src/cli/pr-comment.ts +137 -0
- package/src/cli/run.ts +21 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.9.0] — 2026-04-22
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- **`--post-comments` flag on `run`** — posts a formatted markdown summary to the open PR after the pipeline; edits existing autopilot comment on re-runs instead of creating a new one (tracked via `<!-- autopilot-review -->` marker)
|
|
7
|
+
- **`detectPrNumber()`** — reads `PR_NUMBER`/`GH_PR_NUMBER`/`GITHUB_PR_NUMBER` env vars (CI) or falls back to `gh pr view` (local)
|
|
8
|
+
- **`formatComment()`** — status badge, context line, phase table, critical/warning findings with `file:line`, notes in `<details>`, cost footer
|
|
9
|
+
- 10 new formatter tests — **215 total**
|
|
10
|
+
|
|
11
|
+
## [1.8.0] — 2026-04-22
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
- **Shared `parseReviewOutput()`** (`src/adapters/review-engine/parse-output.ts`) — extracts `file:line` attribution from review finding bodies; used by all five adapters; eliminates ~100 lines of duplicated parser code
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
- `hardcoded-secrets` false positive on route object keys containing `password` (e.g. `forgot_password: '/forgot-password'`)
|
|
18
|
+
|
|
19
|
+
## [1.7.2] — 2026-04-22
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
- `hardcoded-secrets` rule no longer fires on route path values (values starting with `/`)
|
|
23
|
+
|
|
24
|
+
## [1.7.1] — 2026-04-22
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
- Detection logging: `auto-detected:` line in run output shows stack, protected paths, and test command when inferred; git context (branch + last commit) shown on every run
|
|
28
|
+
|
|
3
29
|
## [1.7.0] — 2026-04-22
|
|
4
30
|
|
|
5
31
|
### Added
|
package/package.json
CHANGED
package/src/cli/index.ts
CHANGED
|
@@ -65,6 +65,7 @@ Options (run):
|
|
|
65
65
|
--config <path> Path to config file (default: ./autopilot.config.yaml)
|
|
66
66
|
--files <a,b,c> Explicit comma-separated file list (skips git detection)
|
|
67
67
|
--dry-run Show what would run without executing
|
|
68
|
+
--post-comments Post/update a summary comment on the open PR
|
|
68
69
|
--format <text|sarif> Output format (default: text)
|
|
69
70
|
--output <path> Output file path (required with --format sarif)
|
|
70
71
|
|
|
@@ -118,6 +119,7 @@ switch (subcommand) {
|
|
|
118
119
|
const config = flag('config');
|
|
119
120
|
const filesArg = flag('files');
|
|
120
121
|
const dryRun = boolFlag('dry-run');
|
|
122
|
+
const postComments = boolFlag('post-comments');
|
|
121
123
|
const formatArg = flag('format');
|
|
122
124
|
const outputPath = flag('output');
|
|
123
125
|
|
|
@@ -135,6 +137,7 @@ switch (subcommand) {
|
|
|
135
137
|
configPath: config,
|
|
136
138
|
files: filesArg ? filesArg.split(',').map(f => f.trim()) : undefined,
|
|
137
139
|
dryRun,
|
|
140
|
+
postComments,
|
|
138
141
|
format: formatArg as 'text' | 'sarif' | undefined,
|
|
139
142
|
outputPath,
|
|
140
143
|
});
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { runSafe } from '../core/shell.ts';
|
|
2
|
+
import type { RunResult } from '../core/pipeline/run.ts';
|
|
3
|
+
import type { AutopilotConfig } from '../core/config/types.ts';
|
|
4
|
+
import type { GitContext } from '../core/detect/git-context.ts';
|
|
5
|
+
import { readFileSync } from 'node:fs';
|
|
6
|
+
import { join, dirname } from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
|
|
9
|
+
const COMMENT_MARKER = '<!-- autopilot-review -->';
|
|
10
|
+
|
|
11
|
+
function readVersion(): string {
|
|
12
|
+
try {
|
|
13
|
+
const pkgPath = join(dirname(fileURLToPath(import.meta.url)), '../../package.json');
|
|
14
|
+
return (JSON.parse(readFileSync(pkgPath, 'utf8')) as { version: string }).version;
|
|
15
|
+
} catch { return 'unknown'; }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Detect the current open PR number via gh CLI or CI env vars. */
|
|
19
|
+
export function detectPrNumber(cwd: string): number | null {
|
|
20
|
+
// CI env vars set by GitHub Actions
|
|
21
|
+
const fromEnv = process.env.PR_NUMBER ?? process.env.GH_PR_NUMBER ?? process.env.GITHUB_PR_NUMBER;
|
|
22
|
+
if (fromEnv && /^\d+$/.test(fromEnv)) return parseInt(fromEnv, 10);
|
|
23
|
+
|
|
24
|
+
// gh CLI — works locally and in CI when gh is authenticated
|
|
25
|
+
const raw = runSafe('gh', ['pr', 'view', '--json', 'number', '--jq', '.number'], { cwd });
|
|
26
|
+
if (raw) {
|
|
27
|
+
const n = parseInt(raw.trim(), 10);
|
|
28
|
+
if (!isNaN(n)) return n;
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Find the ID of a previously-posted autopilot comment, if any. */
|
|
34
|
+
function findExistingCommentId(pr: number, cwd: string): number | null {
|
|
35
|
+
const raw = runSafe('gh', ['api', `repos/{owner}/{repo}/issues/${pr}/comments`,
|
|
36
|
+
'--jq', `[.[] | select(.body | startswith("${COMMENT_MARKER}")) | .id] | first`], { cwd });
|
|
37
|
+
if (!raw) return null;
|
|
38
|
+
const n = parseInt(raw.trim(), 10);
|
|
39
|
+
return isNaN(n) ? null : n;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Format a RunResult into a markdown PR comment. */
|
|
43
|
+
export function formatComment(
|
|
44
|
+
result: RunResult,
|
|
45
|
+
config: AutopilotConfig,
|
|
46
|
+
gitCtx: GitContext,
|
|
47
|
+
touchedFileCount: number,
|
|
48
|
+
): string {
|
|
49
|
+
const statusIcon = result.status === 'pass' ? '✅' : result.status === 'warn' ? '⚠️' : '❌';
|
|
50
|
+
const statusLabel = result.status === 'pass' ? 'Passed' : result.status === 'warn' ? 'Passed with warnings' : 'Failed';
|
|
51
|
+
|
|
52
|
+
const lines: string[] = [
|
|
53
|
+
COMMENT_MARKER,
|
|
54
|
+
`## ${statusIcon} Autopilot Review — ${statusLabel}`,
|
|
55
|
+
'',
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
// Context line
|
|
59
|
+
const ctx: string[] = [];
|
|
60
|
+
if (config.stack) ctx.push(`**Stack:** ${config.stack}`);
|
|
61
|
+
if (gitCtx.branch) ctx.push(`**Branch:** \`${gitCtx.branch}\``);
|
|
62
|
+
if (gitCtx.commitMessage) ctx.push(`**Commit:** ${gitCtx.commitMessage}`);
|
|
63
|
+
ctx.push(`**Files reviewed:** ${touchedFileCount}`);
|
|
64
|
+
lines.push(ctx.join(' · '), '');
|
|
65
|
+
|
|
66
|
+
// Phase table
|
|
67
|
+
lines.push('| Phase | Status | Findings |');
|
|
68
|
+
lines.push('|---|:---:|:---:|');
|
|
69
|
+
for (const phase of result.phases) {
|
|
70
|
+
const icon = phase.status === 'pass' ? '✅' : phase.status === 'skip' ? '—' :
|
|
71
|
+
phase.status === 'warn' ? '⚠️' : '❌';
|
|
72
|
+
lines.push(`| ${phase.phase} | ${icon} | ${phase.findings.length} |`);
|
|
73
|
+
}
|
|
74
|
+
lines.push('');
|
|
75
|
+
|
|
76
|
+
// Findings by severity
|
|
77
|
+
const critical = result.allFindings.filter(f => f.severity === 'critical');
|
|
78
|
+
const warnings = result.allFindings.filter(f => f.severity === 'warning');
|
|
79
|
+
const notes = result.allFindings.filter(f => f.severity === 'note');
|
|
80
|
+
|
|
81
|
+
if (critical.length > 0) {
|
|
82
|
+
lines.push('### 🚨 Critical');
|
|
83
|
+
for (const f of critical) {
|
|
84
|
+
const loc = f.file !== '<unspecified>' ? `\`${f.file}${f.line ? `:${f.line}` : ''}\` — ` : '';
|
|
85
|
+
lines.push(`- ${loc}${f.message}`);
|
|
86
|
+
if (f.suggestion) lines.push(` > ${f.suggestion}`);
|
|
87
|
+
}
|
|
88
|
+
lines.push('');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (warnings.length > 0) {
|
|
92
|
+
lines.push('### ⚠️ Warnings');
|
|
93
|
+
for (const f of warnings) {
|
|
94
|
+
const loc = f.file !== '<unspecified>' ? `\`${f.file}${f.line ? `:${f.line}` : ''}\` — ` : '';
|
|
95
|
+
lines.push(`- ${loc}${f.message}`);
|
|
96
|
+
if (f.suggestion) lines.push(` > ${f.suggestion}`);
|
|
97
|
+
}
|
|
98
|
+
lines.push('');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (notes.length > 0) {
|
|
102
|
+
lines.push('<details><summary>Notes</summary>\n');
|
|
103
|
+
for (const f of notes) {
|
|
104
|
+
const loc = f.file !== '<unspecified>' ? `\`${f.file}${f.line ? `:${f.line}` : ''}\` — ` : '';
|
|
105
|
+
lines.push(`- ${loc}${f.message}`);
|
|
106
|
+
}
|
|
107
|
+
lines.push('\n</details>\n');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (result.totalCostUSD !== undefined) {
|
|
111
|
+
lines.push(`*Cost: $${result.totalCostUSD.toFixed(4)} · ${result.durationMs}ms · [@delegance/claude-autopilot](https://github.com/axledbetter/claude-autopilot) v${readVersion()}*`);
|
|
112
|
+
} else {
|
|
113
|
+
lines.push(`*${result.durationMs}ms · [@delegance/claude-autopilot](https://github.com/axledbetter/claude-autopilot) v${readVersion()}*`);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return lines.join('\n');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Post or update the autopilot comment on the given PR. */
|
|
120
|
+
export async function postPrComment(
|
|
121
|
+
pr: number,
|
|
122
|
+
body: string,
|
|
123
|
+
cwd: string,
|
|
124
|
+
): Promise<{ action: 'created' | 'updated'; url: string | null }> {
|
|
125
|
+
const existingId = findExistingCommentId(pr, cwd);
|
|
126
|
+
|
|
127
|
+
if (existingId) {
|
|
128
|
+
runSafe('gh', ['api', `repos/{owner}/{repo}/issues/comments/${existingId}`,
|
|
129
|
+
'--method', 'PATCH', '--field', `body=${body}`], { cwd });
|
|
130
|
+
return { action: 'updated', url: null };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const raw = runSafe('gh', ['pr', 'comment', String(pr), '--body', body], { cwd });
|
|
134
|
+
// gh outputs the comment URL on success
|
|
135
|
+
const url = raw?.trim() ?? null;
|
|
136
|
+
return { action: 'created', url };
|
|
137
|
+
}
|
package/src/cli/run.ts
CHANGED
|
@@ -37,6 +37,7 @@ import { detectStack } from '../core/detect/stack.ts';
|
|
|
37
37
|
import { detectProtectedPaths } from '../core/detect/protected-paths.ts';
|
|
38
38
|
import { detectGitContext } from '../core/detect/git-context.ts';
|
|
39
39
|
import { detectProject } from './detector.ts';
|
|
40
|
+
import { detectPrNumber, formatComment, postPrComment } from './pr-comment.ts';
|
|
40
41
|
|
|
41
42
|
function readToolVersion(): string {
|
|
42
43
|
const pkgPath = path.join(path.dirname(fileURLToPath(import.meta.url)), '../../package.json');
|
|
@@ -60,11 +61,12 @@ function fmt(color: keyof typeof C, text: string): string {
|
|
|
60
61
|
export interface RunCommandOptions {
|
|
61
62
|
cwd?: string;
|
|
62
63
|
configPath?: string;
|
|
63
|
-
base?: string;
|
|
64
|
-
files?: string[];
|
|
65
|
-
dryRun?: boolean;
|
|
64
|
+
base?: string; // git base ref (default HEAD~1)
|
|
65
|
+
files?: string[]; // explicit file list (skips git detection)
|
|
66
|
+
dryRun?: boolean; // skip review, print what would run
|
|
66
67
|
format?: 'text' | 'sarif';
|
|
67
68
|
outputPath?: string;
|
|
69
|
+
postComments?: boolean; // post/update summary comment on the open PR
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
/**
|
|
@@ -189,6 +191,22 @@ export async function runCommand(options: RunCommandOptions = {}): Promise<numbe
|
|
|
189
191
|
console.log(fmt('dim', `[run] SARIF written to ${options.outputPath}`));
|
|
190
192
|
}
|
|
191
193
|
|
|
194
|
+
// Post PR comment if requested
|
|
195
|
+
if (options.postComments) {
|
|
196
|
+
const pr = detectPrNumber(cwd);
|
|
197
|
+
if (!pr) {
|
|
198
|
+
console.log(fmt('yellow', ' [run] --post-comments: no open PR found — skipping comment'));
|
|
199
|
+
} else {
|
|
200
|
+
try {
|
|
201
|
+
const body = formatComment(result, config, gitCtx, touchedFiles.length);
|
|
202
|
+
const { action } = await postPrComment(pr, body, cwd);
|
|
203
|
+
console.log(fmt('dim', ` [run] PR #${pr} comment ${action}`));
|
|
204
|
+
} catch (err) {
|
|
205
|
+
console.error(fmt('yellow', ` [run] Failed to post PR comment: ${err instanceof Error ? err.message : String(err)}`));
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
192
210
|
// Print phase summaries
|
|
193
211
|
for (const phase of result.phases) {
|
|
194
212
|
const icon = phase.status === 'pass' ? fmt('green', '✓') :
|