MCPcopy Create free account
hub / github.com/Noumena-Network/code / buildHatchContext

Function buildHatchContext

src/buddy/observer.ts:446–482  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

444}
445
446export 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
484export async function fireHatchReaction(
485 companion: Companion,

Callers 1

fireHatchReactionFunction · 0.85

Calls 2

getCwdFunction · 0.85
readFileFunction · 0.85

Tested by

no test coverage detected