()
| 444 | } |
| 445 | |
| 446 | export async function buildHatchContext(): Promise<string> { |
| 447 | const cwd = getCwd() |
| 448 | const results = await Promise.allSettled([ |
| 449 | readFile(join(cwd, 'package.json'), 'utf8'), |
| 450 | execa('git', ['--no-optional-locks', 'log', '--oneline', '-n', String(RECENT_COMMITS_COUNT)], { |
| 451 | cwd, |
| 452 | reject: false, |
| 453 | }), |
| 454 | ]) |
| 455 | |
| 456 | const parts: string[] = [] |
| 457 | |
| 458 | const packageResult = results[0] |
| 459 | if (packageResult?.status === 'fulfilled') { |
| 460 | try { |
| 461 | const pkg = JSON.parse(packageResult.value) as { |
| 462 | description?: string |
| 463 | name?: string |
| 464 | } |
| 465 | if (pkg.name) { |
| 466 | parts.push( |
| 467 | `project: ${pkg.name}${pkg.description ? ` — ${pkg.description}` : ''}`, |
| 468 | ) |
| 469 | } |
| 470 | } catch {} |
| 471 | } |
| 472 | |
| 473 | const gitResult = results[1] |
| 474 | if (gitResult?.status === 'fulfilled') { |
| 475 | const stdout = gitResult.value.stdout.trim() |
| 476 | if (stdout) { |
| 477 | parts.push(`recent commits:\n${stdout}`) |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | return parts.join('\n') |
| 482 | } |
| 483 | |
| 484 | export async function fireHatchReaction( |
| 485 | companion: Companion, |
no test coverage detected