weekly

package
v0.164.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package weekly builds the report that says what moved — and, more often, that nothing did.

The premium page promises "the repository that cost 3× its usual week", and the whole difficulty is in the word *usual*. Comparing this week with last week gives a ratio, not a finding: a repository that cost $2 and then $6 has tripled and means nothing. So "usual" here is the median of the four weeks before this one, and a mover is only reported when it also clears an absolute floor in dollars. Below that the report says the week was ordinary, which is true and worth saying (ADR-024).

This matters more than it would on the dashboard. A reader looking at a screen can click into a figure that surprises them; a reader holding a message cannot. A confident wrong headline in a weekly message is a claim they have no way to check, which is the reason `caprock report` already refuses to publish a breakdown whose linkage is too weak.

Index

Constants

View Source
const BaselineWeeks = 4

BaselineWeeks is how many weeks "usual" is measured over.

Four is a compromise: long enough that one unusual week does not become the baseline, short enough to follow someone whose work genuinely changed a month ago. The median of the four is used rather than the mean, because one runaway week would drag a mean up and hide the next one.

View Source
const MinMoveUSD = 10.0

MinMoveUSD is the smallest change worth calling a movement.

Ten dollars, and the first draft had it at three — which the tests caught immediately. A repository going from $2 to $6 clears a $3 floor and is exactly the finding this floor exists to suppress: it is three times its usual week and it is nothing. The floor has to be large enough that the change is worth a person's attention on its own, before the multiple is even considered, because a report that cries wolf is one people stop opening — and that costs more than missing a mover.

View Source
const TelegramAPI = "https://api.telegram.org"

TelegramAPI is the only host this package ever contacts.

Variables

This section is empty.

Functions

func Message

func Message(r Report, basis string) string

Message renders a report as the text of one Telegram message.

Plain prose, not a table: a phone is narrow, and a column layout that wraps is harder to read than a sentence. The first line is the whole claim, so a notification preview carries the point without being opened.

Types

type Day

type Day struct {
	Day     string // YYYY-MM-DD
	Project string
	Model   string
	CostUSD float64
	Tokens  int64
}

Day is one row of daily_stats: a day, a project, a model, and what it cost.

type Move

type Move struct {
	Project string  `json:"project"`
	ThisUSD float64 `json:"this_usd"`
	// UsualUSD is the median of the baseline weeks, which is what "3× its usual
	// week" is measured against — not last week.
	UsualUSD float64 `json:"usual_usd"`
	// Multiple is ThisUSD / UsualUSD. Zero when the project had no baseline at
	// all, which is reported as "new" rather than as an infinite multiple.
	Multiple float64 `json:"multiple"`
	New      bool    `json:"new"`
}

Move is one repository whose week departed from its usual.

type ProjectWeek

type ProjectWeek struct {
	Project string  `json:"project"`
	CostUSD float64 `json:"cost_usd"`
	Tokens  int64   `json:"tokens"`
}

ProjectWeek is one repository's week.

type Report

type Report struct {
	WeekStart time.Time `json:"week_start"`
	WeekEnd   time.Time `json:"week_end"`
	CostUSD   float64   `json:"cost_usd"`
	// PriorUSD is the median week of the baseline, for the one line that says
	// whether the week as a whole was ordinary.
	PriorUSD float64 `json:"prior_usd"`
	Tokens   int64   `json:"tokens"`
	// Movers are ranked by how far they departed, biggest first. Empty is the
	// normal case and is not a failure.
	Movers []Move `json:"movers"`
	// Projects is the week's spend per repository, biggest first — the part
	// that is true whether or not anything moved.
	Projects []ProjectWeek `json:"projects"`
	// Quiet says the week produced no reportable movement, so the message can
	// say so plainly instead of listing nothing.
	Quiet bool `json:"quiet"`
	// NoData means the week has no priced activity at all — the machine was off,
	// or the daemon was. Reporting a 100% drop for a week nobody worked would be
	// a lie the reader cannot check.
	NoData bool `json:"no_data"`
}

Report is a week, and what is worth saying about it.

func Build

func Build(rows []Day, weekEnd time.Time) Report

Build assembles the report for the week ending at weekEnd (exclusive) from daily rows covering that week and the baseline before it.

It takes rows rather than a database so the judgement above can be tested without one — the same reason cmd/caprock/report.go keeps its assembly pure.

type Sender

type Sender struct {
	HTTP *http.Client
	// Base overrides the API host in tests.
	Base string
}

Sender delivers a finished report. The zero value is usable.

This is the product's first *background* outbound call — the release check and Gemini both fire because a person did something in that moment. What keeps it inside rule 4 is what it carries and what turns it on: figures the user already sees on their own dashboard, never a prompt, a reply, a tool result or a file path, and only once they have configured a bot of their own. With no token there is no timer and nothing to switch off.

func (*Sender) Send

func (s *Sender) Send(ctx context.Context, token, chat, text string) error

Send posts one message. token and chat are the user's own bot and chat.

No parse mode: Markdown would need every repository name escaped, and a name with an underscore in it would either break the message or silently italicise half of it. Plain text always renders.

func (*Sender) SendFormatted added in v0.74.0

func (s *Sender) SendFormatted(ctx context.Context, token, chat, text, parseMode string) error

SendFormatted posts one message in a Telegram parse mode ("HTML"); the caller has escaped the text for it. An empty mode is plain text.

Jump to

Keyboard shortcuts

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