Skip to content

Add Operator() method to Signals#5

Merged
clouvet merged 1 commit into
mainfrom
add-operator-method
Jul 13, 2026
Merged

Add Operator() method to Signals#5
clouvet merged 1 commit into
mainfrom
add-operator-method

Conversation

@clouvet

@clouvet clouvet commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds an Operator() method on Signals that returns a single classification string
  • Precedence: ci > agent > interactive > unknown
  • Convenience for consumers that need one label without reimplementing the precedence logic
  • Raw fields (CI, Agent, Interactive) remain available for finer-grained use

Usage

s := clientsignals.DetectOnce()
fmt.Println(s.Operator())    // "ci", "agent", "interactive", or "unknown"
fmt.Println(s.Agent)          // e.g. "claude-code" (when Operator() == "agent")

Motivation

flyctl metrics needs to classify deploy/launch traffic by operator type. Rather than each consumer reimplementing the same precedence switch, this centralizes it in the library.

Related PRs

Test plan

  • go test ./... passes
  • Table-driven tests cover all precedence cases (ci wins over agent, agent wins over interactive, unknown fallback)

🤖 Generated with Claude Code

Returns a single classification string for the process operator:
ci > agent > interactive > unknown. Convenience for consumers that
want one label without reimplementing the precedence logic.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a small convenience API to the Go clientsignals package: a Signals.Operator() method that collapses the existing CI, Agent, and Interactive signals into a single stable classification label with a defined precedence order. This helps downstream consumers avoid re-implementing the same precedence logic while still leaving the raw signal fields available for more detailed use.

Changes:

  • Added Signals.Operator() returning one of: "ci", "agent", "interactive", "unknown" with precedence ci > agent > interactive > unknown.
  • Added a table-driven unit test covering all precedence branches and the default fallback.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
go/signals.go Adds Operator() method to map existing signals into a single operator classification string with documented precedence.
go/signals_test.go Adds table-driven tests validating Operator() precedence and fallback behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@clouvet clouvet merged commit 3a1e44d into main Jul 13, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants