util

package
v0.1.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package util contains small, cross-layer helpers with no business ownership.

Keep package contents generic and dependency-light. Helpers that belong to a specific subsystem should live with that subsystem instead of being added here.

Index

Constants

View Source
const (
	PrefixUser                = "u"
	PrefixTeam                = "tm"
	PrefixIssue               = "i"
	PrefixIssueComment        = "ic"
	PrefixAgent               = "a"
	PrefixAgentRevision       = "arv"
	PrefixWorkflow            = "w"
	PrefixWorkflowRevision    = "wrv"
	PrefixWorkflowRun         = "wr"
	PrefixWorkflowStepRun     = "wsr"
	PrefixConversation        = "c"
	PrefixTask                = "t"
	PrefixTaskRun             = "r"
	PrefixArtifact            = "ar"
	PrefixArtifactItem        = "f"
	PrefixConversationMessage = "cm"
	PrefixWebhookKey          = "whk"
	PrefixLLMCall             = "lc"
	PrefixLLMModel            = "lm"
	PrefixAuditEvent          = "ae"
	PrefixAuthSession         = "as"
	PrefixSystemGrant         = "sg"
	PrefixPlugin              = "pl"
	PrefixPluginRelease       = "plr"
)

Prefix constants for prefixed IDs. Use with NewPrefixedID. Semantics: u=user, tm=team, a=agent, arv=agent revision, c=conversation, t=task, r=task run, ar=artifact, f=artifact item, cm=conversation message, ic=issue comment, wrv=workflow revision, whk=user webhook key, lc=managed LLM call, lm=managed model catalog entry, as=auth session (one login chain of refresh tokens), sg=system grant (a deployment-scoped role held by a user). Agent session IDs are internal (not user-facing) and use UUID.

Variables

This section is empty.

Functions

func ClipRunes

func ClipRunes(s string, maxRunes int) string

ClipRunes returns at most the first maxRunes runes of s without adding a suffix. If maxRunes is non-positive, it returns the empty string.

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration formats a duration in a compact human-readable way.

func FormatUnixMinute

func FormatUnixMinute(unixSec int64) string

FormatUnixMinute formats a unix timestamp as YYYY-MM-DD HH:MM.

func NewPrefixedID

func NewPrefixedID(prefix string) string

NewPrefixedID returns a string of the form "<prefix>_<body>", where body is 20 characters from [a-z0-9] (lowercase base36), derived from 128 bits of crypto-random entropy. Ordering is by created_at; IDs are not time-ordered.

func Ptr

func Ptr[T any](v T) *T

Ptr returns a pointer to v. Useful for filling optional pointer fields.

func ResolvePath

func ResolvePath(root, userPath string) (string, error)

ResolvePath resolves a user-supplied path relative to root, ensuring the result stays under root. Returns the absolute, cleaned path. Includes a Windows-safe prefix check (filepath.Rel can return an absolute path when roots differ on different drives). Does NOT stat the path — callers handle existence and type checks.

func ResolveWorkspaceRoot

func ResolveWorkspaceRoot(dir string) (string, error)

ResolveWorkspaceRoot resolves and absolutizes a workspace root directory. If dir is empty, the current working directory is used.

func TruncateRunes

func TruncateRunes(s string, maxRunes int) string

TruncateRunes truncates s to at most maxRunes runes and appends an ellipsis when truncation happens. If maxRunes is non-positive, it returns the empty string.

func WithEnvVar

func WithEnvVar(envKey, value string, fn func() error) error

WithEnvVar sets envKey to value for the duration of fn, then restores the previous process env state.

func WorkerJobNameForTaskRun

func WorkerJobNameForTaskRun(taskRunID string) string

WorkerJobNameForTaskRun returns a DNS-1123-compatible worker Job name for a task run id.

func WorkerJobNameForTaskRunAt

func WorkerJobNameForTaskRunAt(taskRunID string, now time.Time) string

WorkerJobNameForTaskRunAt returns a DNS-1123-compatible worker Job name for a task run id and timestamp. Total length is kept <= 63 characters.

Types

This section is empty.

Jump to

Keyboard shortcuts

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