pi-hackerone 0.3.0 → 0.5.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # pi-hackerone
2
2
 
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).
3
+ A pi package that adds HackerOne report fetching, commenting, and triaging powered by [`@matteo.collina/hackerone`](https://www.npmjs.com/package/@matteo.collina/hackerone).
4
4
 
5
5
  ## Install
6
6
 
@@ -67,6 +67,21 @@ Parameters:
67
67
  - `internal` - Post as an internal (team-only) comment instead of a public one.
68
68
  - `attachmentIds` - Optional attachment IDs to attach to the comment.
69
69
 
70
+ ### Tool: `hackerone_triage`
71
+
72
+ Move a specific report to triaged when explicitly requested:
73
+
74
+ ```text
75
+ Move HackerOne report 12345 to triaged.
76
+ ```
77
+
78
+ Parameters:
79
+
80
+ - `reportId` - HackerOne report number/id.
81
+ - `message` - Optional public message visible to the reporter; use `hackerone_comment` with `internal: true` for team-only notes.
82
+
83
+ This action requires the API user's Report Management permission and may notify the reporter.
84
+
70
85
  ### Command: `/hackerone-report`
71
86
 
72
87
  Fetch a report directly from the pi prompt:
@@ -78,6 +93,15 @@ Fetch a report directly from the pi prompt:
78
93
 
79
94
  The command inserts the fetched report into the session as a displayed custom message.
80
95
 
96
+ ### Command: `/hackerone-triage`
97
+
98
+ ```text
99
+ /hackerone-triage 12345
100
+ /hackerone-triage 12345 --message "Confirmed"
101
+ ```
102
+
103
+ The command inserts the updated report state into the session.
104
+
81
105
  ### Command: `/hackerone-comment`
82
106
 
83
107
  Post a comment directly from the pi prompt:
@@ -4,6 +4,8 @@ import { join } from "node:path";
4
4
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
5
5
  import {
6
6
  HackerOneClient,
7
+ ReportState,
8
+ changeReportState,
7
9
  createComment,
8
10
  filterComments,
9
11
  getReport,
@@ -16,6 +18,7 @@ import { Type } from "typebox";
16
18
 
17
19
  const TOOL_NAME = "hackerone_report";
18
20
  const COMMENT_TOOL_NAME = "hackerone_comment";
21
+ const TRIAGE_TOOL_NAME = "hackerone_triage";
19
22
 
20
23
  const reportParameters = Type.Object({
21
24
  reportId: Type.Integer({
@@ -64,6 +67,21 @@ interface CommentToolParams {
64
67
  attachmentIds?: number[];
65
68
  }
66
69
 
70
+ const triageParameters = Type.Object({
71
+ reportId: Type.Integer({
72
+ minimum: 1,
73
+ description: "HackerOne report number/id to move to triaged.",
74
+ }),
75
+ message: Type.Optional(Type.String({
76
+ description: "Optional public message visible to the reporter when the state changes. Do not include team-only notes.",
77
+ })),
78
+ });
79
+
80
+ interface TriageToolParams {
81
+ reportId: number;
82
+ message?: string;
83
+ }
84
+
67
85
  interface FetchReportResult {
68
86
  report: Report;
69
87
  comments?: Activity[];
@@ -197,6 +215,13 @@ async function postComment(options: CommentToolParams, cwd: string): Promise<Act
197
215
  });
198
216
  }
199
217
 
218
+ async function triageReport(options: TriageToolParams, cwd: string): Promise<Report> {
219
+ const client = createClient(cwd);
220
+ return changeReportState(client, options.reportId, ReportState.Triaged, {
221
+ message: options.message,
222
+ });
223
+ }
224
+
200
225
  function formatActor(activity: Activity): string {
201
226
  const actor = activity.relationships?.actor?.data;
202
227
  return actor?.attributes?.username ?? actor?.attributes?.handle ?? actor?.id ?? "unknown";
@@ -278,6 +303,10 @@ function formatReportMarkdown(result: FetchReportResult): string {
278
303
  return lines.join("\n");
279
304
  }
280
305
 
306
+ function formatTriagedReport(report: Report): string {
307
+ return `# HackerOne report #${report.id}\n\n- State: ${report.attributes.state}`;
308
+ }
309
+
281
310
  function formatError(error: unknown): string {
282
311
  if (isAppError(error)) {
283
312
  const retry = error.retryAfter === undefined ? "" : ` Retry after ${error.retryAfter} seconds.`;
@@ -349,6 +378,36 @@ export default function hackerOneExtension(pi: ExtensionAPI) {
349
378
  },
350
379
  });
351
380
 
381
+ pi.registerTool({
382
+ name: TRIAGE_TOOL_NAME,
383
+ label: "HackerOne Triage",
384
+ description: "Move a HackerOne report to triaged using the HackerOne API.",
385
+ promptSnippet: "Move a HackerOne report to triaged by report number/id",
386
+ promptGuidelines: [
387
+ "Use hackerone_triage only when the user explicitly requests moving a specific report to triaged.",
388
+ "Before using hackerone_triage, ensure the user supplied the report number/id.",
389
+ "A state change can notify the reporter; its optional message is visible to the reporter. Use hackerone_comment with internal: true for team-only notes.",
390
+ "Do not call this tool for a request to merely inspect a report.",
391
+ ],
392
+ parameters: triageParameters,
393
+ prepareArguments: normalizeToolArguments,
394
+ async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
395
+ try {
396
+ const report = await triageReport(params, ctx.cwd);
397
+ return {
398
+ content: [{ type: "text", text: formatTriagedReport(report) }],
399
+ details: report,
400
+ };
401
+ } catch (error) {
402
+ return {
403
+ content: [{ type: "text", text: formatError(error) }],
404
+ isError: true,
405
+ details: undefined,
406
+ };
407
+ }
408
+ },
409
+ });
410
+
352
411
  pi.registerCommand("hackerone-report", {
353
412
  description: "Fetch a HackerOne report: /hackerone-report <number> [--comments] [--program handle]",
354
413
  handler: async (args, ctx) => {
@@ -373,6 +432,30 @@ export default function hackerOneExtension(pi: ExtensionAPI) {
373
432
  },
374
433
  });
375
434
 
435
+ pi.registerCommand("hackerone-triage", {
436
+ description: "Move a report to triaged: /hackerone-triage <number> [--message \"text\"]",
437
+ handler: async (args, ctx) => {
438
+ const parsed = parseTriageArgs(args);
439
+ if (!parsed) {
440
+ ctx.ui.notify("Usage: /hackerone-triage <number> [--message \"text\"]", "warning");
441
+ return;
442
+ }
443
+
444
+ try {
445
+ ctx.ui.notify(`Triaging HackerOne report #${parsed.reportId}...`, "info");
446
+ const report = await triageReport(parsed, ctx.cwd);
447
+ pi.sendMessage({
448
+ customType: "hackerone-triage",
449
+ content: formatTriagedReport(report),
450
+ display: true,
451
+ details: report,
452
+ });
453
+ } catch (error) {
454
+ ctx.ui.notify(formatError(error), "error");
455
+ }
456
+ },
457
+ });
458
+
376
459
  pi.registerCommand("hackerone-comment", {
377
460
  description: "Post a comment on a HackerOne report: /hackerone-comment <number> --message \"text\" [--internal] [--attachment-id id]",
378
461
  handler: async (args, ctx) => {
@@ -443,6 +526,17 @@ function tokenizeCommand(input: string): string[] {
443
526
  return tokens;
444
527
  }
445
528
 
529
+ function parseTriageArgs(args: string): TriageToolParams | undefined {
530
+ const tokens = tokenizeCommand(args);
531
+ const reportId = normalizeReportId(tokens[0]);
532
+ if (reportId === undefined) return undefined;
533
+ if (tokens.length === 1) return { reportId };
534
+ if (tokens.length === 3 && tokens[1] === "--message" && tokens[2]) {
535
+ return { reportId, message: tokens[2] };
536
+ }
537
+ return undefined;
538
+ }
539
+
446
540
  function parseCommentArgs(args: string): CommentToolParams | undefined {
447
541
  const tokens = tokenizeCommand(args);
448
542
  const reportId = normalizeReportId(tokens[0]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-hackerone",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "Pi package that adds a HackerOne report tool and slash command.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -16,10 +16,11 @@
16
16
  "README.md"
17
17
  ],
18
18
  "scripts": {
19
+ "test": "node --test 'test/*.test.mjs'",
19
20
  "typecheck": "tsc --noEmit"
20
21
  },
21
22
  "dependencies": {
22
- "@matteo.collina/hackerone": "^0.2.0"
23
+ "@matteo.collina/hackerone": "^0.3.0"
23
24
  },
24
25
  "peerDependencies": {
25
26
  "@earendil-works/pi-coding-agent": "*",
@@ -29,7 +30,8 @@
29
30
  "@earendil-works/pi-coding-agent": "*",
30
31
  "@types/node": "^24.0.0",
31
32
  "typebox": "*",
32
- "typescript": "^5.9.0"
33
+ "typescript": "^5.9.0",
34
+ "undici": "^7.30.2"
33
35
  },
34
36
  "pi": {
35
37
  "extensions": [