caelum0x 49b183818c Unify gitgram + aitimemachine into the monorepo (de-submodule) and merge vendored engines
Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as
opaque submodule gitlinks on GitHub) into fully-tracked first-party content.

AITM now merges its 7 vendored repos as first-party engines:
- memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts
- git: vendored C git (bundled binary) + gitnexus (in-process code intelligence)
- agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess)

Includes the full session's product build: Gitgram web/mobile/backend features,
AITM website/CLI/MCP, the unified memory layer, engine build tooling
(scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md),
and extensive test suites.

Build artifacts, node_modules, external/, and gemini-cli are gitignored.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-23 14:14:09 +03:00

68 lines
1.9 KiB
Go

// Package ui provides terminal styling and output helpers for beads CLI.
package ui
import (
"os"
"golang.org/x/term"
)
// IsTerminal returns true if stdout is connected to a terminal (TTY).
func IsTerminal() bool {
return term.IsTerminal(int(os.Stdout.Fd()))
}
// IsStderrTerminal returns true if stderr is connected to a terminal (TTY).
// Used to suppress advisory messages (e.g. deprecation notices) when stderr
// is captured by test harnesses or piped to another process.
func IsStderrTerminal() bool {
return term.IsTerminal(int(os.Stderr.Fd()))
}
// ShouldUseColor determines if ANSI color codes should be used.
// Respects standard conventions:
// - BD_GIT_HOOK=1: disables color in git hook context (prevents OSC 11 queries, GH#1303)
// - NO_COLOR: https://no-color.org/ - disables color if set
// - CLICOLOR=0: disables color
// - CLICOLOR_FORCE: forces color even in non-TTY
// - Falls back to TTY detection
func ShouldUseColor() bool {
// Git hook context - disable color to prevent termenv OSC 11 terminal
// background queries that leak escape sequences to the terminal (GH#1303).
// Set by bd hook shim templates before calling 'bd hooks run'.
if os.Getenv("BD_GIT_HOOK") == "1" {
return false
}
// NO_COLOR standard - any value disables color
if os.Getenv("NO_COLOR") != "" {
return false
}
// CLICOLOR=0 disables color
if os.Getenv("CLICOLOR") == "0" {
return false
}
// CLICOLOR_FORCE forces color even in non-TTY
if os.Getenv("CLICOLOR_FORCE") != "" {
return true
}
// Default: use color only if stdout is a TTY
return IsTerminal()
}
// ShouldUseEmoji determines if emoji decorations should be used.
// Disabled in non-TTY mode to keep output machine-readable.
// Can be controlled with BD_NO_EMOJI environment variable.
func ShouldUseEmoji() bool {
// Explicit disable
if os.Getenv("BD_NO_EMOJI") != "" {
return false
}
// Default: use emoji only if stdout is a TTY
return IsTerminal()
}