aiwg
Version:
Deployment tool and support utility for AI context. Copies agents, skills, commands, rules, and behaviors into the paths each AI platform reads (Claude Code, Codex, Copilot, Cursor, Warp, OpenClaw, and 6 more) so one source of truth works across 10 platfo
82 lines • 2.54 kB
JavaScript
/**
* AIWG CLI Environment Detection
*
* Centralized helpers for detecting the runtime environment so handlers
* can make consistent interactive / non-interactive decisions.
*
* Phase 3 of the CLI Stabilization Epic (#920).
*/
/**
* Return true iff the CLI is running attached to an interactive terminal
* where it is safe to prompt the user.
*
* Conditions (all must hold):
* - stdin is a TTY
* - stdout is a TTY
* - TERM is not 'dumb'
* - CI env var is not truthy (matches GitHub Actions, GitLab, CircleCI,
* Travis, Buildkite, Jenkins, and most other CI systems)
* - DEBIAN_FRONTEND is not 'noninteractive' (common in Docker images)
*
* Respects common CI convention: any of
* CI, CONTINUOUS_INTEGRATION, BUILD_NUMBER, RUN_ID, GITHUB_ACTIONS,
* GITLAB_CI, CIRCLECI, TRAVIS, BUILDKITE, JENKINS_URL
* set (to any truthy value) indicates a CI environment.
*
* Handlers MUST call this helper instead of re-deriving the check locally.
* Divergent isTTY checks scattered across handlers have caused bugs in the
* past (#918 audit findings).
*/
export function isInteractive() {
if (!process.stdin.isTTY)
return false;
if (!process.stdout.isTTY)
return false;
if (process.env['TERM'] === 'dumb')
return false;
if (process.env['DEBIAN_FRONTEND'] === 'noninteractive')
return false;
if (isCI())
return false;
return true;
}
/**
* Return true iff we're running in a continuous-integration environment.
* Checks the common CI env vars set by major CI systems.
*/
export function isCI() {
const ciVars = [
'CI',
'CONTINUOUS_INTEGRATION',
'BUILD_NUMBER',
'RUN_ID',
'GITHUB_ACTIONS',
'GITLAB_CI',
'CIRCLECI',
'TRAVIS',
'BUILDKITE',
'JENKINS_URL',
'TF_BUILD', // Azure DevOps
'TEAMCITY_VERSION',
];
for (const v of ciVars) {
const val = process.env[v];
if (val && val !== '0' && val.toLowerCase() !== 'false')
return true;
}
return false;
}
/**
* Return true iff colored output should be emitted.
*
* Honors NO_COLOR (per https://no-color.org) and FORCE_COLOR.
* Requires stdout (or the passed stream) to be a TTY.
*/
export function shouldUseColor(stream = process.stdout) {
if (process.env['NO_COLOR'])
return false;
if (process.env['FORCE_COLOR'] && process.env['FORCE_COLOR'] !== '0')
return true;
return !!stream.isTTY;
}
//# sourceMappingURL=env.js.map