Build the environment for a hook command. The full parent env is inherited * (so PATH, HOME, npx, git, … all work) minus anything that looks like a * credential — hooks must never see the user's API token.
(cwd: string)
| 366 | * (so PATH, HOME, npx, git, … all work) minus anything that looks like a |
| 367 | * credential — hooks must never see the user's API token. */ |
| 368 | function buildHookEnv(cwd: string): NodeJS.ProcessEnv { |
| 369 | const env: NodeJS.ProcessEnv = { MATTERAI_PROJECT_DIR: cwd } |
| 370 | for (const [key, value] of Object.entries(process.env)) { |
| 371 | if (value === undefined) continue |
| 372 | if (HOOK_ENV_REDACT_EXACT.has(key)) continue |
| 373 | if (HOOK_ENV_REDACT_PATTERN.test(key)) continue |
| 374 | env[key] = value |
| 375 | } |
| 376 | return env |
| 377 | } |
| 378 | |
| 379 | function truncate(text: string, max: number): string { |
| 380 | const oneLine = text.replace(/\s+/g, " ").trim() |