pi-hackerone 0.1.0 → 0.3.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 +38 -17
- package/extensions/hackerone.ts +206 -5
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
# pi-hackerone
|
|
2
2
|
|
|
3
|
-
A pi package that adds a HackerOne report fetcher powered by [`@matteo.collina/hackerone`](https://www.npmjs.com/package/@matteo.collina/hackerone).
|
|
3
|
+
A pi package that adds a HackerOne report fetcher and commenter powered by [`@matteo.collina/hackerone`](https://www.npmjs.com/package/@matteo.collina/hackerone).
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Install from npm as a pi package:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pi install npm:pi-hackerone
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or try it without installing:
|
|
6
14
|
|
|
7
15
|
```sh
|
|
8
|
-
npm
|
|
16
|
+
pi -e npm:pi-hackerone
|
|
9
17
|
```
|
|
10
18
|
|
|
11
19
|
Configure credentials in pi settings. Global settings live at `~/.pi/agent/settings.json`; project settings live at `.pi/settings.json` and override global settings.
|
|
@@ -28,20 +36,6 @@ export HACKERONE_API_TOKEN="your_api_token"
|
|
|
28
36
|
export HACKERONE_API_BASE_URL="https://api.hackerone.com/v1"
|
|
29
37
|
```
|
|
30
38
|
|
|
31
|
-
## Use locally
|
|
32
|
-
|
|
33
|
-
From this repository:
|
|
34
|
-
|
|
35
|
-
```sh
|
|
36
|
-
pi -e ./extensions/hackerone.ts
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
Or install as a local pi package:
|
|
40
|
-
|
|
41
|
-
```sh
|
|
42
|
-
pi install .
|
|
43
|
-
```
|
|
44
|
-
|
|
45
39
|
## What it adds
|
|
46
40
|
|
|
47
41
|
### Tool: `hackerone_report`
|
|
@@ -58,6 +52,21 @@ Parameters:
|
|
|
58
52
|
- `includeComments` - Fetch comments from the activity API.
|
|
59
53
|
- `program` - Program handle override, useful when fetching comments.
|
|
60
54
|
|
|
55
|
+
### Tool: `hackerone_comment`
|
|
56
|
+
|
|
57
|
+
The agent can call this tool to post a comment on a report:
|
|
58
|
+
|
|
59
|
+
```text
|
|
60
|
+
Post a public comment on HackerOne report 12345 saying the fix is deployed.
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Parameters:
|
|
64
|
+
|
|
65
|
+
- `reportId` - HackerOne report number/id.
|
|
66
|
+
- `message` - The comment message to post.
|
|
67
|
+
- `internal` - Post as an internal (team-only) comment instead of a public one.
|
|
68
|
+
- `attachmentIds` - Optional attachment IDs to attach to the comment.
|
|
69
|
+
|
|
61
70
|
### Command: `/hackerone-report`
|
|
62
71
|
|
|
63
72
|
Fetch a report directly from the pi prompt:
|
|
@@ -69,4 +78,16 @@ Fetch a report directly from the pi prompt:
|
|
|
69
78
|
|
|
70
79
|
The command inserts the fetched report into the session as a displayed custom message.
|
|
71
80
|
|
|
81
|
+
### Command: `/hackerone-comment`
|
|
82
|
+
|
|
83
|
+
Post a comment directly from the pi prompt:
|
|
84
|
+
|
|
85
|
+
```text
|
|
86
|
+
/hackerone-comment 12345 --message "A fix has been deployed, can you retest?"
|
|
87
|
+
/hackerone-comment 12345 --message "Internal triage note" --internal
|
|
88
|
+
/hackerone-comment 12345 --message "See attached POC" --attachment-id 42
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
When a comment is posted, the inserted message is a Markdown summary of the posted comment.
|
|
92
|
+
|
|
72
93
|
> HackerOne reports can contain sensitive vulnerability details and attachments metadata. Only load this extension in trusted pi sessions.
|
package/extensions/hackerone.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { join } from "node:path";
|
|
|
4
4
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
5
5
|
import {
|
|
6
6
|
HackerOneClient,
|
|
7
|
+
createComment,
|
|
7
8
|
filterComments,
|
|
8
9
|
getReport,
|
|
9
10
|
isAppError,
|
|
@@ -14,6 +15,7 @@ import {
|
|
|
14
15
|
import { Type } from "typebox";
|
|
15
16
|
|
|
16
17
|
const TOOL_NAME = "hackerone_report";
|
|
18
|
+
const COMMENT_TOOL_NAME = "hackerone_comment";
|
|
17
19
|
|
|
18
20
|
const reportParameters = Type.Object({
|
|
19
21
|
reportId: Type.Integer({
|
|
@@ -35,7 +37,32 @@ interface FetchReportOptions {
|
|
|
35
37
|
program?: string;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
|
|
40
|
+
const commentParameters = Type.Object({
|
|
41
|
+
reportId: Type.Integer({
|
|
42
|
+
minimum: 1,
|
|
43
|
+
description: "HackerOne report number/id to comment on.",
|
|
44
|
+
}),
|
|
45
|
+
message: Type.String({
|
|
46
|
+
minLength: 1,
|
|
47
|
+
description: "The comment message to post.",
|
|
48
|
+
}),
|
|
49
|
+
internal: Type.Optional(Type.Boolean({
|
|
50
|
+
default: false,
|
|
51
|
+
description: "Post as an internal (team-only) comment instead of a public one.",
|
|
52
|
+
})),
|
|
53
|
+
attachmentIds: Type.Optional(Type.Array(Type.Integer({
|
|
54
|
+
minimum: 1,
|
|
55
|
+
}), {
|
|
56
|
+
description: "Optional attachment IDs to attach to the comment.",
|
|
57
|
+
})),
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
interface CommentToolParams {
|
|
61
|
+
reportId: number;
|
|
62
|
+
message: string;
|
|
63
|
+
internal?: boolean;
|
|
64
|
+
attachmentIds?: number[];
|
|
65
|
+
}
|
|
39
66
|
|
|
40
67
|
interface FetchReportResult {
|
|
41
68
|
report: Report;
|
|
@@ -115,9 +142,9 @@ function normalizeReportId(value: unknown): number | undefined {
|
|
|
115
142
|
return undefined;
|
|
116
143
|
}
|
|
117
144
|
|
|
118
|
-
function normalizeToolArguments(args: unknown):
|
|
145
|
+
function normalizeToolArguments<T extends object>(args: unknown): T {
|
|
119
146
|
if (!args || typeof args !== "object") {
|
|
120
|
-
return args as
|
|
147
|
+
return args as T;
|
|
121
148
|
}
|
|
122
149
|
|
|
123
150
|
const record = args as Record<string, unknown>;
|
|
@@ -127,10 +154,10 @@ function normalizeToolArguments(args: unknown): ReportToolParams {
|
|
|
127
154
|
?? normalizeReportId(record.id);
|
|
128
155
|
|
|
129
156
|
if (reportId === undefined || record.reportId === reportId) {
|
|
130
|
-
return args as
|
|
157
|
+
return args as T;
|
|
131
158
|
}
|
|
132
159
|
|
|
133
|
-
return { ...record, reportId } as
|
|
160
|
+
return { ...record, reportId } as T;
|
|
134
161
|
}
|
|
135
162
|
|
|
136
163
|
function getProgramHandle(report: Report, fallback?: string): string | undefined {
|
|
@@ -161,11 +188,36 @@ async function fetchReport(options: FetchReportOptions, cwd: string): Promise<Fe
|
|
|
161
188
|
return { report, comments, programHandle, warnings };
|
|
162
189
|
}
|
|
163
190
|
|
|
191
|
+
async function postComment(options: CommentToolParams, cwd: string): Promise<Activity> {
|
|
192
|
+
const client = createClient(cwd);
|
|
193
|
+
return createComment(client, options.reportId, {
|
|
194
|
+
message: options.message,
|
|
195
|
+
internal: options.internal ?? false,
|
|
196
|
+
attachmentIds: options.attachmentIds,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
164
200
|
function formatActor(activity: Activity): string {
|
|
165
201
|
const actor = activity.relationships?.actor?.data;
|
|
166
202
|
return actor?.attributes?.username ?? actor?.attributes?.handle ?? actor?.id ?? "unknown";
|
|
167
203
|
}
|
|
168
204
|
|
|
205
|
+
function formatCommentMarkdown(comment: Activity, reportId: number): string {
|
|
206
|
+
const actor = comment.relationships?.actor?.data;
|
|
207
|
+
const actorName = actor?.attributes?.username ?? actor?.attributes?.handle ?? actor?.id ?? "unknown";
|
|
208
|
+
const visibility = comment.attributes.internal ? "internal" : "public";
|
|
209
|
+
const lines = [
|
|
210
|
+
`# Comment posted on report #${reportId}`,
|
|
211
|
+
"",
|
|
212
|
+
`- Visibility: ${visibility}`,
|
|
213
|
+
`- Author: ${actorName}`,
|
|
214
|
+
`- Created: ${comment.attributes.created_at}`,
|
|
215
|
+
"",
|
|
216
|
+
comment.attributes.message ?? "_(empty comment)_",
|
|
217
|
+
];
|
|
218
|
+
return lines.join("\n");
|
|
219
|
+
}
|
|
220
|
+
|
|
169
221
|
function formatReportMarkdown(result: FetchReportResult): string {
|
|
170
222
|
const { report, comments, programHandle, warnings } = result;
|
|
171
223
|
const reporter = report.relationships.reporter?.data;
|
|
@@ -268,6 +320,35 @@ export default function hackerOneExtension(pi: ExtensionAPI) {
|
|
|
268
320
|
},
|
|
269
321
|
});
|
|
270
322
|
|
|
323
|
+
pi.registerTool({
|
|
324
|
+
name: COMMENT_TOOL_NAME,
|
|
325
|
+
label: "HackerOne Comment",
|
|
326
|
+
description: "Post a public or internal comment on a HackerOne report using the HackerOne API.",
|
|
327
|
+
promptSnippet: "Post a comment on a HackerOne report by report number/id",
|
|
328
|
+
promptGuidelines: [
|
|
329
|
+
"Use hackerone_comment when the user wants to add a comment to a HackerOne report.",
|
|
330
|
+
"Before using hackerone_comment, ensure the user provided the report number/id and the comment message.",
|
|
331
|
+
"Set internal to true when the comment should only be visible to the program's team.",
|
|
332
|
+
],
|
|
333
|
+
parameters: commentParameters,
|
|
334
|
+
prepareArguments: normalizeToolArguments,
|
|
335
|
+
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
336
|
+
try {
|
|
337
|
+
const result = { comment: await postComment(params, ctx.cwd), reportId: params.reportId };
|
|
338
|
+
return {
|
|
339
|
+
content: [{ type: "text", text: formatCommentMarkdown(result.comment, result.reportId) }],
|
|
340
|
+
details: result,
|
|
341
|
+
};
|
|
342
|
+
} catch (error) {
|
|
343
|
+
return {
|
|
344
|
+
content: [{ type: "text", text: formatError(error) }],
|
|
345
|
+
isError: true,
|
|
346
|
+
details: undefined,
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
},
|
|
350
|
+
});
|
|
351
|
+
|
|
271
352
|
pi.registerCommand("hackerone-report", {
|
|
272
353
|
description: "Fetch a HackerOne report: /hackerone-report <number> [--comments] [--program handle]",
|
|
273
354
|
handler: async (args, ctx) => {
|
|
@@ -291,6 +372,126 @@ export default function hackerOneExtension(pi: ExtensionAPI) {
|
|
|
291
372
|
}
|
|
292
373
|
},
|
|
293
374
|
});
|
|
375
|
+
|
|
376
|
+
pi.registerCommand("hackerone-comment", {
|
|
377
|
+
description: "Post a comment on a HackerOne report: /hackerone-comment <number> --message \"text\" [--internal] [--attachment-id id]",
|
|
378
|
+
handler: async (args, ctx) => {
|
|
379
|
+
const parsed = parseCommentArgs(args);
|
|
380
|
+
if (!parsed) {
|
|
381
|
+
ctx.ui.notify(
|
|
382
|
+
"Usage: /hackerone-comment <number> --message \"text\" [--internal] [--attachment-id id]",
|
|
383
|
+
"warning",
|
|
384
|
+
);
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
try {
|
|
389
|
+
ctx.ui.notify(`Posting comment on HackerOne report #${parsed.reportId}...`, "info");
|
|
390
|
+
const comment = await postComment(parsed, ctx.cwd);
|
|
391
|
+
pi.sendMessage({
|
|
392
|
+
customType: "hackerone-comment",
|
|
393
|
+
content: formatCommentMarkdown(comment, parsed.reportId),
|
|
394
|
+
display: true,
|
|
395
|
+
details: { comment, reportId: parsed.reportId },
|
|
396
|
+
});
|
|
397
|
+
} catch (error) {
|
|
398
|
+
ctx.ui.notify(formatError(error), "error");
|
|
399
|
+
}
|
|
400
|
+
},
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
function tokenizeCommand(input: string): string[] {
|
|
405
|
+
const tokens: string[] = [];
|
|
406
|
+
let current = "";
|
|
407
|
+
let inSingle = false;
|
|
408
|
+
let inDouble = false;
|
|
409
|
+
let escaping = false;
|
|
410
|
+
|
|
411
|
+
for (const ch of input) {
|
|
412
|
+
if (escaping) {
|
|
413
|
+
current += ch;
|
|
414
|
+
escaping = false;
|
|
415
|
+
continue;
|
|
416
|
+
}
|
|
417
|
+
if (ch === "\\") {
|
|
418
|
+
escaping = true;
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
if (ch === "'" && !inDouble) {
|
|
422
|
+
inSingle = !inSingle;
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
if (ch === '"' && !inSingle) {
|
|
426
|
+
inDouble = !inDouble;
|
|
427
|
+
continue;
|
|
428
|
+
}
|
|
429
|
+
if (/\s/.test(ch) && !inSingle && !inDouble) {
|
|
430
|
+
if (current) {
|
|
431
|
+
tokens.push(current);
|
|
432
|
+
current = "";
|
|
433
|
+
}
|
|
434
|
+
continue;
|
|
435
|
+
}
|
|
436
|
+
current += ch;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
if (current) {
|
|
440
|
+
tokens.push(current);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
return tokens;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function parseCommentArgs(args: string): CommentToolParams | undefined {
|
|
447
|
+
const tokens = tokenizeCommand(args);
|
|
448
|
+
const reportId = normalizeReportId(tokens[0]);
|
|
449
|
+
|
|
450
|
+
if (reportId === undefined) {
|
|
451
|
+
return undefined;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
const options: Partial<CommentToolParams> = { reportId };
|
|
455
|
+
for (let index = 1; index < tokens.length; index += 1) {
|
|
456
|
+
const token = tokens[index];
|
|
457
|
+
if (token === "--internal") {
|
|
458
|
+
options.internal = true;
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
if (token === "--message") {
|
|
463
|
+
const message = tokens[index + 1];
|
|
464
|
+
if (!message) {
|
|
465
|
+
return undefined;
|
|
466
|
+
}
|
|
467
|
+
options.message = message;
|
|
468
|
+
index += 1;
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
if (token === "--attachment-id") {
|
|
473
|
+
const value = tokens[index + 1];
|
|
474
|
+
if (!value) {
|
|
475
|
+
return undefined;
|
|
476
|
+
}
|
|
477
|
+
const attachmentId = Number.parseInt(value, 10);
|
|
478
|
+
if (!Number.isInteger(attachmentId) || attachmentId < 1) {
|
|
479
|
+
return undefined;
|
|
480
|
+
}
|
|
481
|
+
options.attachmentIds ??= [];
|
|
482
|
+
options.attachmentIds.push(attachmentId);
|
|
483
|
+
index += 1;
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
return undefined;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
if (!options.message) {
|
|
491
|
+
return undefined;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
return options as CommentToolParams;
|
|
294
495
|
}
|
|
295
496
|
|
|
296
497
|
function parseCommandArgs(args: string): FetchReportOptions | undefined {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-hackerone",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Pi package that adds a HackerOne report tool and slash command.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"typecheck": "tsc --noEmit"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@matteo.collina/hackerone": "^0.
|
|
22
|
+
"@matteo.collina/hackerone": "^0.2.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@earendil-works/pi-coding-agent": "*",
|