v2.0.0: modernised velocity post extraction from foundryos and alloy#1
Merged
Conversation
Updates go.mod, all internal imports, examples, slogbridge, benchmarks, and README install/import snippets to github.com/tensorfoundrylabs/velocity/v2.
…ates, TTYRenderable Three root causes found and fixed in one pass: 1. template.useColours was always true when the theme had colours, causing ANSI to leak into pipes and files. It now derives from actual TTY state at construction. 2. StatusItem/Group/ContinuationBlock detected TTY from the io.Writer passed to Render(), but Logger.Render() passes an intermediate *bytes.Buffer — which is never a terminal. Added TTYRenderable interface with RenderTTY(w, isTTY bool) and updated Logger.Render/RenderRaw to call it, passing the console writer's resolved isTTY so colour decisions are always correct. 3. On Windows, terminal emulators (VS Code, Git Bash, Windows Terminal) proxy stdout through a named pipe; term.IsTerminal returns false even on a real terminal. Added FORCE_COLOR / NO_COLOR env var support via resolveColourForWriter(). Set FORCE_COLOR=1 to force colour in any of these environments. ConsoleWriter.SetTheme now also updates template.useColours to match the new theme and current TTY state, so a SetTheme call on a TTY writer correctly re-enables colour.
Four root causes:
1. Theme.ResetStr() was missing — renderers always emitted Reset (\033[0m) even
when the colour prefix was an empty string (mono/noColour theme). Added
Theme.ResetStr() that returns "" for noColour themes; all render functions in
renderable.go, pretty.go, continuation.go, group.go, and status.go updated to
use it instead of the bare Reset constant.
2. NewPrettyFromLogger used log.Theme() which always returns the colour theme.
Changed to log.Style() which returns noColourTheme when colour is off.
3. NewPretty(w, nil) always fell back to ThemeNightOwl regardless of TTY state.
Now calls resolveColourForWriter(w) and selects ThemeMono when colour is off.
4. Logger.Style() only checked cfg.DisableColour and writer presence, not the
actual resolved TTY state of the console writer. Added isTTY check so callers
using style.Format() / style.Wrap() get plain text in NO_COLOR and piped modes.
Two test assertions that checked the old (incorrect) behaviour updated to use
t.Setenv("FORCE_COLOR","1") to exercise the colour path in CI without a TTY.
Five examples were passing explicit theme objects (ThemeNightOwl) or calling velocity.Hyperlink() directly without a TTY guard, causing ANSI and OSC 8 sequences to leak into pipes and NO_COLOR runs. - tables, notify, terminal-velocity: NewTable/NewTree/NewBox calls switched from velocity.ThemeNightOwl to log.Style() so colour follows the resolved TTY state. - themes: slot demo uses log.Style() instead of the raw theme so NO_COLOR is respected even in a demo context. - hyperlinks: Hyperlink() calls with WithHyperlinkFallback() cannot override OSC 8 when HyperlinksSupported()=true; replace with plain string construction or TTY guard so pipes always get clean text. - terminal-velocity: added a local link() helper that gates Hyperlink on IsTerminalWriter(os.Stdout) && HyperlinksSupported().
…on non-TTY output
…tem Secure fields
scanSecure was a per-Logger atomic copied at With()/Detailed() time. When a parent gained an untrusted writer after a child was created, recomputeScanSecure only updated the parent — children kept stale false, leaking <secure> tags in plaintext. Move scanSecure onto the shared writerSet so every AddWriter/RemoveWriter call is immediately visible to all loggers sharing the topology. Regression test: TestSecureTag_ChildLoggerSeesWriterAddedAfterCreation. Positive test: TestSecureTag_TrustedWriterAddedAfterChildDoesNotFlipScan.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This is the first proper release of velocity post extraction out of FoundryOS and Alloy.
Module path bumped to
github.com/tensorfoundrylabs/velocity/v2. 45 commits, ~7 months of work folded onto one branch.Headline changes
velocity→velocity/v2(Go semver requirement for v2+)New(opts ...Option)replacesNewWithBuilder+Preset*familyvelocity/live; slog handler invelocity/slogbridge; all renderables (Box/Table/Tree/Banner/KeyValue/SystemInfo/StatusItem/Group/ContinuationBlock) live in rootprettypackage killed:Prettyfacade and renderables consolidated into root;NewPrettyFromLogger(log)shares the logger's mutexNewTheme+ThemeOption; semanticStyleSlotenum;Theme.Format/Wrap/StylishWriterTrusted()opt-in; capability interfaces (ThemedWriter,LeveledWriter,FlushableWriter,TrustedWriter)RingBufferWriter,Notify/NotifyLines/NotifyBox,Hyperlink(OSC 8),Secure/SecureURL/Redacted/Truncatedfield constructors with<secure>tag scanningLogger.Statusredesigned to render inline (indented under parent log line, no own timestamp); JSON writers still emit structured recordsNO_COLOR/FORCE_COLORenv var support, correct TTY gating end-to-end