Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.PHONY: build test fmt vet

# A tagged checkout gets the nearest semantic Git description. Repositories
# without a reachable tag leave this empty so Go's embedded VCS revision and
# dirty state remain the authoritative development identity.
VERSION ?= $(shell git describe --tags --dirty 2>/dev/null)
LDFLAGS := $(if $(VERSION),-X github.com/merefield/codexometer/internal/version.buildVersion=$(VERSION),)

build:
go build -trimpath -ldflags "$(LDFLAGS)" -o codexometer .

test:
go test ./...

fmt:
go fmt ./...

vet:
go vet ./...
34 changes: 27 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ opening `/status` in your working Codex session.
```text
█▀▀ █▀█ █▀▄ █▀▀ ▀▄▀ █▀█ █▀▄▀█ █▀▀ ▀█▀ █▀▀ █▀█
█▄▄ █▄█ █▄▀ ██▄ █ █ █▄█ █ ▀ █ ██▄ █ ██▄ █▀▄
◉ QUOTA TELEMETRY CONSOLE // CRT-01 // SIGNAL LOCKED
◉ QUOTA TELEMETRY CONSOLE · VERSION 0.7.8
```

![Codexometer Hacker theme showing quota and reset-cycle gauges](assets/codexometer.png)
Expand Down Expand Up @@ -149,9 +149,12 @@ To build the current checkout:
```sh
git clone https://github.com/merefield/codexometer.git
cd codexometer
go build -trimpath -ldflags="-s -w" -o codexometer .
go build -trimpath -o codexometer .
```

On systems with Make, `make build` is an equivalent convenience target that
also injects the nearest reachable Git tag when one exists.

On Windows, use `-o codexometer.exe` instead. The compiled executable is
standalone and does not require Go at runtime. Run it from the project directory
as `./codexometer` (or `.\codexometer.exe` in PowerShell), or copy it into any
Expand Down Expand Up @@ -1024,12 +1027,29 @@ need Go or Codexometer's source dependencies.
## Versioning

Codexometer follows semantic versioning; the current source version is
`v0.7.7`. The Git tag is the release source of truth. Go automatically embeds
`v0.7.8`. The Git tag is the release source of truth. Go automatically embeds
that tag in binaries built with
`go install github.com/merefield/codexometer@v0.7.7`; direct source builds fall
back to the maintained value in `internal/version/version.go`.
`go install github.com/merefield/codexometer@v0.7.8`.

The resolver uses the first version available in this order:

1. a link-time value, such as the nearest Git description injected by
`make build`;
2. Go's embedded module version—an exact tag for a release build or, when Go
supplies one, a pseudo-version such as
`0.7.9-0.<timestamp>-<commit>[+dirty]`;
3. for a local checkout whose module version is `(devel)`, a VCS fallback in
the explicit form `0.7.8-dev+<commit>[.dirty]`;
4. the maintained source version, `0.7.8`, when no build or VCS identity is
available.

The leading `v` used by Git tags and Go module versions is removed in every
case. The VCS fallback is a Codexometer development identity, not a Go
pseudo-version.

Both forms report the embedded version and exit without starting the interface:
The dashboard masthead, app-server client metadata, and both CLI flags all use
that one resolved value. The flags report it and exit without starting the
interface:

```sh
codexometer -v
Expand All @@ -1039,7 +1059,7 @@ codexometer --version
Release automation can override the source-build fallback without editing code:

```sh
go build -ldflags="-s -w -X github.com/merefield/codexometer/internal/version.Fallback=0.7.7" .
go build -ldflags="-s -w -X github.com/merefield/codexometer/internal/version.buildVersion=v0.7.8" .
```

## How refresh works
Expand Down
11 changes: 11 additions & 0 deletions internal/codex/app_server_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package codex

import "github.com/merefield/codexometer/internal/version"

func codexometerClientInfo() map[string]string {
return map[string]string{
"name": "codexometer",
"title": "Codexometer",
"version": version.Current(),
}
}
6 changes: 1 addition & 5 deletions internal/codex/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import (
"time"

"go.starlark.net/starlark"

"github.com/merefield/codexometer/internal/version"
)

const (
Expand Down Expand Up @@ -314,9 +312,7 @@ func startAppServerWithExperimentalUsage(ctx context.Context, binary string, exp
}
go server.readLoop(json.NewDecoder(bufio.NewReader(stdout)))
initialize := map[string]any{
"clientInfo": map[string]string{
"name": "codexometer", "title": "Codexometer", "version": version.Current(),
},
"clientInfo": codexometerClientInfo(),
}
if experimental {
initialize["capabilities"] = map[string]bool{"experimentalApi": true}
Expand Down
10 changes: 1 addition & 9 deletions internal/codex/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"strings"
"sync"
"time"

"github.com/merefield/codexometer/internal/version"
)

const requestTimeout = 15 * time.Second
Expand Down Expand Up @@ -100,13 +98,7 @@ func (c Client) Fetch(ctx context.Context) (Snapshot, error) {
if err := encoder.Encode(map[string]any{
"method": "initialize",
"id": 1,
"params": map[string]any{
"clientInfo": map[string]string{
"name": "codexometer",
"title": "Codexometer",
"version": version.Current(),
},
},
"params": map[string]any{"clientInfo": codexometerClientInfo()},
}); err != nil {
return Snapshot{}, fmt.Errorf("initialize Codex app-server: %w", err)
}
Expand Down
9 changes: 9 additions & 0 deletions internal/codex/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@ import (
"os"
"strings"
"testing"

"github.com/merefield/codexometer/internal/version"
)

func TestCodexometerClientInfoUsesResolvedVersion(t *testing.T) {
info := codexometerClientInfo()
if info["name"] != "codexometer" || info["title"] != "Codexometer" || info["version"] != version.Current() {
t.Fatalf("client info = %#v", info)
}
}

func TestMain(m *testing.M) {
if os.Getenv("CODEXOMETER_FAKE_APP_SERVER") == "1" {
runFakeAppServer()
Expand Down
2 changes: 1 addition & 1 deletion internal/codex/daemon_status_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (p *daemonStatusProvider) ensureConnected(ctx context.Context) error {
UserAgent string `json:"userAgent"`
}
if err := p.request(ctx, "initialize", map[string]any{
"clientInfo": map[string]string{"name": "codexometer", "title": "Codexometer", "version": "monitor"},
"clientInfo": codexometerClientInfo(),
"capabilities": map[string]any{"experimentalApi": true},
}, &initialized); err != nil {
p.disconnect(connection)
Expand Down
3 changes: 3 additions & 0 deletions internal/ui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
tea "charm.land/bubbletea/v2"

"github.com/merefield/codexometer/internal/codex"
"github.com/merefield/codexometer/internal/version"
)

type Fetcher interface {
Expand Down Expand Up @@ -57,6 +58,7 @@ type Model struct {
flashSequence uint64
benchmarkRunner BenchmarkRunner
preferenceStore PreferenceStore
appVersion string

benchmarkState benchmarkState
benchmarkResults []codex.BenchmarkResult
Expand Down Expand Up @@ -315,6 +317,7 @@ func New(fetcher Fetcher, refreshEvery time.Duration) Model {
benchmarkRankMode: benchmarkRankBalanced,
quotaAPIAnchors: make(map[string]quotaAPIAnchor),
quotaAPIIssues: make(map[string]string),
appVersion: version.Current(),
}
if usageFetcher, ok := fetcher.(TokenUsageFetcher); ok {
model.usageFetcher = usageFetcher
Expand Down
7 changes: 7 additions & 0 deletions internal/ui/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/charmbracelet/x/ansi"

"github.com/merefield/codexometer/internal/codex"
"github.com/merefield/codexometer/internal/version"
)

type stubFetcher struct {
Expand Down Expand Up @@ -49,6 +50,12 @@ func (f stubFetcher) Fetch(context.Context) (codex.Snapshot, error) {
return f.snapshot, f.err
}

func TestNewUsesResolvedApplicationVersion(t *testing.T) {
if got := New(nil, time.Minute).appVersion; got != version.Current() {
t.Fatalf("model version = %q, want %q", got, version.Current())
}
}

func TestThemeHotkeyCyclesAndWraps(t *testing.T) {
model := New(nil, time.Minute)
for want := themeRust; want < themeCount; want++ {
Expand Down
12 changes: 8 additions & 4 deletions internal/ui/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (m Model) render() string {
if !m.loading || len(m.snapshot.Meters()) > 0 {
account = m.renderAccount(colors)
}
header := renderHeader(contentWidth, m.phase, m.renderSignalStatus(contentWidth, colors), account, colors)
header := renderHeader(contentWidth, m.phase, m.renderSignalStatus(contentWidth, colors), account, m.appVersion, colors)
parts := []string{header}
if m.loading && len(m.snapshot.Meters()) == 0 {
parts = append(parts, renderBoot(contentWidth, m.phase, colors))
Expand Down Expand Up @@ -71,18 +71,22 @@ func (m Model) render() string {
return lipgloss.NewStyle().Margin(1, 2).Render(panel)
}

func renderHeader(width, phase int, signal, account string, colors palette) string {
func renderHeader(width, phase int, signal, account, appVersion string, colors palette) string {
displayedVersion := strings.ToUpper(strings.TrimSpace(strings.TrimPrefix(appVersion, "v")))
if displayedVersion == "" {
displayedVersion = "DEVELOPMENT"
}
if width < 64 {
title := colors.header().Render("▰ CODEXOMETER ▰")
subtitle := colors.dimmed().Render("QUOTA TELEMETRY CONSOLE // CRT-01")
subtitle := colors.dimmed().Render(ansi.Truncate("QUOTA TELEMETRY // VERSION "+displayedVersion, width, ""))
return joinRight(title, signal, width) + "\n" + joinRight(subtitle, account, width)
}
logo := []string{
"█▀▀ █▀█ █▀▄ █▀▀ ▀▄▀ █▀█ █▀▄▀█ █▀▀ ▀█▀ █▀▀ █▀█",
"█▄▄ █▄█ █▄▀ ██▄ █ █ █▄█ █ ▀ █ ██▄ █ ██▄ █▀▄",
}
beacon := []string{"◉", "◎", "◌", "◎"}[phase%4]
subtitle := colors.dimmed().Render(fmt.Sprintf("%s QUOTA TELEMETRY CONSOLE // CRT-01 // SIGNAL LOCKED", beacon))
subtitle := colors.dimmed().Render(fmt.Sprintf("%s QUOTA TELEMETRY CONSOLE · VERSION %s", beacon, displayedVersion))
return joinRight(colors.header().Render(logo[0]), signal, width) + "\n" +
colors.header().Render(logo[1]) + "\n" +
joinRight(subtitle, account, width)
Expand Down
6 changes: 5 additions & 1 deletion internal/ui/view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,14 @@ func TestStatusAndFooterKeepOnlyEssentialMetadata(t *testing.T) {
snapshot: codex.DemoSnapshot(),
nextRefresh: time.Now().Add(time.Minute),
meterView: viewBars,
appVersion: "0.7.8-dev+abc123.dirty",
}
colors := paletteFor(themeHacker)
account := ansi.Strip(model.renderAccount(colors))
if account != "ACCOUNT // PLUS" {
t.Fatalf("account metadata = %q", account)
}
header := ansi.Strip(renderHeader(100, 0, model.renderSignalStatus(100, colors), model.renderAccount(colors), colors))
header := ansi.Strip(renderHeader(100, 0, model.renderSignalStatus(100, colors), model.renderAccount(colors), model.appVersion, colors))
headerLines := strings.Split(header, "\n")
firstLine := headerLines[0]
status := ansi.Strip(model.renderSignalStatus(100, colors))
Expand All @@ -152,6 +153,9 @@ func TestStatusAndFooterKeepOnlyEssentialMetadata(t *testing.T) {
if !strings.HasSuffix(headerLines[len(headerLines)-1], "ACCOUNT // PLUS") {
t.Fatalf("account is not aligned with the subtitle: %q", headerLines[len(headerLines)-1])
}
if !strings.Contains(headerLines[len(headerLines)-1], "VERSION 0.7.8-DEV+ABC123.DIRTY") {
t.Fatalf("resolved build version is absent from the masthead: %q", headerLines[len(headerLines)-1])
}
footer := ansi.Strip(model.renderFooter(100, colors))
if !strings.Contains(footer, "THEME // HACKER") || strings.Contains(footer, "VIEW") {
t.Fatalf("footer theme readout = %q", footer)
Expand Down
82 changes: 47 additions & 35 deletions internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,64 @@ package version
import (
"runtime/debug"
"strings"
"time"
)

// Fallback is the version reported by binaries built directly from a source
// checkout. Release automation may override it with:
//
// -X github.com/merefield/codexometer/internal/version.Fallback=1.2.3
var Fallback = "0.7.7"
// Version is the source fallback. Tagged module installs and builds made with
// an injected buildVersion use their embedded version instead.
const Version = "0.7.8"

// Current returns the module version embedded by Go for tagged installs, or
// Fallback for ordinary source builds. The leading tag prefix is omitted so
// callers can choose how to present it.
// buildVersion may be populated at link time from the nearest Git tag.
var buildVersion string

// Current returns a display-ready version without the conventional v prefix
// used by Go module tags. It prefers an injected version, then Go's embedded
// module version, then a VCS-based development identity.
func Current() string {
if info, ok := debug.ReadBuildInfo(); ok {
return selectVersion(info.Main.Version, Fallback)
if value := normalize(buildVersion); value != "" {
return value
}
return selectVersion("", Fallback)
}

func selectVersion(moduleVersion, fallback string) string {
moduleVersion = strings.TrimSpace(moduleVersion)
if moduleVersion != "" && moduleVersion != "(devel)" && !isPseudoVersion(moduleVersion) {
return strings.TrimPrefix(moduleVersion, "v")
if info, ok := debug.ReadBuildInfo(); ok {
if value := normalize(info.Main.Version); value != "" {
return value
}
if value := vcsFallback(info.Settings); value != "" {
return value
}
}
return strings.TrimPrefix(strings.TrimSpace(fallback), "v")
return Version
}

func isPseudoVersion(value string) bool {
parts := strings.Split(strings.TrimPrefix(strings.TrimSpace(value), "v"), "-")
if len(parts) < 3 {
return false
// vcsFallback identifies a local checkout when Go reports Main.Version as
// "(devel)". It is intentionally distinct from a Go pseudo-version: Go's own
// embedded module version remains authoritative whenever one is available.
func vcsFallback(settings []debug.BuildSetting) string {
revision := ""
modified := false
for _, setting := range settings {
switch setting.Key {
case "vcs.revision":
revision = setting.Value
case "vcs.modified":
modified = setting.Value == "true"
}
}
timestamp, revision := parts[len(parts)-2], parts[len(parts)-1]
if clean, _, found := strings.Cut(revision, "+"); found {
revision = clean
if revision == "" {
return ""
}
if len(timestamp) != 14 || len(revision) < 7 {
return false
if len(revision) > 12 {
revision = revision[:12]
}
if _, err := time.Parse("20060102150405", timestamp); err != nil {
return false
value := Version + "-dev+" + revision
if modified {
value += ".dirty"
}
Comment thread
merefield marked this conversation as resolved.
Resolved
for _, character := range revision {
if !strings.ContainsRune("0123456789abcdef", character) {
return false
}
return value
}

func normalize(value string) string {
value = strings.TrimSpace(value)
if value == "" || value == "(devel)" {
return ""
}
return true
return strings.TrimPrefix(value, "v")
}
Loading
Loading