okr

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package okr provides types and utilities for OKR (Objectives and Key Results) goal-setting documents.

OKR is a framework popularized by Intel and Google for setting and communicating goals and results. Each Objective has associated Key Results that define how success is measured.

Key characteristics of OKRs:

  • Objectives are qualitative, inspirational goals
  • Key Results are quantitative, measurable outcomes
  • Progress is scored 0.0-1.0, where 0.7 is typically considered success
  • OKRs are typically set quarterly with annual themes

This package consolidates OKR types from both standalone OKR documents and PRD-embedded OKRs, providing a single source of truth.

Index

Constants

View Source
const (
	StatusDraft     = "Draft"
	StatusActive    = "Active"
	StatusCompleted = "Completed"
	StatusCancelled = "Cancelled"
)

Status constants for OKR lifecycle.

View Source
const (
	ConfidenceLow    = "Low"    // 0-30% likely to achieve
	ConfidenceMedium = "Medium" // 30-70% likely to achieve
	ConfidenceHigh   = "High"   // 70-100% likely to achieve
)

Confidence constants for Key Result confidence levels.

View Source
const (
	ScoreExcellent = 1.0 // Fully achieved
	ScoreGood      = 0.7 // Typical success threshold
	ScoreOK        = 0.4 // Partial achievement
	ScoreFailed    = 0.0 // Not achieved
)

ScoreThresholds for OKR evaluation.

View Source
const DefaultFilename = "okr.json"

DefaultFilename is the standard OKR filename.

Variables

This section is empty.

Functions

func GenerateID

func GenerateID() string

GenerateID generates an OKR ID based on the current date. Format: OKR-YYYY-DDD where DDD is the day of year.

func IsValid

func IsValid(errs []ValidationError) bool

IsValid returns true if there are no error-level validation issues.

func ScoreDescription

func ScoreDescription(score float64) string

ScoreDescription returns a description for a score.

func ScoreGrade

func ScoreGrade(score float64) string

ScoreGrade returns a letter grade for a score.

Types

type Alignment

type Alignment struct {
	ParentOKRID   string   `json:"parentOkrId,omitempty"`   // Parent OKR document ID
	CompanyOKRIDs []string `json:"companyOkrIds,omitempty"` // Company-level objective IDs this supports
}

Alignment represents how OKRs align with parent/company objectives.

type KeyResult

type KeyResult struct {
	ID                string        `json:"id,omitempty"`
	Title             string        `json:"title"`                       // Short display title
	Description       string        `json:"description,omitempty"`       // Detailed description
	Owner             string        `json:"owner,omitempty"`             // Person or team responsible
	Metric            string        `json:"metric,omitempty"`            // What is being measured
	Baseline          string        `json:"baseline,omitempty"`          // Starting value
	Target            string        `json:"target,omitempty"`            // Target value to achieve
	Current           string        `json:"current,omitempty"`           // Current value
	Unit              string        `json:"unit,omitempty"`              // Unit of measurement
	MeasurementMethod string        `json:"measurementMethod,omitempty"` // How it's measured (from PRD)
	Score             float64       `json:"score,omitempty"`             // 0.0-1.0 achievement score
	Confidence        string        `json:"confidence,omitempty"`        // Low, Medium, High
	Status            string        `json:"status,omitempty"`            // On Track, At Risk, Behind, Achieved
	DueDate           string        `json:"dueDate,omitempty"`           // ISO 8601 date
	PhaseTargets      []PhaseTarget `json:"phaseTargets,omitempty"`      // Per-phase targets for roadmap alignment (from PRD)
	Tags              []string      `json:"tags,omitempty"`              // For filtering by topic/domain (from PRD)
}

KeyResult represents a measurable outcome for an Objective. Merged from standalone OKR and PRD key result types.

type Metadata

type Metadata struct {
	ID         string    `json:"id,omitempty"`
	Name       string    `json:"name,omitempty"`
	Owner      string    `json:"owner,omitempty"`
	Team       string    `json:"team,omitempty"`
	Period     string    `json:"period,omitempty"`     // e.g., "2025-Q1", "FY2025"
	PeriodType string    `json:"periodType,omitempty"` // "quarter", "half", "annual"
	Version    string    `json:"version,omitempty"`
	Status     string    `json:"status,omitempty"`
	CreatedAt  time.Time `json:"createdAt,omitempty"`
	UpdatedAt  time.Time `json:"updatedAt,omitempty"`
}

Metadata contains document metadata.

type OKR

type OKR struct {
	Objective  Objective   `json:"objective"`
	KeyResults []KeyResult `json:"keyResults"` // Alternative to Objective.KeyResults
}

OKR represents an Objective with its Key Results in nested form. This format is commonly used in PRDs for cleaner nesting.

type OKRDocument

type OKRDocument struct {
	Schema     string      `json:"$schema,omitempty"`
	Metadata   *Metadata   `json:"metadata,omitempty"`
	Theme      string      `json:"theme,omitempty"`     // Annual or quarterly theme
	Objectives []Objective `json:"objectives"`          // The OKRs
	Risks      []Risk      `json:"risks,omitempty"`     // Cross-cutting risks
	Alignment  *Alignment  `json:"alignment,omitempty"` // Links to parent/company OKRs
}

OKRDocument represents a complete OKR document containing objectives. Used for standalone OKR files (team/company OKRs).

func New

func New(id, name, owner string) *OKRDocument

New creates a new OKR document with required fields initialized.

func Parse

func Parse(data []byte) (*OKRDocument, error)

Parse parses OKR JSON data.

func ReadFile

func ReadFile(filepath string) (*OKRDocument, error)

ReadFile reads an OKR document from a JSON file.

func (*OKRDocument) AllKeyResults

func (doc *OKRDocument) AllKeyResults() []KeyResult

AllKeyResults returns all key results from all objectives, flattened.

func (*OKRDocument) AllRisks

func (doc *OKRDocument) AllRisks() []Risk

AllRisks returns all risks (global + objective-specific), flattened.

func (*OKRDocument) CalculateOverallProgress

func (doc *OKRDocument) CalculateOverallProgress() float64

CalculateOverallProgress calculates the overall OKR document progress.

func (*OKRDocument) JSON

func (doc *OKRDocument) JSON() ([]byte, error)

JSON returns the OKR document as formatted JSON.

func (*OKRDocument) Validate

func (doc *OKRDocument) Validate(opts *ValidationOptions) []ValidationError

Validate checks the OKR document for issues.

func (*OKRDocument) WriteFile

func (doc *OKRDocument) WriteFile(filepath string) error

WriteFile writes the OKR document to a JSON file.

type OKRSet

type OKRSet struct {
	OKRs []OKR `json:"okrs"`
}

OKRSet represents a set of OKRs within a PRD or other document. This is the embedded form (vs standalone OKRDocument).

func FromObjectives

func FromObjectives(objectives []Objective) *OKRSet

FromObjectives creates an OKRSet from a list of Objectives.

func (*OKRSet) ToObjectives

func (s *OKRSet) ToObjectives() []Objective

ToObjectives converts an OKRSet to a flat list of Objectives. Merges KeyResults from OKR struct into Objective.KeyResults.

type Objective

type Objective struct {
	ID          string      `json:"id,omitempty"`
	Title       string      `json:"title"`                 // Short display title
	Description string      `json:"description,omitempty"` // Detailed description
	Rationale   string      `json:"rationale,omitempty"`   // Why this objective matters (from PRD)
	Category    string      `json:"category,omitempty"`    // Business, Product, Team, etc. (from PRD)
	Owner       string      `json:"owner,omitempty"`       // Person or team responsible
	Timeframe   string      `json:"timeframe,omitempty"`   // Target period (e.g., "Q2 2026")
	Status      string      `json:"status,omitempty"`      // Draft, Active, Completed, Cancelled
	KeyResults  []KeyResult `json:"keyResults"`            // Must have 1+ Key Results
	Progress    float64     `json:"progress,omitempty"`    // Calculated from key results (0.0-1.0)
	Risks       []Risk      `json:"risks,omitempty"`       // Objective-specific risks
	ParentID    string      `json:"parentId,omitempty"`    // Link to parent/company objective
	AlignedWith []string    `json:"alignedWith,omitempty"` // IDs of objectives this supports
	Tags        []string    `json:"tags,omitempty"`        // For filtering by topic/domain (from PRD)
}

Objective represents an inspirational, qualitative goal. Merged from standalone OKR and PRD objective types.

func (*Objective) CalculateProgress

func (o *Objective) CalculateProgress() float64

CalculateProgress calculates the overall progress of an Objective based on its Key Results. Uses average scoring by default.

func (*Objective) UpdateProgress

func (o *Objective) UpdateProgress()

UpdateProgress recalculates the progress for an objective.

type PhaseTarget

type PhaseTarget struct {
	PhaseID string `json:"phaseId"`          // Reference to roadmap phase
	Target  string `json:"target"`           // Target value for this phase
	Status  string `json:"status,omitempty"` // not_started, in_progress, achieved, missed
	Actual  string `json:"actual,omitempty"` // Actual value achieved
	Notes   string `json:"notes,omitempty"`  // Commentary on progress
}

PhaseTarget represents a Key Result target for a specific roadmap phase. This enables alignment between OKRs and roadmap phases.

type Risk

type Risk struct {
	ID          string `json:"id,omitempty"`
	Title       string `json:"title"`
	Description string `json:"description,omitempty"`
	Impact      string `json:"impact,omitempty"`     // Low, Medium, High, Critical
	Likelihood  string `json:"likelihood,omitempty"` // Low, Medium, High
	Mitigation  string `json:"mitigation,omitempty"`
	Status      string `json:"status,omitempty"` // Identified, Mitigating, Resolved, Accepted
}

Risk represents a challenge or risk to achieving objectives.

type ValidationError

type ValidationError struct {
	Path    string // JSON path to the problematic field
	Message string
	IsError bool // true for errors, false for warnings
}

ValidationError represents a validation issue.

func Errors

func Errors(errs []ValidationError) []ValidationError

Errors returns only error-level validation results.

func Warnings

func Warnings(errs []ValidationError) []ValidationError

Warnings returns only warning-level validation results.

func (ValidationError) Error

func (e ValidationError) Error() string

Error implements the error interface.

type ValidationOptions

type ValidationOptions struct {
	RequireKeyResults   bool // Require at least one key result per objective
	RequireScores       bool // Require scores to be set on key results
	MinKeyResultsPerObj int  // Minimum key results per objective (default: 1)
	MaxKeyResultsPerObj int  // Maximum key results per objective (default: 5, 0 = no limit)
	MaxObjectives       int  // Maximum objectives per document (default: 5, 0 = no limit)
	RequireTargets      bool // Require target values on key results
	ValidateScoreRange  bool // Ensure scores are in 0.0-1.0 range
	RequireTimeframe    bool // Require timeframe on active objectives
}

ValidationOptions configures validation behavior.

func DefaultValidationOptions

func DefaultValidationOptions() *ValidationOptions

DefaultValidationOptions returns sensible defaults.

func StrictValidationOptions

func StrictValidationOptions() *ValidationOptions

StrictValidationOptions returns strict validation settings.

Directories

Path Synopsis
Package render provides interfaces and utilities for rendering OKR documents to various output formats including Marp slides.
Package render provides interfaces and utilities for rendering OKR documents to various output formats including Marp slides.
marp
Package marp provides a Marp markdown renderer for OKR documents.
Package marp provides a Marp markdown renderer for OKR documents.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL